DeepSeek API guide — API keys, pricing and a first request

Last content update 2026-10-29
Service guide
QUICK ANSWER
Start on the official DeepSeek Platform by checking your API key and balance. Free access to Chat does not mean free API calls. Check current model names and input/output token prices, then compare the response and Usage after one small request, keeping the key out of public code. For 401, check the key; for 402, check the balance; for 429, check request pacing and concurrency limits.

Create an API key and check the balance

This guide is for developers calling DeepSeek models from a program. If you only want to ask questions in Korean or another language on the web, start with the related guide to ordinary chat.

  1. Sign in to the official Platform above with the account you intend to use.
  2. Create a key in API Keys and store it in the connected program’s secret configuration.
  3. In Top Up and Billing, check payment methods, the billing account and records.
  4. In Usage, check the time range and API Key filters.

The official FAQ lists PayPal, bank cards, Alipay and WeChat Pay for top-ups. Check what your account actually offers and the payment conditions, then fund only what you need. The FAQ says topped-up balances do not expire; do not assume separately granted credits have the same conditions.

Treat the key like a password. Keep it out of repositories, shared documents, screenshots and browser JavaScript. For a deployed service, pass it through server-side secrets. Separating keys by team member or program purpose makes usage easier to review.

Calculate prices by input, output and time period

The following official rates are in US dollars per million tokens, checked on 25 October and rechecked on 29 October 2026. Recheck the current table before calling, because names, rates and time periods can change.

Model and billing itemOff-peakPeak
deepseek-flash input, cache hit$0.003$0.006
deepseek-flash input, cache miss$0.15$0.30
deepseek-flash output$0.60$1.20
deepseek-v4-pro input, cache hit$0.022$0.044
deepseek-v4-pro input, cache miss$0.66$1.32
deepseek-v4-pro output$1.98$3.96

Peak periods are 01:00–04:00 and 06:00–10:00 UTC, Monday–Friday, excluding Chinese public holidays. Other hours, weekends and Chinese public holidays use off-peak rates. Those are UTC times, not the same clock times in Korea or your own location.

Estimate model cost by dividing each category’s token count by one million, multiplying by its rate and adding the results. Character counts and question counts are not enough. Cache hits, output length and reasoning mode affect usage. Separate Search and Fetch API charges are not included in this table.

Prepare a small first request in Python

This Python 3 standard-library example uses the official Chat Completion format. No SDK installation is needed; the key is entered without echo in the terminal. It is not executed on this page, and no paid response-quality test was performed. Running it can incur charges on your account.

Save it as deepseek_first.py and run python3 deepseek_first.py in a terminal. If Windows uses py as the Python command, use py deepseek_first.py. If a warning says hidden key input is unavailable, stop entering the key and use a normal terminal.

import getpass
import json
import urllib.error
import urllib.request

key = getpass.getpass("DeepSeek API key: ").strip()
if not key:
    raise SystemExit("API key is required")

payload = {
    "model": "deepseek-flash",
    "messages": [
        {"role": "user", "content": "한국어로 짧게 인사해 줘."}
    ],
    "thinking": {"type": "disabled"},
    "max_tokens": 256,
    "stream": False,
}
request = urllib.request.Request(
    "https://api.deepseek.com/chat/completions",
    data=json.dumps(payload).encode("utf-8"),
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer " + key,
    },
)
try:
    with urllib.request.urlopen(request, timeout=90) as response:
        result = json.load(response)
except urllib.error.HTTPError as error:
    raise SystemExit(f"HTTP {error.code}; check key/balance/limits")

print(result["choices"][0]["message"]["content"])
print(result.get("usage", {}))

The Korean sample message asks for a brief greeting in Korean. Current official documentation lists deepseek-flash and deepseek-v4-pro. The example disables Thinking and caps output at 256 to keep the response short. That is not a fixed price or a guarantee of a total cost ceiling.

For a successful response, inspect its text and usage, then compare them with the same account, time range and key in the Platform. A timeout does not prove the server never received the request; inspect usage before automatically repeating it.

Check 401, 402 and 429 errors

Code or symptomCheck first
401 authentication failureKey typos, whitespace, revocation, the DeepSeek key and endpoint
402 insufficient balanceBalance of the key-owning account and the account actually funded
400 or 422 request errorJSON structure, fields and parameters supported by the current model
429 limit reachedRequest spacing, concurrent requests and official limits
500 or 503 server problemWait briefly, check service status and stop endless retries

Do not send another provider’s key to a DeepSeek endpoint or use your consumer login password as an API key. For support, prepare the time, code, model and request structure with sensitive information removed. Do not send the full key.

Review usage by key and revoke a leaked key

Use Usage → Time → API Key to select the period and key. The official FAQ also describes opening the amount CSV from an Export ZIP file to inspect costs by key.

If a key is exposed, use API Keys → that key’s trash icon → Revoke and check the confirmation. A revoked key cannot be reused, so replace it in connected programs. Revoking a key and refunding a remaining top-up balance are separate procedures. For an unused-balance refund, check Billing and the official support guidance for the payment method.

Official sources

Frequently asked questions

The DeepSeek app is free. Is the API free too?
Do not apply the free Chat/app description to the developer API. API charges are deducted according to current token prices and the account's topped-up or granted balance. Do not build your setup around an assumption of free credits.
Can I keep using an old deepseek-v4-flash example?
Current official documentation recommends deepseek-flash. The old deepseek-v4-flash and deepseek-v4-flash-vision-exp names are accepted, but those older models have been retired and requests are served by the current Flash model. An accepted name does not mean the old model is still running.
Why is my balance missing after a top-up?
First check whether the funded account owns the API key. The official FAQ recommends checking accounts reached through different login methods, such as Google and email, and their top-up records. Do not keep making the same payment just because you received 402.
What if my API key is exposed in GitHub or browser code?
Revoke the key in the official Platform's API Keys area and replace it in application secrets with a new key. Removing the string from a public file does not invalidate a copied key. Review usage for that key, too.