DeepSeek API keys are created on the API keys page of the DeepSeek Platform (platform.deepseek.com/api_keys) and sent as Authorization: Bearer <key> to https://api.deepseek.com. DeepSeek's own examples read the key from the DEEPSEEK_API_KEY environment variable and use the OpenAI SDK with a changed base URL. The same key also works on DeepSeek's Anthropic-format endpoint, https://api.deepseek.com/anthropic.
DeepSeek key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| DeepSeek API key DeepSeek does not document a key prefix, per-key permissions or an expiry. Concurrency limits are counted per account, not per key, so a second key does not add capacity. | — | Yes | Every model and endpoint on the DeepSeek account; usage is billed against the account balance | — |
How to create a DeepSeek key
- Sign in to the DeepSeek Platform at
platform.deepseek.com. - Top up the account balance; DeepSeek rejects requests with HTTP 402 when the balance is empty.
- Open the API keys page (
platform.deepseek.com/api_keys) and create a new key. - Copy the DeepSeek API key and store it in
DEEPSEEK_API_KEYor a secrets manager.
Limiting what the key can do
DeepSeek API keys carry no documented permission scopes, model restrictions or spending caps. Every DeepSeek key can call every model the account can use and spends from the same balance. To separate workloads, give each application its own DeepSeek key so one can be deleted without touching the others, and keep the account balance low enough that a leaked key cannot spend much. The user_id request field isolates your own end users for concurrency and content-safety purposes; it is not an access control on the key.
How to rotate a DeepSeek key
- Create a second DeepSeek key on the API keys page.
- Replace the old value in
DEEPSEEK_API_KEY(orANTHROPIC_API_KEYfor Anthropic-format clients) wherever it is deployed. - Confirm requests succeed with the new key, then delete the old key.
DeepSeek has no in-place regenerate flow or overlap setting, so rotation is create, deploy, then delete. Several keys can exist at once, and because concurrency limits are account-wide, running two DeepSeek keys during the switch does not change rate limits.
How to revoke a DeepSeek key
- Sign in to the DeepSeek Platform and open the API keys page.
- Delete the DeepSeek key; requests that use it then fail with HTTP 401 Authentication Fails.
If your DeepSeek key leaked
- Delete the exposed DeepSeek key on the API keys page.
- Create a replacement key and deploy it to every service that used the old one.
- Check the usage and billing pages for spend you do not recognise, since any DeepSeek key spends the shared account balance.
- Keep only a small balance on the account until the leak is understood.
Environment variables and CLI
DeepSeek's SDKs and docs read the key from DEEPSEEK_API_KEY.
Things that catch people out
- A 402 Insufficient Balance error looks like a key problem but is a billing one: the DeepSeek key is valid and the account needs funds.
- Concurrency limits apply to the whole DeepSeek account regardless of which key is used, so creating more keys does not raise throughput.
- DeepSeek keys have no documented scopes or spending caps, so any leaked key can spend the full account balance.
- DeepSeek exposes an OpenAI-format base URL (
https://api.deepseek.com) and an Anthropic-format one (https://api.deepseek.com/anthropic); pointing an SDK at the wrong one fails even with a valid key.
Common DeepSeek authentication errors
401 - Authentication Fails
The DeepSeek API key in the request is wrong, deleted or missing.
402 - Insufficient Balance
The DeepSeek account balance has run out, so every key on the account is refused.
429 - Rate Limit Reached
The account is sending requests too quickly or has exceeded its concurrency limit, which is counted across all of the account's keys.
Using your DeepSeek key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a DeepSeek key, these intents fit:
| Intent | What BotPassword does |
|---|---|
run_with | Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output. |
http_request | Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused. |
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
Where do I get a DeepSeek API key?
Create one on the API keys page of the DeepSeek Platform at platform.deepseek.com/api_keys. Add funds to the account first, because requests from an account with no balance fail with HTTP 402.
What is the DeepSeek API key environment variable?
DeepSeek's documentation sets DEEPSEEK_API_KEY and reads it in its Python (os.environ.get('DEEPSEEK_API_KEY')) and Node examples. Anthropic-format clients read the same DeepSeek key from ANTHROPIC_API_KEY with ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic.
Can I use a DeepSeek API key with the OpenAI SDK?
Yes. DeepSeek says its API format is compatible with OpenAI, so set the OpenAI client's base_url to https://api.deepseek.com and pass the DeepSeek key as the API key.
How do I use a DeepSeek key with Claude Code or another coding agent?
DeepSeek offers an Anthropic-compatible endpoint, so tools built on the Anthropic SDK can use it by setting ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic and supplying the DeepSeek key. DeepSeek accepts the key in either the x-api-key or the Authorization: Bearer header there, and maps Claude model names to DeepSeek models.
Why does my DeepSeek API key return 401?
DeepSeek returns 401 Authentication Fails when the key is incorrect, deleted or not sent. Check the Authorization: Bearer header and create a new key if the old one was deleted.
Can an AI agent use my DeepSeek key without seeing it?
Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, so the agent gets the result and never the value.