TTodAPI

DeepSeek

DeepSeek API rate limits

Two numbers decide throughput on the gateway: how many requests you send, and how many streams you hold open. The second one surprises people, because a stream keeps its slot until the last token.

The two limits

LimitWhat consumes itSymptom
Requests per windowEvery call, streaming or notBursty 429s right after a queue drains
ConcurrencyEach open request429s only on slow or streaming calls
Account balanceSpend, not rate402, and retrying cannot fix it

Long-context generations hurt twice: more tokens billed, and a slot held for longer. If your p95 completion time is 40 seconds and you open 20 streams, you are consuming 20 slots for most of a minute.

429 vs 402 — the distinction people get wrong

Correct backoff

import random, time
from openai import OpenAI, RateLimitError, APIStatusError

client = OpenAI(api_key="sk-...", base_url="https://todapi.work/v1")

def call(**kwargs):
    delay = 0.5
    for attempt in range(6):
        try:
            return client.chat.completions.create(**kwargs)
        except RateLimitError:
            if attempt == 5:
                raise
            time.sleep(delay + random.uniform(0, delay / 2))
            delay = min(delay * 2, 8)
        except APIStatusError as exc:
            if exc.status_code == 402:      # balance, not rate
                raise
            raise

Two details matter more than the numbers: jitter (so parallel workers do not retry in lockstep) and a ceiling (so a long outage does not become an unbounded wait).

Reducing pressure without buying more quota

  1. Cap concurrency explicitly. Most SDKs will happily open as many streams as you ask for; the limit is yours to enforce.
  2. Trim context. A 10k-token system prompt on every call costs tokens and stretches generation time, which holds the slot.
  3. Queue instead of burst. A small worker pool with a bounded queue produces fewer 429s than unbounded parallelism.
  4. Split across keys when one key is the bottleneck — balance is per account, limits are per key.

Retry policy in one line

Retry 429 and 5xx with exponential backoff plus jitter; never retry 401, 402, 403 or 404 — the request or the account state has to change first. Full table in 429 explained.

Streaming failures

A stream that dies mid-answer is not a clean error: you may have been billed for the tokens produced. Treat it as failed, discard the partial output unless you can resume, and retry the call. The mechanism is the same on every model — see 429 and retry policy.

DeepSeek pricing

What a retry costs: $0.0252 / $0.1008 per 1M.

429 explained

Gateway-wide rate limit behaviour.

Model page

Code samples and limits.