Use Inference APIs with Claude Code
Run Claude Code on DeepSeek, GLM, Kimi, MiniMax or GPT-OSS. Claude Code speaks the Anthropic Messages API and nothing else; this endpoint implements it for every chat model, so the switch is three environment variables.
Settings
| Setting | Value |
|---|---|
| Base URL | https://api.inferenceapis.com/v1 (also /openai/v1) |
| API key | From API Keys; send as Authorization: Bearer … |
| Chat model ids | openai/gpt-oss-120b, deepseek-ai/DeepSeek-V4-Flash, zai-org/GLM-5.3-Flash, meta-llama/Llama-3.3-70B-Instruct-Turbo — all models |
| Audio model ids | openai/whisper-large-v3 (transcription), hexgrad/Kokoro-82M (speech) |
Which model
zai-org/GLM-5.3 was the fastest large model in our run and deepseek-ai/DeepSeek-V4.1-Flash the best value. moonshotai/Kimi-K2.7-Code and deepseek-ai/DeepSeek-V4-Pro are the other serious choices for agent work. Prices and measured speed: chat models.
Configuration
export ANTHROPIC_BASE_URL="https://api.inferenceapis.com"
export ANTHROPIC_AUTH_TOKEN="your-inferenceapis-key"
export ANTHROPIC_MODEL="zai-org/GLM-5.3[1m]" # [1m]: tell Claude Code the window is 1M tokens
export ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-ai/DeepSeek-V4.1-Flash[1m]" # Claude Code's own background calls
claude{
"env": {
"ANTHROPIC_BASE_URL": "https://api.inferenceapis.com",
"ANTHROPIC_AUTH_TOKEN": "your-inferenceapis-key",
"ANTHROPIC_MODEL": "zai-org/GLM-5.3[1m]",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "deepseek-ai/DeepSeek-V4.1-Flash[1m]",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "zai-org/GLM-5.3[1m]",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "deepseek-ai/DeepSeek-V4-Pro[1m]",
"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
}
}Verify
claude -p "Reply with the single word: ready" --model deepseek-ai/DeepSeek-V4.1-FlashHow this guide was checked
Run end to end Claude Code 2.1.275 (headless claude -p), 2026-09-18: with the environment below, the task "run the tests, fix the bugs in stats.py, run them again" was completed end to end, all tests passing, on eight models. Turns and wall time: DeepSeek V4.1 Flash 6 turns / 5 s, GLM 5.3 6 / 5 s, GLM 5.3 Flash 6 / 13 s, GPT-OSS 120B 10 / 14 s, MiniMax M3 8 / 19 s, DeepSeek V4 Pro 6 / 19 s, Kimi K2.7 Code 6 / 26 s, DeepSeek V4 Flash 13 / 29 s. Billed cost per run, from our own logs: GLM 5.3 Flash $0.006, DeepSeek V4.1 Flash $0.009, DeepSeek V4 Flash $0.013, MiniMax M3 $0.015, Kimi K2.7 Code $0.028, GPT-OSS 120B $0.029, DeepSeek V4 Pro $0.046, GLM 5.3 $0.056. Then, with the Anthropic Python SDK, streaming, tool use, replayed thinking and tool_use blocks, tool_result and count_tokens were checked on every chat model (18 of 18 runs).
Gotchas
- Claude Code assumes a 200,000-token window for a model it does not recognise and auto-compacts the session there, which also throws away the cached prompt. Append <code>[1m]</code> to the model name for the 1M-context models here (DeepSeek V4 Flash, V4.1 Flash and V4 Pro, GLM 5.3 and 5.3 Flash, MiniMax M3), as in the snippets: Claude Code strips the suffix before sending and sets its window to 1M (checked on the wire with 2.1.275). For Kimi K2.7 Code set <code>CLAUDE_CODE_MAX_CONTEXT_TOKENS=262144</code> instead.
- Claude Code prints <code>[claude-code:unrecognized_model]</code> on stderr for model names it does not know. It is a note about its own price table, not an error; the run continues.
- The cost Claude Code shows (<code>/cost</code>, <code>total_cost_usd</code>) is computed from Anthropic list prices and is wrong here. The real figure is on your <a href="/billing">billing page</a>; our test runs cost 1 to 6 cents each.
- Thinking is on by default: Claude Code sends <code>thinking: {type: "adaptive"}</code>, which keeps the model's reasoning switched on and streams it as thinking blocks. <code>enabled</code>, <code>adaptive</code> and <code>auto</code> are all accepted here, so the <a href="/reference/errors/claude-code-400-type-must-be-in-enabled-disabled-auto">400 'type' must be in ["enabled", "disabled", "auto"]</a> error that some hosts return does not occur. Set <code>CLAUDE_CODE_DISABLE_THINKING=1</code> to switch the model's reasoning off; that is faster and cheaper for routine edits.
- Set ANTHROPIC_DEFAULT_HAIKU_MODEL to a cheap model. Claude Code makes side calls with a Haiku model name; a "claude-*" name that is not set to anything is served by DeepSeek V4 Flash and reported in the X-Model-Mapped response header.
- Every model here saw the full history on every turn, including the replayed thinking and tool_use blocks Claude Code sends back, and none rejected it. Thinking blocks are not verified or replayed upstream; they are dropped on the way in, which every model here tolerates (checked per model on 2026-09-18).
- Web search and web fetch are Anthropic-hosted server tools and are dropped (X-Tools-Dropped header). Claude Code's own tools, Bash, Read, Edit, Write, Agent and the rest, are ordinary function tools and work. MCP servers work the same way.
- Prompt caching works without configuration: 60,000 to 200,000 of the input tokens in each run above were served from cache and billed at the cached rate. <code>cache_control</code> markers are accepted and ignored.
- The Message Batches API, server-side <code>container</code> and <code>mcp_servers</code> fields are not supported. <code>count_tokens</code> returns an estimate (about one token per 3.6 characters), since the open models expose no tokenizer here.
- If you are also logged in with a Claude account, check the model name shown at the start of the session: it should be the one you set. Remove the variables, or the settings block, to go back.
If something fails
401 — key missing or wrong · 402 insufficient_balance — add credits on Billing · 404 model_not_found — check the id against the model list (aliases such as gpt-oss-120b work too) · 503 model_unavailable — the model is being enabled. Full details in the API docs.
