Start
Anthropic compatibility
Use Claude Code and Anthropic SDKs with the Messages API.
POST /v1/messages speaks the Anthropic Messages API. Claude Code and the Anthropic SDKs add /v1/messages themselves, so their base URL has no /v1.
import anthropic
client = anthropic.Anthropic(
base_url="https://deference.si",
api_key="sk-df-...",
)
message = client.messages.create(
model="anthropic/claude-sonnet-5.5",
max_tokens=1024,
messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(message.content[0].text)What passes through
anthropic-versionandanthropic-betaheaders pass through as sent. The body keeps its Anthropic format, including thinking and tool-use blocks.- Streams are relayed as they arrive, including
pingevents. Nothing is buffered. systemandcache_controlblocks keep their position, so prompt caching works.- A query string such as
?beta=trueis ignored. - Error bodies from the provider are returned unchanged, and
retry-afteris a whole number of seconds. anthropic-ratelimit-*andx-should-retryresponse headers are passed on when the provider sends them.
Set max_tokens to an output limit your available credit can cover. Deference never lowers it on Messages. A provider-run web_search tool's max_uses cannot exceed the request's allowed tool steps, at most 30. If omitted, it uses that allowance. See Messages.
Credentials
Send the key as x-api-key: sk-df-... or as Authorization: Bearer sk-df-.... The Anthropic SDK sends the first. Claude Code sends the second when you set ANTHROPIC_AUTH_TOKEN.
Model ids
Use the catalog id, for example anthropic/claude-sonnet-5.5. A trailing [1m] is accepted: Deference ignores it when it looks up the model and its price, and forwards the body unchanged. Other providers' models are accepted too, but thinking blocks and tool use follow each model's own behavior.
Errors
Errors use Anthropic's envelope: type: "error", an error object with type and message, and a request_id. See Errors.
Not available
POST /v1/messages/count_tokens is not available. Claude Code falls back to an estimate when it cannot count tokens.