Skip to main content
DeepInfra exposes an Anthropic-compatible Messages API. This means tools that target the Anthropic API — Claude Code, the Anthropic Python and TypeScript SDKs, and any framework with an Anthropic adapter — can point at DeepInfra and use open-source models, as well as the Claude models DeepInfra resells.

Endpoint

These endpoints are available:

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 as zai-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-5 runs on anthropic/claude-opus-5-5.
  • A dated id runs on the undated model when DeepInfra doesn’t list the dated one: claude-haiku-4-5-20251001 runs on anthropic/claude-haiku-4-5.
  • A Claude model DeepInfra doesn’t resell returns 404 with not_found_error.
The 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.
Map every slot you use. For a slot with no mapping, Claude Code sends Anthropic’s own id, such as claude-opus-5-5 when you set no model at all. DeepInfra runs that on the resold Claude model at its price (see Model names), and an id DeepInfra doesn’t resell fails with a 404.
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_TOKENS to the model’s context window in tokens, for example 131072. It applies to model names without [1m].
  • Keep CLAUDE_CODE_MAX_OUTPUT_TOKENS below the model’s output limit. The examples below use 16384.
The startup warning Model "…" isn't recognized · context assumed to be 200k tokens means one of the names in your config still needs this. 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
Reload Claude Code (or restart your VS Code window) and all five models show up in the /model picker. To go back to Anthropic’s own models, delete the env block and reload. Notes on this file:
  • ANTHROPIC_BASE_URL has no /v1 suffix — Claude Code appends /v1/messages itself.
  • ANTHROPIC_AUTH_TOKEN is sent as Authorization: Bearer …. ANTHROPIC_API_KEY (sent as x-api-key) works too.
  • Each *_MODEL_NAME sets the label shown in the picker; it is cosmetic.
  • ANTHROPIC_CUSTOM_MODEL_OPTION adds 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_TOKENS covers the one name above without [1m], the 128K haiku model.
  • Claude Code’s effort level (/effort, or output_config.effort on the wire) is passed to the model as DeepInfra’s reasoning_effort.
  • VS Code extension: if the picker doesn’t pick up the config after a window reload, also add the same variables under claudeCode.environmentVariables in 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:
Then run 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 under env, 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 its anthropic/ 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 — use stream=True (Python) or stream: true (JS/cURL):

Token counting

Count the tokens in a message request before sending it:
For Claude models the count is an estimate, because DeepInfra has no Claude tokenizer.

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 the anthropic/ 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.