Notas / 21

DeepSeek rate limits and what a retry covers

2026-11-19Notas da Modelry

A rate limit is three separate limits wearing one name: requests per minute per key, non-streaming requests in flight, and a wall-clock ceiling on a single request. They return different codes, carry different headers, and need different client behaviour — and a retry loop tuned for one of them makes the other two worse. This article separates them, shows the exact response bodies from a load test that produced both at once, explains why the 429 window is fixed rather than rolling (which changes what retry-after means), and states precisely what failover does and does not cover, since a retry after the first streamed token is not a retry at all.

### Three limits, not one

| Limit | Scope | Exceeded → | Header | Correct client behaviour | |---|---|---|---|---| | Requests per minute | one API key, fixed one-minute window | 429 rate_limit_exceeded | retry-after: 50 | sleep exactly that, then one request | | Non-streaming in flight | the platform, per instance | 503 concurrency_limit | retry-after: 2 | retry shortly, or switch to stream: true | | Request duration | one request | connection closed | — | stream, so the clock measures time-to-first-token |

All three appeared in a single probe: 75 concurrent non-streaming calls from one key, fired at once. The result was 53 × 200, 15 × 429, 7 × 503. That distribution is the point of this article — a client that treats every non-200 the same will spend its retries on the wrong wall.

### What a 429 actually looks like here

HTTP/1.1 429 Too Many Requests
content-type: application/json
retry-after: 50

{"error":{"message":"Rate limit exceeded.","type":"rate_limit_error","code":"rate_limit_exceeded"}}

Two things are worth reading carefully.

retry-after is computed from the clock, not from your burst. The limiter buckets on floor(now / 60000) and the response header is 60 − current second. A request rejected at second 10 of the window says retry-after: 50; a request rejected at second 55 says 5. So the value is not "back off a bit" and not a fixed penalty — it is the exact number of seconds until the counter resets. Sleeping that long and sending one request will succeed. Sleeping half of it will not.

The window is fixed, not rolling. A rolling window (token bucket, sliding log) would let a client that was throttled resume as capacity frees up; a fixed window resets everything at once, which means the retry herd arrives together. This is why the header matters more than usual: the correct client behaviour is not "retry with exponential backoff", it is "read the header, sleep exactly that, send one request, and let the counter refill". Exponential backoff on a 50-second window just wastes 40 seconds of your throughput.

import time, httpx

def post_with_limits(client, url, payload, headers, tries=5):
    for _ in range(tries):
        r = client.post(url, json=payload, headers=headers, timeout=180)
        if r.status_code == 200:
            return r
        if r.status_code == 429:
            wait = int(r.headers.get("retry-after", "60"))
            time.sleep(wait)                  # exact: the counter resets here
            continue
        if r.status_code == 503 and r.json().get("error", {}).get("code") == "concurrency_limit":
            time.sleep(int(r.headers.get("retry-after", "2")))
            payload["stream"] = True          # stop competing for the non-streaming queue
            continue
        r.raise_for_status()                  # 401 / 402 / 404 are not retryable
    raise RuntimeError("rate limited after %d attempts" % tries)

Three lines in that function carry the whole argument: sleep(wait) instead of a backoff curve, stream = True on concurrency_limit, and raise_for_status() on everything else so a 402 does not get retried five times.

### The 503 that is not an outage

HTTP/1.1 503 Service Unavailable
retry-after: 2

{"error":{"message":"Server busy. Retry shortly, or set stream=true to avoid buffering.","type":"server_error","code":"concurrency_limit"}}

This is a queue, not a failure. Non-streaming responses are buffered whole before they are returned, so the number of them in flight is capped; when the cap is full the platform says so in two seconds rather than holding your connection. Streaming bypasses the queue because the body is forwarded as it arrives. In the probe above, the non-streaming calls produced 7 of these while the streaming path was untouched — which is the honest advice: a workload that mixes batch and interactive traffic should send the interactive half as streams and leave the buffer queue to the batch half.

### Failover: what it covers, and the sentence that limits it

The rule is one sentence: where a second channel is configured, a request that has produced no output can be retried on the next channel for the same model; once bytes have been streamed, the response is committed.

That single rule decides three behaviours you can rely on and one you cannot:

  • Reliable: a connection refused or a 5xx before the first token moves to another channel without you noticing, and the model does not change.
  • Reliable: a request that fails this way releases its pre-authorised amount rather than charging you for nothing.
  • Reliable: the model field in the response is the upstream that served it, so routing changes are visible in your logs.
  • Not available: a mid-stream failure cannot be resumed. There is no "restart from token 800" — the request is charged for what was produced and you retry the whole thing or nothing.

Which is why long-running work should be checkpointed at the job level, not the request level: a map-reduce over twenty chunks that dies on the nineteenth should reread eighteen cached notes from disk, not resend eighteen requests.

### The ceiling nobody reads

A single request is closed after 280 seconds regardless of activity. A non-streaming call that thinks for four minutes will never return, however healthy the account. The fix is not a longer timeout on your side — it is stream: true, which keeps the connection alive with events and lets you measure time-to-first-token instead of total duration. Your own client idle timeout should be set above your measured worst case, and that number comes from your traffic, not from a template.

### What to put in a runbook

Four lines, and an on-call engineer can tell the three limits apart at 3 a.m.: 429 → sleep retry-after, it is exact; 503 concurrency_limit → retry in 2s or stream; connection closed at 280s → stream, or split the request; anything else → do not retry, read the code. The machine-readable rate card and per-model limits are on the pricing page, the request-level detail is under API reference, and the failover claim is restated with its limits on /start.

One more limit that is per model rather than per key: the reasoning tier keeps its thinking budget, which changes how long a request can legitimately stay silent — see the deepseek-reasoner model page and the deepseek-chat model page.

A Modelry opera uma plataforma que serve modelos DeepSeek atrás de um único endpoint HTTP, com créditos pré-pagos e impostos tratados pelo merchant of record no checkout, além de uma política de retenção de dados documentada. Comece com $0.50 de crédito de teste: criar uma chave.

Todas as notas

DeepSeek rate limits and what a retry covers — Modelry