EN ▾

DeepSeek API Rate Limit: Limits, Errors and Retries

Two numbers decide how fast you can send requests: how many run at the same time and how many start per minute. Here are the limits on this API, how they interact, and code that respects them.

Updated

Key points

  • A full key allows 8 concurrent requests and 300 requests per minute; a trial key allows 2 and 60.
  • Concurrency is usually the limit you hit first, because slow completions hold a slot for many seconds.
  • Use a semaphore plus retries with backoff, and read the X-RateLimit headers instead of guessing.
  • This is not DeepSeek's official API, so for DeepSeek's own limits check their documentation.
Illustration of a gate with eight channels controlling streams of requests, representing API rate limits

The limits on this API

If you searched for deepseek api rate limit, one clarification first: this site is an independent OpenAI-compatible API running one open-weight model. It is not DeepSeek's official service, so DeepSeek's own limits are theirs to document. Check their current docs for those. What follows are the limits that apply here.

LimitFull keyTrial key
Concurrent requests82
Requests per minute30060
Max request body8 MB8 MB
Context window100,000 tokens100,000 tokens

The context window counts the prompt plus the completion. The responses carry X-Request-Id, X-Balance-USD, X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency, so your code can read the limits that apply to its own key.

Requests per minute versus concurrency

These are two separate ceilings, and they behave differently.

  • Requests per minute limits how many requests you may start in a rolling minute.
  • Concurrency limits how many requests may be in flight at once. A request holds its slot from the moment you send it until the response is complete. For a streamed reply, treat the slot as held until you have read the stream to the end.

Which one bites first depends on how long each request takes. With a full key you have 8 slots. If the average request lasts 10 seconds, each slot finishes 6 requests per minute, so you top out at 8 x 6 = 48 requests per minute. That is far below 300. To actually reach 300 per minute with 8 slots, the average request would have to finish in 8 x 60 / 300 = 1.6 seconds.

Long creative outputs and big prompts take seconds, so for most chat and writing workloads the concurrency cap is your real throughput limit. Short classification calls with tiny outputs are the ones that approach the per-minute cap.

The trial key works the same way with smaller numbers: 2 slots and 60 per minute. To reach 60 per minute the average request must finish within 2 x 60 / 60 = 2 seconds.

Staying under the concurrency limit in Python

The simplest control is a semaphore sized to your key. This example sends 40 prompts with at most 8 in flight, using the OpenAI async client.

import asyncio
from openai import AsyncOpenAI

client = AsyncOpenAI(
    base_url="https://api.deepseeknsfw.com/v1",
    api_key="YOUR_API_KEY",
    max_retries=4,
)
slots = asyncio.Semaphore(8)  # use 2 for a trial key

async def ask(prompt):
    async with slots:
        r = await client.chat.completions.create(
            model="uncensored",
            messages=[{"role": "user", "content": prompt}],
            max_tokens=300,
        )
        return r.choices[0].message.content

async def main():
    prompts = ["Summarize item %d in one sentence." % i for i in range(40)]
    results = await asyncio.gather(*(ask(p) for p in prompts))
    print(len(results), "done")

asyncio.run(main())

The max_retries setting makes the SDK retry connection errors, 429 and 5xx responses with a short delay. That covers brief spikes. It does not replace the semaphore: retrying a flood of requests only makes the flood last longer.

Pacing requests per minute

If your calls are short, add a pacer so you do not start more than 300 per minute. A simple approach is to space starts evenly: 60 / 300 = 0.2 seconds apart. Keep some headroom and aim for 240 per minute (one start every 0.25 seconds) so clock differences do not push you over.

import time
from openai import OpenAI

client = OpenAI(base_url="https://api.deepseeknsfw.com/v1", api_key="YOUR_API_KEY")
INTERVAL = 0.25  # 240 requests per minute; use 1.25 for a trial key
last = 0.0

def paced_call(prompt):
    global last
    wait = last + INTERVAL - time.monotonic()
    if wait > 0:
        time.sleep(wait)
    last = time.monotonic()
    return client.chat.completions.create(
        model="uncensored",
        messages=[{"role": "user", "content": prompt}],
        max_tokens=50,
    )

This single-threaded version never has more than one request in flight, so it satisfies the concurrency cap too. For parallel work, combine it with the semaphore from the previous section.

The same idea in Node

Node has no built-in semaphore, but a small worker pool does the same job. Each worker pulls the next prompt until the queue is empty, so no more than 8 requests are ever in flight.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.deepseeknsfw.com/v1",
  apiKey: process.env.API_KEY,
  maxRetries: 4,
});

const prompts = Array.from({ length: 40 }, (_, i) => "Summarize item " + i + " in one sentence.");
const results = [];
let next = 0;

async function worker() {
  while (next < prompts.length) {
    const i = next++;
    const r = await client.chat.completions.create({
      model: "uncensored",
      messages: [{ role: "user", content: prompts[i] }],
      max_tokens: 300,
    });
    results[i] = r.choices[0].message.content;
  }
}

await Promise.all(Array.from({ length: 8 }, worker));
console.log(results.length, "done");

Reading the headers instead of hard-coding numbers

Your key type decides the limits, so let the response tell you. With the Python SDK, ask for the raw response to see the headers.

from openai import OpenAI

client = OpenAI(base_url="https://api.deepseeknsfw.com/v1", api_key="YOUR_API_KEY")

raw = client.chat.completions.with_raw_response.create(
    model="uncensored",
    messages=[{"role": "user", "content": "ping"}],
    max_tokens=5,
)
print(raw.headers.get("X-RateLimit-Limit-Requests"))
print(raw.headers.get("X-RateLimit-Limit-Concurrency"))
print(raw.headers.get("X-Balance-USD"))
completion = raw.parse()

Set your semaphore and pacer from those two values. When you upgrade from a trial key to a full key, the code adapts without a change. Log X-Request-Id with every error too; it is the first thing to quote if you need to trace a specific call.

Troubleshooting slow throughput

SymptomLikely causeFix
Many 429 responses at startupBurst of parallel calls above the slot countCap parallelism with a semaphore sized to the concurrency limit
Steady throughput well under 300 per minuteLong completions holding slotsLower max_tokens, add stop, shorten prompts
Errors only on the trial keyTrial limits are 2 concurrent and 60 per minuteUse a semaphore of 2 and a pacer of one start per second
Rejected bodyRequest larger than 8 MBSend less context or split the job
Slow streaming loopStreams not fully read, slots stay busyRead to the end or close the stream cleanly

Handling errors and large batches

Treat a rate-limit response as a signal to slow down, not as a failure to hide. A reasonable policy:

  • Retry on 429 and on 5xx responses with exponential backoff and a little random jitter.
  • Do not retry 4xx errors that point at your request, such as a body over 8 MB or a prompt that overflows the 100,000-token window. Fix the request.
  • Failed or refused requests are not charged, so retries on errors do not cost balance.

For a large batch, do the arithmetic before you start. Suppose you need 100,000 short requests on a full key. At 300 per minute that is 100,000 / 300 = 333 minutes, about 5.6 hours, if each call is short enough to hit the per-minute cap. At 48 per minute (the 10-second case above) it is 100,000 / 48 = 2,083 minutes, almost 35 hours. In the second case, shortening outputs with max_tokens and stop will help more than any retry logic.

Also keep a durable queue. Write each result to disk or a database as it completes, so a crash at hour four does not cost you the first four hours.

When you need more headroom

Start by checking whether the work can be reshaped. Fewer, larger requests use fewer slots: ask for ten items in one JSON response with response_format: {"type":"json_object"} instead of ten separate calls. The 100,000-token context leaves room for that.

Cost scales linearly with tokens, at $0.15 per 1M input and $0.50 per 1M output, and the plan is prepaid, so a throttled batch costs the same as a fast one. Details on top-ups are on the pricing page, and the API docs list every supported parameter. To test your pacing code with real responses, claim the trial from the API key page and set the semaphore to 2.

Questions and answers

What is the DeepSeek API rate limit?

That is set by DeepSeek and can change, so read their current documentation. On this independent API, a full key allows 8 concurrent requests and 300 requests per minute, and a trial key allows 2 and 60.

Why am I limited even below 300 requests per minute?

Probably concurrency. If each request takes 10 seconds, 8 slots give you only 48 requests per minute. Shorter outputs or smaller prompts free the slots faster.

How do I find my own limits in code?

Read the X-RateLimit-Limit-Requests and X-RateLimit-Limit-Concurrency response headers, and configure your semaphore and pacer from them.

Do retries cost money?

Failed or refused requests are not charged, so retrying an error does not use balance. A retry that succeeds is billed once, like any normal request.

Can I raise the limits?

The documented limits are 8 concurrent and 300 per minute for a full key. For heavy batches, restructure the work into fewer requests and queue the rest.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key