Endpoint
Authentication
Both standard Anthropic authentication methods are supported:
You can also pass
anthropic-version and anthropic-beta headers as needed. The two model endpoints also answer without a key.
Using the Anthropic SDK
Installation
Create a message
Point the client at the DeepInfra endpoint and pass a DeepInfra model name:Model names
Pass a DeepInfra model name, such aszai-org/GLM-5.2. Anthropic’s Claude models are the ones under anthropic/, such as anthropic/claude-opus-5-5, billed at the price on their model page.
A bare Claude id works too:
claude-opus-5-5runs onanthropic/claude-opus-5-5.- A dated id runs on the undated model when DeepInfra doesn’t list the dated one:
claude-haiku-4-5-20251001runs onanthropic/claude-haiku-4-5. - A Claude model DeepInfra doesn’t resell returns
404withnot_found_error.
model field in the reply is the id you sent.
List models
GET /anthropic/v1/models returns the public chat models in Anthropic’s format, newest first. It pages with limit (up to 1000), after_id and before_id. GET /anthropic/v1/models/{model_id} returns one model and accepts a bare Claude id: claude-opus-4-8 comes back as anthropic/claude-opus-4-8. Neither needs an API key.
Using with Claude Code
Claude Code can use DeepInfra as its backend. Claude Code exposes four model slots —opus, sonnet, fable, and haiku — plus one extra custom entry in the /model picker. You map each slot to a DeepInfra model.
Recommended models
Claude Code’s slots are a capability/cost ladder —haiku < sonnet < opus < fable. fable sits above opus: it’s the slowest and most expensive slot, meant for the hardest long-horizon work. Map DeepInfra models onto it the same way, most capable first:
All five support prompt caching, which makes cache reads substantially cheaper than fresh input — worth enabling for long agent sessions. See each model’s page on deepinfra.com/models for current per-token pricing.
Use the dated slugs —
DeepSeek-V4.1-Flash-1017 and DeepSeek-V4-Pro-0813. The undated deepseek-ai/DeepSeek-V4.1-Flash and deepseek-ai/DeepSeek-V4-Pro are the earlier checkpoints, which the dated releases supersede.Context window
Claude Code doesn’t know DeepInfra model names, so it assumes a 200K context window for every one of them and auto-compacts the conversation at that point — on a 1M model that throws away 80% of the window. Tell it the real size:- 1M models (all of the table above except
haiku): append[1m]to the model name wherever you set it —deepseek-ai/DeepSeek-V4.1-Flash-1017[1m]. Claude Code strips the suffix before sending the request to DeepInfra. - Any other size: set
CLAUDE_CODE_MAX_CONTEXT_TOKENSto the model’s context window in tokens, for example131072. It applies to model names without[1m]. - Keep
CLAUDE_CODE_MAX_OUTPUT_TOKENSbelow the model’s output limit. The examples below use16384.
Model "…" isn't recognized · context assumed to be 200k tokens means one of the names in your config still needs this.
Option A: .claude/settings.json (recommended)
Instead of exporting environment variables, put the configuration in a Claude Code settings file. Use ~/.claude/settings.json to apply it to all projects, or <repo>/.claude/settings.local.json for a single project (that file is gitignored by default, so your key stays out of version control).
Get an API key at deepinfra.com/dash/keys.
.claude/settings.json
/model picker. To go back to Anthropic’s own models, delete the env block and reload.
Notes on this file:
ANTHROPIC_BASE_URLhas no/v1suffix — Claude Code appends/v1/messagesitself.ANTHROPIC_AUTH_TOKENis sent asAuthorization: Bearer ….ANTHROPIC_API_KEY(sent asx-api-key) works too.- Each
*_MODEL_NAMEsets the label shown in the picker; it is cosmetic. ANTHROPIC_CUSTOM_MODEL_OPTIONadds one extra picker entry. Any other DeepInfra model still works via/model <name>as free text; append[1m]for a 1M model.CLAUDE_CODE_MAX_CONTEXT_TOKENScovers the one name above without[1m], the 128Khaikumodel.- Claude Code’s effort level (
/effort, oroutput_config.efforton the wire) is passed to the model as DeepInfra’sreasoning_effort. - VS Code extension: if the picker doesn’t pick up the config after a window reload, also add the same variables under
claudeCode.environmentVariablesin your VS Code settings.
Option B: shell function with environment variables
If you’d rather keep your default Claude Code setup untouched and switch per-invocation, add a dedicated shell function to your~/.bashrc or ~/.zshrc:
deepinfra instead of claude to launch Claude Code via DeepInfra. Your regular claude command stays unchanged.
Model override environment variables
The same variable names work in both options — as JSON keys underenv, or as shell exports:
Each
*_MODEL variable above has an optional *_MODEL_NAME companion (e.g. ANTHROPIC_DEFAULT_OPUS_MODEL_NAME) that sets the display label in the picker.
ANTHROPIC_DEFAULT_HAIKU_MODEL is used for lightweight background tasks like tab completions and commit messages. Pick a fast, cheap model here to keep costs low. The older ANTHROPIC_SMALL_FAST_MODEL variable is deprecated — use ANTHROPIC_DEFAULT_HAIKU_MODEL instead.Claude models in Claude Code
To run one of Anthropic’s Claude models through DeepInfra, map a slot to itsanthropic/ name, for example ANTHROPIC_DEFAULT_OPUS_MODEL=anthropic/claude-opus-5-5. To have them in the /model picker, set CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1. Claude Code then reads the model list and keeps only the ids that contain claude or anthropic, so the picker gains the anthropic/ models and none of the open ones.
Streaming
Streaming works the same as the Anthropic API — usestream=True (Python) or stream: true (JS/cURL):
Token counting
Count the tokens in a message request before sending it:Notes
- Most models here are open-source. Anthropic’s Claude models are the ones under
anthropic/. - Model names are DeepInfra identifiers (e.g.
zai-org/GLM-5.2). The only Anthropic names accepted are bare Claude ids, which map to theanthropic/models (see Model names). - Not all Anthropic-specific features may be supported. Standard message creation, streaming, token counting, and model listing work as expected.
Chat Completions
Use the OpenAI-compatible API instead.
Authentication
API keys and scoped JWTs.