CLAUDE OPUS 4.8 β€’ MESSAGES API

Opus 4.8
Utilities

Small, self-contained Python scripts that demonstrate real Claude Opus 4.8 capabilities on the Anthropic Messages API.

Claude Opus 4.8 β€” Frontier Intelligence
3 self-contained scripts
Zero dependencies beyond the SDK
Each prints exactly what it demonstrates
Get started

Requirements

All scripts target the model claude-opus-4-8.
Runnable demos

The Three Utilities

Each script is a single file. Run it and watch the behavior (and the token accounting) in real time.

Effort
effort_demo.py

Same model, same prompt β€” turn the effort dial from low to max and watch output tokens rise.

See the effort dial in action β†’
Caching
cache_safe_system_injection.py

Inject mid-conversation instructions as system messages without destroying your prompt cache prefix.

Preserve cache across turns β†’
Independence
disagreement_probe.py

Test whether the model pushes back on confident-but-wrong claims or caves under pressure.

Calibrated pushback vs sycophancy β†’
01

effort_demo.py β€” Effort as a dial

Run the exact same prompt on the exact same model at every effort level. The only thing that changes is output_config={"effort": "..."}.

Key insight

Output tokens (and quality) scale with the effort setting. You don’t switch models β€” you turn a dial. high is the default. xhigh and max are Opus-tier only.

Run it
python3 effort_demo.py
What the script does

It loops over ["low", "medium", "high", "xhigh", "max"], calls the model with thinking={"type": "adaptive"} + the chosen effort, and prints the answer plus input/output token counts.

You’ll see output length (and usually depth) increase as effort goes up β€” all on the identical base model.

Source: effort_demo.py
02

cache_safe_system_injection.py β€” Mid-conversation system messages

How do you give new instructions to a long-running agent without blowing away your expensive prompt cache?

Key insight

Put the new instruction as a {"role": "system"} entry inside the messages array. The top-level system (the cached prefix) stays byte-identical.

Run it
python3 cache_safe_system_injection.py
Three calls it prints
  • turn 1 β€” cold start, writes the big system block into cache (cache_write > 0)
  • turn 2a (good) β€” injects a one-off system message in the messages list β†’ cache prefix survives (cache_read > 0)
  • turn 2b (bad) β€” mutates the top-level system β†’ cache is invalidated, full rewrite (cache_write > 0, cache_read = 0)

The gap between 2a and 2b is the real cost of cache invalidation in production agents. Requires a Claude 4+ model.

03

disagreement_probe.py β€” Does it push back?

Frontier models can be sycophantic. This script probes native behavior with no system prompt coaching.

Two tests
A) Correction test β€” four claims presented as fact (three false, one true). Does it agree with everything or correct the falsehoods?
B) Pressure test β€” after an initial response, push back hard with authority. Does it hold its ground or fold?
Run it
python3 disagreement_probe.py

The script prints both the model’s answers and the token usage. Look for whether it confidently agrees with provably false statements or stands its ground under pressure.

These scripts make live API calls.
Keep max_tokens and effort modest while experimenting. Token costs add up quickly on the higher effort tiers.