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 | Cataloged pricing |
Reasoning¶
Since Anthropic budgets thinking in tokens rather than naming levels, reasoning effort maps to a budget:
| Effort | Wire form |
|---|---|
minimal |
{"type": "disabled"} |
low |
1024 tokens |
medium |
4096 tokens |
high |
16384 tokens |
Thinking arrives as ReasoningDelta events on the
event stream. Thinking starts the first-token clock (the model
is working and the user sees activity), but its text is excluded from the answer.
Structured Output¶
Anthropic has no response_format field, so a schema becomes a single forced tool call,
which the API does constrain. The caller still gets a normal validated result.structured; the
emulation is invisible except in structured_mechanism. See
structured output for how mechanisms are chosen.
Pointing This Adapter Elsewhere¶
Several other services expose an Anthropic-Messages-shaped endpoint. This adapter serves
any of them through a base_url override; nothing else changes:
ai.ProviderSettings.of(
"anthropic",
base_url="https://api.deepseek.com/anthropic",
api_key="env://DEEPSEEK_API_KEY",
)
DeepSeek, xAI, and several of the presets document such endpoints. Prefer the provider's own adapter or preset unless Messages-dialect behavior is specifically needed, since provider-specific features are wired only there.
Multimodal Inputs¶
Images and PDF documents accept inline bytes or provider-fetchable URLs. The adapter emits native image/document content blocks. Audio input is not part of this Messages projection and fails explicitly. See multimodal inputs for the normalized input model.
Notes¶
- System messages become the top-level
systemfield. max_tokensis required by the API; AnyInfer sends 4096 when none is set 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.