How to Get a DeepSeek API Key

Last updated: May 14, 2026

To get a DeepSeek API key, create or log in to your account on the DeepSeek Platform, open the API Keys section, create a new key, copy it once, store it securely, add balance if required, and test it with a small API request. This guide shows you how to get a DeepSeek API key, protect it, and use it with cURL, Python, and Node.js.

The current DeepSeek API is compatible with OpenAI and Anthropic-style API formats. In the official DeepSeek docs, the OpenAI-compatible base URL is https://api.deepseek.com, the Anthropic-compatible base URL is https://api.deepseek.com/anthropic, and the current model IDs include deepseek-v4-flash and deepseek-v4-pro.

Answer box: How do you get a DeepSeek API key?
Go to the DeepSeek Platform, sign up or log in, open the API Keys page, create a new secret key, copy it immediately, and save it in a secure location such as an environment variable or secret manager. If requests fail because of balance, add funds on the Top Up or Billing page.

Quick Steps

  1. Go to the DeepSeek Platform.
  2. Sign up or log in.
  3. Open API Keys.
  4. Create a new key.
  5. Copy and store it securely.
  6. Add balance or top up if required.
  7. Test it with cURL, Python, or Node.js.

For more API setup guides, see AI API tutorials, API key security guide, and OpenAI-compatible APIs guide.


What Is a DeepSeek API Key?

A DeepSeek API key is a private credential that lets your application authenticate requests to the DeepSeek API. Think of it like a password for your app: if someone else gets it, they may be able to send API requests from your account.

DeepSeek’s API reference says you must create an API key before using the API, and the authentication method is HTTP Bearer Auth. In practice, that means your request includes an authorization header like Authorization: Bearer YOUR_DEEPSEEK_API_KEY.

Never publish your key in frontend JavaScript, GitHub repositories, screenshots, browser code, or logs.


Before You Start: Requirements

Before creating and testing a DeepSeek API key, prepare the following:

RequirementWhy you need it
DeepSeek Platform accountYou need an account to create API keys.
Supported email or login methodIf one email domain fails, DeepSeek recommends major providers such as Gmail, Outlook, Hotmail, or Yahoo.
Billing or top-up accessAPI usage may require available balance.
Terminal or code editorNeeded to test the key with cURL, Python, or Node.js.
Secure storage methodUse environment variables locally and a secret manager in production.

DeepSeek’s FAQ says users can top up online through PayPal, bank card, Alipay, or WeChat Pay, and check billing results on the Billing page.


How to Get a DeepSeek API Key: Step-by-Step

Step 1: Open the DeepSeek Platform

Visit the DeepSeek Platform. This is the official dashboard where you manage API keys, billing, usage, and account settings.

Step 2: Sign Up or Log In

Create a new account or log in to an existing one. If your email domain is not accepted, use a major international email provider or contact DeepSeek support, as recommended in the official FAQ.

Step 3: Go to the API Keys Page

Look for a menu item named API Keys, API Key, Secret Key, or something similar. Dashboard labels can change over time, so focus on the section that manages keys for API access.

Step 4: Create a New API Key

Click Create new key, Create secret key, or the equivalent button. The DeepSeek API reference links users to the platform’s API key creation page before they can use the API.

Step 5: Name the Key Clearly

Use a name that tells you where the key is used. Examples:

  • my-app-dev
  • backend-production
  • customer-support-bot
  • automation-testing

Clear names help when you need to audit usage, revoke a key, or find which application is causing high token usage.

Step 6: Copy the Key Immediately

API platforms often show secret keys only once. Copy the key immediately and place it somewhere secure. Do not paste it into a public issue, Slack channel, Notion page, Google Doc, GitHub repository, or frontend source code.

Step 7: Add Balance or Top Up If Needed

If your first request returns 402 Insufficient Balance, your key may be valid but your account has no available balance. DeepSeek’s error code documentation says 402 means the account has run out of balance and should be topped up.


How to Store Your DeepSeek API Key Safely

A DeepSeek API key should be treated like a production password. OWASP’s secrets management guidance recommends properly managing secret storage, provisioning, auditing, rotation, and access control to reduce the risk of leaks.

For local development, use a .env file and make sure it is excluded from Git.

DEEPSEEK_API_KEY=YOUR_DEEPSEEK_API_KEY

Recommended safety practices:

PracticeRecommendation
Local developmentUse .env and add it to .gitignore.
Production appsUse a cloud secret manager or deployment platform secrets.
Frontend appsNever expose the key in browser JavaScript.
LogsLog request IDs and errors, not API keys.
RotationRotate or revoke the key if it is exposed.
EnvironmentsUse separate keys for development, staging, and production.

GitHub also warns that API keys and passwords committed as hardcoded secrets can become targets for unauthorized access; secret scanning helps detect credential leaks.


Test Your DeepSeek API Key with cURL

After saving your key, test it with a small request. DeepSeek’s first-call documentation shows the OpenAI-compatible chat completions endpoint at /chat/completions and uses the Authorization: Bearer ${DEEPSEEK_API_KEY} header.

export DEEPSEEK_API_KEY="YOUR_DEEPSEEK_API_KEY"

curl https://api.deepseek.com/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "Reply with one sentence: my DeepSeek API key works."
}
],
"thinking": {
"type": "disabled"
},
"stream": false
}'

If the request succeeds, you should receive a JSON response with a model-generated message. If it fails, check the error code table later in this guide.


Test Your DeepSeek API Key with Python

DeepSeek’s official example uses the OpenAI Python SDK with base_url="https://api.deepseek.com" and reads the key from the DEEPSEEK_API_KEY environment variable.

Install the SDK:

pip3 install openai

Create a file named test_deepseek.py:

import os
from openai import OpenAI

api_key = os.environ.get("DEEPSEEK_API_KEY")

if not api_key:
raise RuntimeError("Missing DEEPSEEK_API_KEY environment variable.")

client = OpenAI(
api_key=api_key,
base_url="https://api.deepseek.com"
)

response = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[
{"role": "system", "content": "You are a concise technical assistant."},
{"role": "user", "content": "Reply with one sentence: the DeepSeek API key works."}
],
stream=False,
extra_body={
"thinking": {"type": "disabled"}
}
)

print(response.choices[0].message.content)

Run it:

export DEEPSEEK_API_KEY="YOUR_DEEPSEEK_API_KEY"
python3 test_deepseek.py

A successful output means your environment variable, API key, base URL, and model name are working.


Test Your DeepSeek API Key with Node.js

DeepSeek’s official JavaScript example also uses the OpenAI SDK with baseURL: "https://api.deepseek.com" and apiKey: process.env.DEEPSEEK_API_KEY.

Install the SDK:

npm install openai

Create a file named test-deepseek.mjs:

import OpenAI from "openai";

if (!process.env.DEEPSEEK_API_KEY) {
throw new Error("Missing DEEPSEEK_API_KEY environment variable.");
}

const client = new OpenAI({
baseURL: "https://api.deepseek.com",
apiKey: process.env.DEEPSEEK_API_KEY,
});

async function main() {
const completion = await client.chat.completions.create({
model: "deepseek-v4-flash",
messages: [
{
role: "system",
content: "You are a concise technical assistant.",
},
{
role: "user",
content: "Reply with one sentence: the DeepSeek API key works.",
},
],
thinking: {
type: "disabled",
},
stream: false,
});

console.log(completion.choices[0].message.content);
}

main().catch(console.error);

Run it:

export DEEPSEEK_API_KEY="YOUR_DEEPSEEK_API_KEY"
node test-deepseek.mjs

DeepSeek API Authentication and Base URL

Use this table when configuring your app, SDK, or automation workflow.

ItemCurrent value
OpenAI-compatible base URLhttps://api.deepseek.com
Anthropic-compatible base URLhttps://api.deepseek.com/anthropic
Authentication methodHTTP Bearer Auth
Header formatAuthorization: Bearer YOUR_DEEPSEEK_API_KEY
Suggested environment variableDEEPSEEK_API_KEY
Current model examplesdeepseek-v4-flash, deepseek-v4-pro
Legacy model namesdeepseek-chat, deepseek-reasoner

DeepSeek’s docs say the API is compatible with OpenAI and Anthropic formats, while the API reference lists Bearer Auth as the authentication method.


Which DeepSeek Model Should You Use?

The current DeepSeek API model IDs are deepseek-v4-flash and deepseek-v4-pro. The API docs list both as valid model values for chat completions.

ModelBest forNotes
deepseek-v4-flashFast tests, everyday chat, simple automations, lower-cost workflowsDeepSeek describes V4-Flash as fast, efficient, and economical.
deepseek-v4-proCoding agents, complex reasoning, advanced workflows, production tasks that need stronger capabilityDeepSeek describes V4-Pro as stronger for agentic coding, knowledge, Math, STEM, and coding tasks.

For a first API key test, use deepseek-v4-flash. For more demanding coding, reasoning, or agent tasks, test deepseek-v4-pro.

Important: older model names such as deepseek-chat and deepseek-reasoner are legacy names. DeepSeek says they currently route to modes of deepseek-v4-flash and will be discontinued on July 24, 2026.


Common DeepSeek API Key Errors and Fixes

Use this table to troubleshoot your first request. DeepSeek’s error code page lists common API errors including 401, 402, 429, 500, and 503.

ErrorLikely causeFix
400 Invalid FormatThe request body is malformed.Check JSON syntax, headers, endpoint, and required fields.
401 Authentication FailsWrong, missing, expired, or revoked API key.Confirm the key, environment variable, and Authorization: Bearer header.
402 Insufficient BalanceYour account has run out of balance.Check Billing and add funds on the Top Up page.
422 Invalid ParametersThe request contains unsupported or invalid parameters.Confirm the model name and parameter format.
429 Rate Limit ReachedYou are sending requests too quickly or hitting dynamic concurrency limits.Slow requests, add retry logic, and use exponential backoff.
500 Server ErrorDeepSeek server issue.Retry after a brief wait and contact support if it continues.
503 Server OverloadedHigh traffic or temporary overload.Retry after a brief wait.
Email registration issueYour email domain may not be supported.Try Gmail, Outlook, Hotmail, or Yahoo, or contact DeepSeek support.

DeepSeek’s rate limit page says concurrency is dynamically limited based on server load, and reaching the concurrency limit returns HTTP 429.


Official DeepSeek API Key vs Third-Party Gateways

An official DeepSeek API key gives you direct access to DeepSeek through the DeepSeek Platform. This is usually the best option when you want direct billing, direct model access, and official DeepSeek API behavior.

Third-party gateways can be useful if you want one account for multiple AI providers. However, they may use different pricing, routing, limits, logging policies, retry behavior, and model aliases. A key from a third-party platform is not the same as an official DeepSeek API key.

For this guide, use the official DeepSeek Platform unless your project specifically requires a multi-model gateway.


Best Practices Before Using the Key in Production

Before connecting your DeepSeek API key to a production app, apply these practices:

AreaBest practice
Usage monitoringReview usage and billing regularly. DeepSeek’s FAQ explains that usage can be exported and broken down by API key.
RetriesUse retries with exponential backoff for 429, 500, and 503 errors.
LoggingLog status codes and request IDs, not secrets or full authorization headers.
Frontend securityKeep the API key server-side. Never expose it in browser code.
EnvironmentsUse different keys for development, staging, and production.
RotationRotate keys periodically and immediately after any suspected leak.
OwnershipDocument which app, service, or team owns each key.
Cost controlStart with low-volume tests before scaling traffic.

Production API key management is not just about hiding the key. It also includes ownership, rotation, monitoring, access control, and fast revocation when something goes wrong.


Frequently Asked Questions About DeepSeek API Key

Is a DeepSeek API key free?

Creating a key may not be the same as receiving free API usage. DeepSeek’s pricing is token-based, and usage is deducted from topped-up or granted balance. Check the official pricing and billing pages before production use.

Where do I find my DeepSeek API key?

Log in to the DeepSeek Platform and open the API Keys section. Look for labels such as API Keys, Create API key, Create secret key, or similar dashboard wording.

Can I use DeepSeek with the OpenAI SDK?

Yes. DeepSeek’s docs show examples using the OpenAI SDK by setting the base URL to https://api.deepseek.com and passing your DeepSeek API key.

What is the DeepSeek API base URL?

For the OpenAI-compatible format, use https://api.deepseek.com. For the Anthropic-compatible format, use https://api.deepseek.com/anthropic.

Why is my DeepSeek API key not working?

Common reasons include a missing environment variable, wrong key, revoked key, malformed authorization header, unsupported model name, insufficient balance, or rate limit. Start by checking whether the error is 401, 402, 422, or 429.

How do I fix a 401 error?

A 401 Authentication Fails error usually means the API key is wrong or missing. Confirm your key, check that DEEPSEEK_API_KEY is set correctly, and make sure your request includes Authorization: Bearer YOUR_DEEPSEEK_API_KEY.

How do I fix insufficient balance?

If you receive 402 Insufficient Balance, check your account balance and add funds on the Top Up page. DeepSeek’s docs identify 402 as a balance issue.

Can I use deepseek-chat or deepseek-reasoner?

You should use the current model IDs deepseek-v4-flash or deepseek-v4-pro for new projects. DeepSeek says deepseek-chat and deepseek-reasoner are legacy names that will be discontinued on July 24, 2026.

Should I put my DeepSeek API key in frontend code?

No. Keep the key server-side. If you put an API key in frontend JavaScript, users can inspect your code and extract it. Use your backend to call DeepSeek securely.

How do I revoke or rotate a DeepSeek API key?

Go to the API Keys section in the DeepSeek Platform, create a replacement key, update your application secrets, test the new key, then revoke or delete the old key. If the old key was exposed, rotate it immediately.


Conclusion

Getting a DeepSeek API key is straightforward: sign in to the DeepSeek Platform, create a key in the API Keys section, store it securely, add balance if required, and test it with a small request. For new projects, use deepseek-v4-flash or deepseek-v4-pro, not legacy model names.

Before production use, protect the key like a password, keep it server-side, monitor token usage and billing, add retry logic for rate limits and overloads, and check the official DeepSeek API documentation and DeepSeek Models & Pricing page for current model and pricing changes.