Endpoint
Authentication
Both standard Anthropic authentication methods are supported:
You can also pass
anthropic-version and anthropic-beta headers as needed.
Using the Anthropic SDK
Installation
Create a message
Point the client at the DeepInfra endpoint and pass a DeepInfra model name: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-Pro-0813 and DeepSeek-V4-Flash-0731. The undated deepseek-ai/DeepSeek-V4-Pro and deepseek-ai/DeepSeek-V4-Flash are the earlier preview checkpoints, which the dated releases supersede.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/api_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.- 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.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
- You are running open-source models via the Anthropic protocol, not Anthropic’s Claude models.
- Model names use DeepInfra identifiers (e.g.
zai-org/GLM-5.2), not Anthropic model names. - Not all Anthropic-specific features may be supported. Standard message creation, streaming, and token counting work as expected.
Chat Completions
Use the OpenAI-compatible API instead.
Authentication
API keys and scoped JWTs.