All articles
AI

DeepSeek API for Claude Code: Setup, Real Costs, and Kimi or GLM as Alternatives (2026)

How to point Claude Code at DeepSeek's Anthropic-compatible endpoint, what a heavy day costs at peak and off-peak rates, which Claude Code features stop working, and when Kimi or the GLM Coding Plan is the better pick.

DeepSeek API for Claude Code cover: a pale blue clay toy train at a green track switch, one tool sent down a different line
Also available in中文Español

Using the DeepSeek API for Claude Code takes a few environment variables and no extra software. DeepSeek runs an Anthropic-compatible endpoint at https://api.deepseek.com/anthropic and publishes a ready-made Claude Code setup (DeepSeek docs). With its recommended model, deepseek-flash, a heavy coding day in my example costs about $1.31 at peak rates and $0.65 off-peak. Two caveats: Anthropic says it doesn’t support routing Claude Code to non-Claude models (Claude Code docs), and a few Anthropic API features are ignored by DeepSeek.

Kimi (Moonshot) and Zhipu’s GLM offer the same kind of endpoint, so the setup below works for them too with a different URL and model name. I read every source on October 27, 2026; prices change often, so check the linked pages before you top up.

Three providers with Claude Code endpoints

DeepSeek API for Claude Code compared with Kimi and GLM: base URL, recommended model and how each one bills

All three work the same way inside Claude Code: you replace the base URL and the key, then map Claude Code’s model tiers to the provider’s models.

  • DeepSeek: base URL https://api.deepseek.com/anthropic, model deepseek-flash with a 1M context, pay per token (pricing).
  • Kimi: base URL https://api.moonshot.ai/anthropic, model kimi-k3 with a 1M context, $3 input and $15 output per million tokens, no subscription (Kimi pricing).
  • GLM: base URL https://api.z.ai/api/anthropic, models GLM-5.3 and GLM-5.3-Flash, sold as the GLM Coding Plan from $18 a month with credits that refresh every 5 hours (Z.ai).

How to set it up

DeepSeek API for Claude Code: the variables

DeepSeek’s Claude Code guide sets these on macOS or Linux (Windows uses $env: in PowerShell):

  • ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
  • ANTHROPIC_AUTH_TOKEN=your DeepSeek key
  • ANTHROPIC_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL and ANTHROPIC_DEFAULT_SONNET_MODEL = deepseek-flash[1m]
  • ANTHROPIC_DEFAULT_HAIKU_MODEL and CLAUDE_CODE_SUBAGENT_MODEL = deepseek-flash
  • CLAUDE_CODE_EFFORT_LEVEL=max and CLAUDE_CODE_AUTO_COMPACT_WINDOW=786432

Then open your project folder and run claude. If Claude Code isn’t installed yet, the install guide covers Mac, Windows and Linux.

If you’d rather not export variables in every shell, put the same keys in the env block of ~/.claude/settings.json, which applies to you in every project (settings docs). Kimi’s guide warns that the env block there overrides variables exported in your terminal, so old values left in that file are the usual reason a new setup seems to be ignored (Kimi guide). The file holds your key in plain text, so keep it out of git.

DeepSeek API for Claude Code environment variables and what goes wrong when one is missing

Set all the model tiers, not only the main one. Kimi’s table lists the failures: no base URL means requests go to Anthropic and fail authentication, a missing token returns 401, and an unset tier or subagent model makes those tasks fail quietly (source). After starting Claude Code, type /status and check that the base URL and model are the ones you set.

Model names you can pass

DeepSeek also accepts Claude names: anything starting with claude-opus is mapped to deepseek-v4-pro and billed at the V4 Pro price, and other claude names go to deepseek-flash (model mapping). That matters if you leave the Opus tier unset and pick Opus in /model, because you’d pay V4 Pro rates without noticing.

What it costs

DeepSeek bills per million tokens, and off-peak rates are half of peak (pricing):

  • deepseek-flash: input $0.30 on a cache miss, $0.006 on a cache hit, output $1.20 at peak.
  • deepseek-v4-pro: input $1.32 on a miss, $0.044 on a hit, output $3.96 at peak.
  • Peak hours are 01:00 to 04:00 and 06:00 to 10:00 UTC, Monday to Friday, except Chinese public holidays. Everything else is off-peak.
DeepSeek API for Claude Code cost of an example heavy day: deepseek-flash $1.31 peak, $0.65 off-peak; deepseek-v4-pro $5.41 peak, $2.71 off-peak

My example day is 20 million input tokens, 90% of them cache hits, plus 0.5 million output tokens. That is a long agent session with a large repo, not a typical chat. On deepseek-flash it comes to $1.31 at peak and $0.65 off-peak; on deepseek-v4-pro to $5.41 and $2.71. These are my numbers from DeepSeek’s price table, and your cache hit rate moves them the most.

Web search inside Claude Code also goes through DeepSeek’s Search and Fetch APIs. Those calls are free for now, and per-request billing of $0.75 per 1,000 starts at 00:00 Beijing time on November 1, 2026 (source). For comparison with a Claude plan, see how Claude usage limits work.

What doesn’t carry over

DeepSeek lists which Anthropic API fields it supports (compatibility table). The ones you will notice in Claude Code:

  • cache_control is ignored, so Claude Code’s prompt-caching hints do nothing. DeepSeek applies its own cache-hit pricing instead.
  • mcp_servers in the request is ignored and PDF document blocks are not supported. Local MCP servers that Claude Code runs itself are a different thing and still go through the normal tool calls.
  • thinking works, but budget_tokens is ignored; for effort only output_config.effort is read.
  • Image blocks are accepted; search_result and code execution results are not.

Anthropic’s position matters too. Its gateway page says it doesn’t endorse third-party gateways and doesn’t support routing Claude Code to non-Claude models (source). New Claude Code releases can change behaviour without warning, and Anthropic support won’t help with it. If you hit errors, the Claude Code error list helps tell a provider problem from a local one.

DeepSeek, Kimi or GLM?

DeepSeek API for Claude Code decision chart: GLM Coding Plan for a fixed monthly bill, Kimi for its own coding model, otherwise DeepSeek pay per token

Pick DeepSeek if you want the lowest per-token price and can shift heavy work to off-peak hours. I compared its prices on other tools in DeepSeek Flash on OpenCode.

Pick Kimi if you want a 1M context with thinking on by default: Kimi’s guide maps every Claude Code tier to kimi-k3[1m] (Kimi guide). It costs more per token than DeepSeek. Skip kimi-k2.7-code if you’re new: K2 models close to new users on October 31, 2026 and retire by the end of December (source). Prices are in my Kimi K3.1 Pro pricing post.

Pick GLM if you prefer a fixed monthly bill. The GLM Coding Plan starts at $18 a month and its credits refresh 5 hours after use (Z.ai); its Claude Code page also sets API_TIMEOUT_MS to 3000000 for long tasks.

FAQ

Do I need a Claude subscription?

No. With ANTHROPIC_AUTH_TOKEN set to a DeepSeek key, requests go to DeepSeek and are billed there. Claude Code itself is free to install.

Can I switch back to Claude?

Yes. Remove the ANTHROPIC_* variables from your shell and from the env block in settings.json, restart Claude Code and log in again.

Is my code sent to DeepSeek?

Yes. Every prompt, file excerpt and tool result goes to the provider whose base URL you set, under that provider’s terms. Don’t use it on code you aren’t allowed to share.

Leave a thought

Your email address will not be published.