Anthropic¶
The Messages API over raw httpx2. Registered as anthropic, with the alias claude.
Setup¶
client = ai.Client([
ai.ProviderSettings.of("anthropic", api_key="env://ANTHROPIC_API_KEY"),
])
result = client.generate(prompt, target="anthropic:claude-sonnet-4-5")
No extra required.
Supported¶
| Behavior | Support |
|---|---|
| Streaming | Native, typed SSE events |
| Structured output | Emulated as a forced tool call |
| Tools | Native |
| Reasoning | Extended thinking, budgeted in tokens |
| Usage | Input, output, plus cache read/write |
| Cost | Catalogued pricing |
Thinking¶
Reasoning effort maps to a thinking budget, because Anthropic budgets in tokens rather than naming levels:
| Effort | Wire form |
|---|---|
minimal |
{"type": "disabled"} |
low |
1024 tokens |
medium |
4096 tokens |
high |
16384 tokens |
Thinking arrives as ReasoningDelta events. It starts the first-token clock — the model
is working and the user sees activity — but is excluded from the answer text.
Structured output¶
Anthropic has no response_format field, so a schema becomes a single forced tool call,
which the API does constrain. You still get a normal validated result.structured; the
emulation is invisible except in structured_mechanism.
Notes¶
- System messages become the top-level
systemfield. max_tokensis required by the API; AnyInfer sends 4096 when you set none rather than letting the request fail with a 400.- Tool results ride on a user turn in this dialect, not a
toolrole. - Model listing is cursor-paginated, and pagination is followed automatically.
Wire contract¶
For the exact request/response fields this adapter depends on, see contracts/anthropic.md.