DeepSeek API key: models, prices, Claude Code and OpenRouter
Get a DeepSeek API key: today's model names, peak and off-peak prices, limits, and using the key in Claude Code, Codex, OpenCode or through OpenRouter.
Create the key at platform.deepseek.com/api_keys after topping up your balance; DeepSeek bills prepaid, per token. As of November 30, 2026 there are two model names: deepseek-flash (V4.1 Flash, $0.30 in and $1.20 out per million tokens at peak, half that off-peak) and deepseek-v4-pro ($1.32 and $3.96 at peak). deepseek-chat and deepseek-reasoner were retired on July 24, 2026. The OpenAI-style base URL is https://api.deepseek.com and the Anthropic-style one, which Claude Code uses, is https://api.deepseek.com/anthropic. Through OpenRouter, DeepSeek itself serves deepseek/deepseek-v4.1-flash-1017 and deepseek/deepseek-v4-pro-0813.
Getting the key
Sign in at platform.deepseek.com, add money on its top-up page, then create a key on the API keys page. DeepSeek’s platform terms say you “may need to prepay for the Services” and that DeepSeek can suspend the service when your balance is insufficient. Keys start with sk-. Any credit DeepSeek grants you is spent before the money you put in, and the terms allow a refund of the unspent remainder, less handling fees, if DeepSeek approves it.
DeepSeek’s public docs do not say whether the platform shows a key again after you create it, so save it into a file the moment it appears; if one is lost, delete it and make another. The terms put a leaked key’s spending on you: “You will be solely responsible for any fees incurred and losses caused by sharing or leaking the API key.” Rate limits are per account, not per key, so a second key buys no extra capacity, only a separate thing to revoke.
Store it so it never lands in your shell history
DeepSeek’s own examples have you type export DEEPSEEK_API_KEY=..., which writes the key into ~/.bash_history. Reading it without echo into a file only you can read avoids that, and works the same on a laptop or a server you reach over SSH, since a key needs no browser sign-in:
mkdir -p ~/.config/deepseek
printf 'DeepSeek API key: '; read -rs k; echo
(umask 077; printf 'DEEPSEEK_API_KEY=%s\n' "$k" > ~/.config/deepseek/env); unset k
chmod 600 ~/.config/deepseek/env # the > above overwrites any earlier file thereCopiedThen check the key and the balance in one call, loading the file in a subshell so the variable does not stay in your session:
( set -a; . ~/.config/deepseek/env; set +a
curl -s https://api.deepseek.com/user/balance \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" )CopiedThe balance endpoint returns is_available (whether the balance covers API calls) and, per currency (CNY or USD), the total, the granted and the topped-up balance. A 401 means the key is wrong. When the balance runs out, model calls fail with 402 Insufficient Balance.
Model names as of November 30, 2026
DeepSeek changed its API model names in April and again in September, so an example written before then may use a name that no longer works. The current list, from its models and pricing page:
| Model name | Serves | Context / max output | Notes |
|---|---|---|---|
deepseek-flash | DeepSeek-V4.1-Flash-1017 | 1M / 384K | Thinking on by default; tool calls, JSON, vision |
deepseek-v4-pro | DeepSeek-V4-Pro-0813 | 1M / 384K | Thinking on by default; tool calls, JSON, no vision |
deepseek-v4-flash | DeepSeek-V4.1-Flash-1017 | as Flash | Old name, routed to V4.1 Flash “temporarily”, billed at the Flash price |
deepseek-chat, deepseek-reasoner | Nothing | Retired |
DeepSeek’s V4 announcement of April 24, 2026 set the date for the two old names:
deepseek-chat & deepseek-reasoner will be fully retired and inaccessible after Jul 24th, 2026, 15:59 (UTC Time).CopiedOn September 10 it moved Flash to V4.1 under the new name deepseek-flash, and on October 17 pointed that name at the 1017 update. Thinking versus non-thinking is now a request parameter ("thinking": {"type": "enabled"} in the first-call example), not a second model name. A first call to confirm the name works:
( set -a; . ~/.config/deepseek/env; set +a
curl -s https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{"model": "deepseek-flash", "messages": [{"role": "user", "content": "Hello"}]}' )CopiedWhat it costs
Prices are per million tokens in US dollars, as listed on November 30, 2026. Peak hours are 01:00 to 04:00 and 06:00 to 10:00 UTC, Monday to Friday; every other hour, weekends and Chinese public holidays are off-peak, at half the price.
| Flash, peak | Flash, off-peak | V4 Pro, peak | V4 Pro, off-peak | |
|---|---|---|---|---|
Input, cache hit | $0.006 | $0.003 | $0.044 | $0.022 |
Input, cache miss | $0.30 | $0.15 | $1.32 | $0.66 |
Output | $1.20 | $0.60 | $3.96 | $1.98 |
The cache-hit column matters most for a coding agent: every turn resends the conversation so far, and the repeated part is billed at a fiftieth of the miss price on Flash and a thirtieth on Pro. The peak windows are 09:00 to 12:00 and 14:00 to 18:00 Beijing time: they overlap a European morning, and fall mostly outside the working day in the Americas. DeepSeek notes that prices may change.
Limits, balance and errors
The limit DeepSeek documents is on concurrent requests per account: 2,500 for deepseek-flash and 500 for deepseek-v4-pro, counted from when a request is sent until its response finishes, across all your keys. Past it you get 429; a higher limit is a request to DeepSeek, at no extra cost. Under heavy load the server holds the connection open with blank lines (or : keep-alive comments when streaming) rather than refusing, and closes it if inference has not started after 10 minutes. DeepSeek’s error page says to retry 500 and 503 Server Overloaded after a brief wait; 402 needs a top-up, not a retry.
Using the key in Claude Code
DeepSeek serves Anthropic’s Messages API at https://api.deepseek.com/anthropic, so Claude Code can talk to it with no router in between. DeepSeek’s Claude Code page sets nine variables. As a shell function that reads the key from the file above (add it to ~/.bashrc or ~/.zshrc):
deepseek-claude() {
(
set -a; . ~/.config/deepseek/env; set +a
export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_AUTH_TOKEN="$DEEPSEEK_API_KEY"
export ANTHROPIC_MODEL='deepseek-flash[1m]'
export ANTHROPIC_DEFAULT_OPUS_MODEL='deepseek-flash[1m]'
export ANTHROPIC_DEFAULT_SONNET_MODEL='deepseek-flash[1m]'
export ANTHROPIC_DEFAULT_HAIKU_MODEL=deepseek-flash
export CLAUDE_CODE_SUBAGENT_MODEL=deepseek-flash
export CLAUDE_CODE_EFFORT_LEVEL=max
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=786432
exec claude "$@"
)
}CopiedThe values are DeepSeek’s; the quotes around deepseek-flash[1m] are added, because zsh reads an unquoted [1m] as a filename pattern and stops with “no matches found”. [1m] is Claude Code’s marker for a one-million-token window, which is what DeepSeek lists; Claude Code strips it before sending the name. The subshell keeps the variables out of your normal shell, so plain claude still uses your Claude login. What each variable does is in the Claude Code environment variables guide.
Three things to know. ANTHROPIC_AUTH_TOKEN outranks a claude.ai login in Claude Code’s credential order, so while it is set your subscription is not used and DeepSeek bills every token. DeepSeek maps any model name starting with claude-opus to deepseek-v4-pro, at the Pro price, and claude-sonnet and claude-haiku names to Flash. The opus alias stays on Flash, because the setup points it there, but picking a full claude-opus- model name with /model switches you to the dearer model. And Anthropic’s gateway docs say it “doesn’t support routing Claude Code to non-Claude models through any gateway”: it runs, unsupported. The features that break that way, and how to mix several providers in one session, are in the Claude Code Router guide.
Codex
Codex speaks only the Responses API, which DeepSeek serves at its main base URL. DeepSeek’s Codex page offers a setup script:
bash <(curl -fsSL https://cdn.deepseek.com/api-docs/codex-deepseek-setup-en.sh)CopiedIt runs whatever that URL serves, so read it first if that matters to you. It backs up your config.toml to ~/.codex/backup-deepseek/, and menu option 9 restores it. The manual route has two parts: a model catalogue, ~/.codex/models.json, copied from that page, and this in ~/.codex/config.toml:
model = "deepseek-flash"
model_provider = "deepseek"
preferred_auth_method = "apikey"
forced_login_method = "api"
model_reasoning_effort = "high"
show_raw_agent_reasoning = true
suppress_unstable_features_warning = true
model_catalog_json = "~/.codex/models.json"
[features]
standalone_web_search = true
[model_providers.deepseek]
name = "deepseek"
base_url = "https://api.deepseek.com/"
wire_api = "responses"
env_key = "DEEPSEEK_API_KEY"
supports_standalone_web_search = trueCopiedDeepSeek’s block also has a [desktop] section listing the reasoning levels the ChatGPT desktop app offers, left out here. The one line that differs is the key: DeepSeek’s page pastes it into the file as experimental_bearer_token. Codex’s config reference calls that “discouraged; use env_key”, so the block above names the variable instead, and Codex starts with ( set -a; . ~/.config/deepseek/env; set +a; exec codex ). Web search is on in this setup, and DeepSeek bills those search and fetch calls per successful request ($0.75 per 1,000 each on its pricing page); web_search = "disabled" above the first section turns it off. Codex keeps sessions made with a ChatGPT login apart from API-key sessions, so switching hides the other set until you switch back. The config.toml guide covers the rest of the file.
OpenCode, Aider and other tools
OpenCode has DeepSeek built in. DeepSeek’s OpenCode page asks for v1.18.30 or later: run opencode, type /connect, pick DeepSeek, paste the key, and choose the Flash model. The list may still label it DeepSeek-V4-Flash; that old name is served by V4.1 Flash.
Aider’s DeepSeek page still says aider --model deepseek/deepseek-chat, and its deepseek shortcut points at the same retired name. Aider reaches providers through LiteLLM, whose DeepSeek docs say any DeepSeek model works with the deepseek/ prefix and list deepseek-flash, so the current name is --model deepseek/deepseek-flash with DEEPSEEK_API_KEY set (setup in the Aider guide). Any other tool that takes an OpenAI-compatible endpoint wants base URL https://api.deepseek.com, the key, and one of the two model names; one that asks for an Anthropic endpoint wants https://api.deepseek.com/anthropic.
DeepSeek through OpenRouter instead
On OpenRouter the same models run under several slugs, and only the dated ones include DeepSeek’s own servers. Read from OpenRouter’s model API on November 30, 2026:
| OpenRouter slug | Endpoints | Served by DeepSeek |
|---|---|---|
deepseek/deepseek-v4.1-flash-1017 | 57 | Yes, at $0.15 / $0.60 off-peak, $0.30 / $1.20 peak |
deepseek/deepseek-v4-pro-0813 | 22 | Yes, at $0.66 / $1.98 off-peak, $1.32 / $3.96 peak |
deepseek/deepseek-v4.1-flash | 36 | No (named V4.1 Flash, undated) |
deepseek/deepseek-v4-pro | 12 | No (named V4 Pro 0423) |
By default OpenRouter picks a host per request by expected cost, speed and reliability, so a request may go to any of those hosts, some of them cheaper than DeepSeek (the lowest Flash input price listed was $0.036). To use only DeepSeek’s own endpoint, add a provider filter to the request:
{
"model": "deepseek/deepseek-v4.1-flash-1017",
"provider": { "only": ["deepseek"] },
"messages": [{ "role": "user", "content": "Hello" }]
}Copiedor the opposite, "ignore": ["deepseek"], to keep prompts off DeepSeek’s own service. Which hosts keep or train on prompts, and the account settings that rule them out, are in is DeepSeek safe for AI agents. Making the key is in the OpenRouter API key guide, and pointing Claude Code, Codex or OpenCode at it in OpenRouter in Claude Code, Codex and OpenCode.
Direct key or OpenRouter
| DeepSeek key | OpenRouter key | |
|---|---|---|
Price | DeepSeek’s list, half off-peak | Each host’s list price (DeepSeek’s endpoint matches its own, off-peak included) plus a fee when you buy credits (5.5% on Standard, 8% on Business) |
Who sees the prompts | Always DeepSeek | The host that serves the request, set by your routing and privacy settings |
Limits | 2,500 concurrent (Flash), 500 (Pro), per account | No plan limit of OpenRouter’s own; each host’s limits pass through |
Other models | DeepSeek’s two | Every provider’s, one key and one balance |
Anthropic-style endpoint for Claude Code | Yes | Yes, though OpenRouter says Claude Code is “only guaranteed to work with the Anthropic first-party provider” |
The fee and the pass-through prices are from OpenRouter’s pricing page, and the OpenRouter pricing guide works through what they add up to. If DeepSeek is the only model you use, the direct key is the shorter path and the off-peak discount is automatic. If you want to try DeepSeek beside other models, or keep your prompts away from DeepSeek’s own servers while still using its weights, OpenRouter does both with one key.