How to Get a DeepSeek API Key: 6 Steps to Your First Request
You create a DeepSeek API key in the backend of the DeepSeek Open Platform. Register an account, add funds, open the API keys page, create a new key, and then plug it into any client or SDK that speaks the OpenAI format. You don't need to write any code to get the key. This guide goes in order and ends with a first request you can copy and paste.
Note: platform pages, menu names, top-up methods, and prices change. This article covers the flow and the underlying ideas only; for specifics, rely on the official DeepSeek docs and the Open Platform dashboard.
What do you need before getting a DeepSeek API key?
- An account that can receive verification messages (a phone number or an email, depending on what the sign-up page asks for).
- A small budget. The API is billed by usage and is separate from the web chat, so your account needs a balance to make calls reliably. Whether any free credit is granted, and how much, depends on what DeepSeek says at the time.
- A terminal with curl, or an environment with Python installed.
If you're not sure what an "API key" is, read What Is an API Key? 5 Things Beginners Should Know Before Using an AI API first.
The 6 steps to apply for a key
- Open the DeepSeek Open Platform. Get the address from the official docs rather than a search result, to avoid landing on an imitation site. Register and sign in. Whether the Open Platform and the DeepSeek web chat share one account system is something to confirm in the official docs.
- Complete any identity or security verification the platform requires.
- Add funds on the top-up or billing page. A small amount is enough to start; top up again when it runs out.
- Go to the API keys page and click Create. Give the key a name that tells you what it's for, such as
local-test. - After creation, the page usually shows the full key only once. Copy it right away into a password manager or an environment variable. Once you close the page you may never see the full key again.
- Look up the current endpoint address (base URL) and the available model names in the official docs. You'll need both for the requests below.
How should you store the key?
Don't put the key in code, screenshots, or chat logs. The simplest approach is an environment variable:
export DEEPSEEK_API_KEY="sk-your-key"
If you add this to a shell config file, make sure that file is never committed to Git. For team setups and what to do after a leak, see How to Store an API Key Safely: Local Development and Team Collaboration and API Key Leaked? A 10-Minute Emergency Checklist.
How do you send the first request with curl?
DeepSeek's API is compatible with the OpenAI Chat Completions format, so the request body looks almost identical to the OpenAI examples you've seen. Only the address, the key, and the model name differ. Replace <BASE_URL> and <MODEL> below with the current values from the official docs:
curl <BASE_URL>/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{
"model": "<MODEL>",
"messages": [
{"role": "user", "content": "Introduce yourself in one sentence"}
]
}'
In the returned JSON, the reply text is in choices[0].message.content and usage is in the usage field. If you can see both, your key, network, and balance are all fine. For a more detailed curl walkthrough, see Your First AI API Call: Send a Request with curl.
How do you call it with an OpenAI-compatible SDK?
Because the format is compatible, you can use OpenAI's Python SDK directly and change just two parameters:
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DEEPSEEK_API_KEY"],
base_url="<BASE_URL>", # see the official docs
)
resp = client.chat.completions.create(
model="<MODEL>", # see the official docs
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
Many editors and chat clients have a "custom OpenAI endpoint" option. It asks for the same three things: endpoint address, key, and model name.
How do you troubleshoot a failed call?
| Symptom | Common cause | What to do first |
|---|---|---|
| 401 | Wrong key, extra whitespace, or key deleted | Copy the key again and check that the environment variable took effect |
| 402 or an insufficient-balance message | No usable balance on the account | Check the balance on the billing page |
| 404 or model not found | Model name misspelled, or the URL is missing a path | Compare against the model names and paths in the official docs |
| 429 | Too many requests | Lower concurrency and retry with a delay |
| 5xx, timeout | Server is busy, or your network to the server is unstable | Check service status first, then your local network |
The exact meaning of each error code is defined on the official error-code page; the table above is only the usual mapping.
For a 5xx or a timeout, open /en/status/deepseek. It shows cdnping's probe results from the Cloudflare edge against DeepSeek's official API entry point (every 5 minutes, with 30 days of history), so you can tell whether the provider is having trouble or only your side is. For how to troubleshoot the web app, the mobile app, and the API separately, see Who Is Responsible When DeepSeek Says "Server Busy"? A Three-Step Check for Web, App, and API. If the problem is just high latency, you can measure first-connection and round-trip times from your network to each provider's API on the cdnping home page, and see /en/learn/ai-api-latency-china.
How much does one call cost?
Billing is per token, with input and output counted separately. I don't list specific unit prices here because prices get adjusted; the official pricing page is the source of truth. To build intuition first, read How Token Billing Works: A Line-by-Line Breakdown of One LLM API Call. In your first week, watch the usage in each response and check usage and balance in the dashboard regularly.
What if you want several model providers at once?
If you only use DeepSeek, going straight to the official Open Platform is simplest. If you also want to switch between models of different strengths in tools like Claude Code or Codex, and handling overseas payments is inconvenient, you can look at AGI Plan. Disclosure: AGI Plan is a commercial partner of cdnping. It is a multi-provider LLM aggregation gateway sold as a monthly subscription, paid in RMB, with no overseas credit card required. Tools such as Claude Code and Codex only need one changed endpoint address, and you can use a single quota to switch among capability groups: frontier reasoning, balanced general-purpose, Chinese flagship, and fast lightweight. It is not an officially authorized channel of the model vendors, and some models are available only outside mainland China; check https://agiplan.dev/models for the current list. Getting-started steps are at https://agiplan.dev/startup. For an explanation of the underlying principle, see How One API Key Can Call Multiple Models: Interface Compatibility and How Gateways Work.
What should you do next?
- Send the first request with the curl command above and confirm you get a reply.
- Put the key in an environment variable and make sure it never enters version control.
- Read the official docs on error codes and rate limits, and add timeouts and retries to your program.
- When you're ready to go to production, come back to cost and status monitoring.