Independent guide · not affiliated with, sponsored by, or endorsed by DeepSeek (Hangzhou DeepSeek Artificial Intelligence Co., Ltd.) · Official site: deepseek.com · About this site

    Independent developer guide

    DeepSeek API guide

    The DeepSeek API gives you DeepSeek's hosted models over plain HTTPS, in the same request format as the OpenAI and Anthropic SDKs. You change the base URL to https://api.deepseek.com, use a DeepSeek key, and pick one of two models: deepseek-flash or deepseek-v4-pro. Calls are billed per token, from $0.15 per 1M input tokens.

    This page is written by an independent site, not by DeepSeek. Every model name, limit and price below is checked against the official API docs.

    Last verified: November 3, 2026Reviewed by deepseek.ai editorial desk
    Base URL (OpenAI format)
    https://api.deepseek.com
    Base URL (Anthropic format)
    https://api.deepseek.com/anthropic
    Models
    deepseek-flash · deepseek-v4-pro
    Context / max output
    1M / 384K tokens
    Price from (off-peak)
    $0.15 in · $0.60 out per 1M
    Auth header
    Authorization: Bearer <key>

    How to get a DeepSeek API key

    You need a DeepSeek account and a positive balance — the API has no free tier. A key takes about two minutes.

    1. 1

      Sign in to the DeepSeek platform

      Go to platform.deepseek.com and sign in or create an account. Trouble signing in? See our DeepSeek login help.

    2. 2

      Top up your balance

      Open Top up and add credit. Without balance every call fails with HTTP 402. A promotional balance, if your account has one, is spent first.

    3. 3

      Create the key

      Open API keys, click Create new API key, name it (for example "production") and copy it immediately — it is shown only once.

    4. 4

      Store it outside your code

      Put it in an environment variable called DEEPSEEK_API_KEY. Never commit it to Git or ship it in browser or mobile code.

    # macOS / Linux
    export DEEPSEEK_API_KEY="sk-..."
    
    # Windows PowerShell (current window)
    $env:DEEPSEEK_API_KEY = "sk-..."
    
    # Windows PowerShell (permanent, for new windows)
    [Environment]::SetEnvironmentVariable("DEEPSEEK_API_KEY", "sk-...", "User")

    Your first DeepSeek API call

    Install the official OpenAI SDK (pip install openai or npm install openai), point it at DeepSeek and send a chat completion. No DeepSeek-specific SDK is needed.

    One thing catches most people out: thinking mode is on by default. For quick answers, switch it off as in the examples below; you get the reply faster and pay for fewer tokens.

    # pip install openai
    import os
    from openai import OpenAI
    
    client = OpenAI(
        api_key=os.environ["DEEPSEEK_API_KEY"],
        base_url="https://api.deepseek.com",
    )
    
    response = client.chat.completions.create(
        model="deepseek-flash",
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": "Explain what an API is in one sentence."},
        ],
        # Thinking is on by default. Turn it off for quick, cheap answers:
        extra_body={"thinking": {"type": "disabled"}},
    )
    
    print(response.choices[0].message.content)
    // npm install openai
    import OpenAI from "openai";
    
    const client = new OpenAI({
      apiKey: process.env.DEEPSEEK_API_KEY,
      baseURL: "https://api.deepseek.com",
    });
    
    const res = await client.chat.completions.create({
      model: "deepseek-flash",
      messages: [
        { role: "system", content: "You are a helpful assistant." },
        { role: "user", content: "Explain what an API is in one sentence." },
      ],
      // DeepSeek-specific field; thinking is on by default
      thinking: { type: "disabled" },
    });
    
    console.log(res.choices[0].message.content);
    curl https://api.deepseek.com/chat/completions \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DEEPSEEK_API_KEY" \
      -d '{
        "model": "deepseek-flash",
        "messages": [
          {"role": "system", "content": "You are a helpful assistant."},
          {"role": "user", "content": "Explain what an API is in one sentence."}
        ],
        "thinking": {"type": "disabled"}
      }'
    # pip install anthropic
    import os
    import anthropic
    
    client = anthropic.Anthropic(
        api_key=os.environ["DEEPSEEK_API_KEY"],
        base_url="https://api.deepseek.com/anthropic",
    )
    
    message = client.messages.create(
        model="deepseek-flash",
        max_tokens=1000,
        messages=[{"role": "user", "content": "Explain what an API is in one sentence."}],
    )
    
    print(message.content)

    Keep the conversation yourself

    The API is stateless: DeepSeek does not remember earlier messages. For a multi-turn chat, append each answer to your message list and send the whole list again.

    messages = [{"role": "user", "content": "What's the highest mountain in the world?"}]
    response = client.chat.completions.create(model="deepseek-flash", messages=messages)
    messages.append(response.choices[0].message)      # keep the answer
    
    messages.append({"role": "user", "content": "And the second highest?"})
    response = client.chat.completions.create(model="deepseek-flash", messages=messages)

    DeepSeek API models

    There are two current model names. Each name always points at DeepSeek's latest release of that model, so results can shift slightly when DeepSeek ships an update.

    Model nameServesContextMax outputImagesOff-peak price (in / out per 1M)Use it for
    deepseek-flashDeepSeek-V4.1-Flash-10171M384KYes$0.15 / $0.60Default for chat, agents, tool use, RAG and vision — fast and cheapest
    deepseek-v4-proDeepSeek-V4-Pro-08131M384KNo$0.66 / $1.98Hardest reasoning, long multi-step coding and math

    Both models support thinking and non-thinking mode, JSON output, tool calls, streaming, the OpenAI Responses API and the Anthropic API format. FIM (fill-in-the-middle) completion and chat prefix completion are in beta and FIM only works with thinking off.

    Old model names: what still works

    deepseek-v4-flash · deepseek-v4-flash-vision-exp

    Still accepted, temporarily routed to DeepSeek-V4.1-Flash and billed at the Flash price (since 10 September 2026).

    Use instead: deepseek-flash

    deepseek-chat · deepseek-reasoner

    Scheduled for discontinuation on 24 July 2026 and no longer in the official model list.

    Use instead: deepseek-flash (thinking off for the old chat behaviour, on for reasoner)

    Thinking mode

    In thinking mode the model works through the problem before it answers. That makes it better at maths, code and multi-step tasks, and slower and more token-hungry on simple ones. It is on by default for both models.

    • Switch it with "thinking": {"type": "enabled"} or "disabled". In the OpenAI Python SDK this goes in extra_body.
    • Set the effort with reasoning_effort: low, high (default) or max.
    • The reasoning comes back in reasoning_content, next to the normal content. Its size is reported in usage.completion_tokens_details.reasoning_tokens.
    • Default max_tokens: 8K with thinking off, 64K with thinking on, 128K at effort max.
    • temperature has no effect in thinking mode, and tool_choice: "required" returns HTTP 400 — switch thinking off for those requests.
    • When you use tools in thinking mode, send reasoning_content back unchanged in later requests, or the API returns HTTP 400. Without tools it is ignored, so you can leave it out.
    response = client.chat.completions.create(
        model="deepseek-v4-pro",
        messages=[{"role": "user", "content": "Is 1,001 a prime number? Explain."}],
        reasoning_effort="high",                       # "low", "high" or "max"
        extra_body={"thinking": {"type": "enabled"}},  # the default, shown for clarity
    )
    
    print(response.choices[0].message.reasoning_content)  # the chain of thought
    print(response.choices[0].message.content)            # the final answer

    DeepSeek API pricing

    You pay per 1M tokens, with a cheaper rate for input that hits DeepSeek's context cache. Rates double during peak hours: 01:00–04:00 and 06:00–10:00 UTC, Monday to Friday, excluding Chinese public holidays. Everything else, including weekends, is off-peak.

    Per 1M tokensdeepseek-flash off-peakdeepseek-flash peakdeepseek-v4-pro off-peakdeepseek-v4-pro peak
    Input, cache hit$0.003$0.006$0.022$0.044
    Input, cache miss$0.15$0.30$0.66$1.32
    Output$0.60$1.20$1.98$3.96
    • A cache hit makes input about 98% cheaper on deepseek-flash and 97% on deepseek-v4-pro. Put the long, unchanging part of your prompt (system prompt, documents) first so repeated calls hit the cache; usage.prompt_cache_hit_tokens shows how much did.
    • Search and Fetch (live web results for agents) cost $0.75 per 1,000 successful requests.
    • Rates checked against the official rate card; full history and more examples on our DeepSeek pricing page.
    Monthly cost calculator
    10M tokens
    2M tokens
    deepseek-flash
    $2.70
    all peak: $5.40
    GPT-5.6 Terra
    $55.00
    Claude Sonnet 5
    $40.00

    Cache-miss input rates, no cache hits counted. DeepSeek rates verified 2026-09-18; competitor list prices verified 2026-07-25.

    Rate limits and concurrency

    • DeepSeek limits concurrent requests per account: 2,500 for deepseek-flash, 500 for deepseek-v4-pro. Extra API keys do not raise it. Above the limit you get HTTP 429.
    • There is no published requests-per-minute or tokens-per-minute limit. You can request a higher concurrency limit from DeepSeek at no extra cost.
    • Pass a user_id per end user (letters, digits, _, -; no personal data) to keep their cache and scheduling separate.
    • Under load the server sends empty lines (or : keep-alive comments when streaming) while you wait. Official SDKs ignore them; a custom HTTP parser must too. If inference has not started after 10 minutes, the connection is closed.

    DeepSeek API error codes and fixes

    CodeMeaningUsual causeFix
    400Invalid FormatThe request body is malformed.Fix the body using the hint in the error message.
    401Authentication FailsWrong or revoked API key.Check the key, or create a new one on the platform.
    402Insufficient BalanceThe account has no balance left.Top up on the platform, then retry.
    422Invalid ParametersA parameter value is not allowed.Correct the parameter named in the error message.
    429Rate Limit ReachedToo many requests at once (concurrency limit).Back off and retry, queue requests, or ask for a higher limit.
    500Server ErrorA problem on DeepSeek's side.Retry after a short wait; contact DeepSeek if it persists.
    503Server OverloadedHigh traffic on DeepSeek's side.Retry after a short wait.

    Retry 429, 500 and 503 with exponential back-off. Do not retry 400, 401, 402 or 422 — they fail the same way until you fix the request or the account. Outages are posted on status.deepseek.com.

    Use the DeepSeek API in Claude Code, Codex and other agents

    Because DeepSeek also speaks the Anthropic and OpenAI Responses formats, coding agents can run on it with a few environment variables. For Claude Code, point the Anthropic base URL at DeepSeek and pick the model ([1m] selects the 1M-token context):

    # macOS / Linux
    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_HAIKU_MODEL=deepseek-flash
    
    # Windows PowerShell
    $env:ANTHROPIC_BASE_URL = "https://api.deepseek.com/anthropic"
    $env:ANTHROPIC_AUTH_TOKEN = $env:DEEPSEEK_API_KEY
    $env:ANTHROPIC_MODEL = "deepseek-flash[1m]"
    $env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "deepseek-flash"

    Any request for a claude-opus* model runs on deepseek-v4-pro and is billed at the Pro rate; other claude* names run on deepseek-flash. Some Anthropic features, such as cache_control, citations and MCP servers inside the request, are ignored. DeepSeek's Claude Code guide also sets the sub-agent model and effort level, and there are guides for Codex, OpenCode and others; its own open-source agent is covered in our DeepSeek Harness review.

    Moving from OpenAI or an older DeepSeek integration

    1. Set the base URL to https://api.deepseek.com and use your DeepSeek key.
    2. Change the model to deepseek-flash. Replace deepseek-chat, deepseek-reasoner and deepseek-v4-flash while you are at it.
    3. Decide on thinking per request: off for chat and extraction, on for reasoning-heavy work.
    4. Drop frequency_penalty and presence_penalty — DeepSeek ignores them.
    5. For JSON, set response_format: {"type": "json_object"} and ask for JSON in the prompt; the API requires both.
    6. Add back-off for HTTP 429, and alerts on HTTP 402 so an empty balance does not take your app down.

    Sending user data to a hosted API? Read where DeepSeek processes API data first. If that is a blocker, the open weights can run on your own hardware — see running DeepSeek locally.

    DeepSeek API: frequently asked questions

    No. Creating an account and an API key is free, but every call is billed per token from your account balance, so you top up first. The cheapest model, deepseek-flash, costs $0.15 per 1M input tokens and $0.60 per 1M output tokens off-peak. If DeepSeek has granted your account a promotional balance, that is used before the money you topped up. The DeepSeek chat app at chat.deepseek.com is free; the API is not.

    Sign in at platform.deepseek.com, top up your balance, open "API keys", click "Create new API key", give it a name and copy it straight away — it is shown only once. Store it in an environment variable such as DEEPSEEK_API_KEY rather than in your code.

    Use https://api.deepseek.com for the OpenAI-compatible format (chat completions live at https://api.deepseek.com/chat/completions) and https://api.deepseek.com/anthropic for the Anthropic-compatible format. You do not need a /v1 suffix.

    Start with deepseek-flash (DeepSeek-V4.1-Flash-1017). It is the cheapest model, supports images, and handles chat, tools and agents well. Switch individual requests to deepseek-v4-pro (DeepSeek-V4-Pro-0813) when they need the strongest reasoning; it costs $0.66 in / $1.98 out per 1M tokens off-peak. Both have a 1M-token context window.

    No — do not build on them. Both were scheduled for discontinuation on 24 July 2026 and are no longer in the official model list. Replace them with deepseek-flash: thinking off for the old deepseek-chat behaviour, thinking on for deepseek-reasoner. The older deepseek-v4-flash name is still accepted for now, but it is only routed to V4.1-Flash, so switch it to deepseek-flash too.

    platform.deepseek.com is DeepSeek's developer console. You use it to create and revoke API keys, top up your balance, check usage and spending, and read the official API docs. It is separate from the consumer chat app at chat.deepseek.com.

    DeepSeek limits concurrent requests per account: 2,500 for deepseek-flash and 500 for deepseek-v4-pro, no matter how many API keys you use. Above that you get HTTP 429. There is no published requests-per-minute or tokens-per-minute cap, and you can ask DeepSeek for a higher limit at no extra cost.

    Off-peak, deepseek-flash costs $0.15 per 1M input tokens ($0.003 on a cache hit) and $0.60 per 1M output tokens; deepseek-v4-pro costs $0.66 / $0.022 / $1.98. During peak hours (01:00–04:00 and 06:00–10:00 UTC, Monday to Friday, excluding Chinese public holidays) every rate doubles. Search and Fetch cost $0.75 per 1,000 successful requests.

    Yes. Point the OpenAI SDK at https://api.deepseek.com or the Anthropic SDK at https://api.deepseek.com/anthropic, use your DeepSeek key and a DeepSeek model name. Streaming, JSON output and tool calls use the same request shape. DeepSeek-specific options such as "thinking" go in extra_body (Python) or as an extra field (Node).

    HTTP 401 means the key is wrong or was deleted — create a new one. HTTP 402 means your balance is empty — top up. HTTP 400 or 422 usually means a malformed body or an invalid parameter, for example tool_choice: "required" while thinking is on. Also check that the base URL is https://api.deepseek.com and the model is deepseek-flash or deepseek-v4-pro.