Rate limits and concurrency control for OpenAI-compatible APIs
This article was prepared by the SiberAI team.
OpenAI-compatible clients make it easy to fire many completions in parallel. Gateways still enforce rate and concurrency limits. Treating every 429 as a transient blip—and immediately retrying the same burst—turns a soft limit into a self-inflicted outage. This note covers queues, backoff and per-key budgets using SiberAI’s public behaviour.
What a 429 is telling you
SiberAI’s error reference lists 429 as a signal to wait because of rate or concurrency. It is not the same as 401 (key/lifetime/user state), 402 (balance or usage reconciliation), or 400 (bad request shape). Retrying an invalid body or a revoked key will not help. After a call that started and then broke, check the usage record first—automatic, fully idempotent production retries are not promised.
Read HTTP status together with error.code. Keep Authorization headers out of logs and tickets.
Prefer a queue over a thundering herd
When several workers share one customer key, put outbound chat completions behind a small queue:
- Cap in-flight requests per key (concurrency budget).
- Cap sustained request rate (token bucket or fixed window—pick one and measure).
- Separate interactive UI traffic from batch jobs with different keys so a batch storm cannot starve the IDE.
SiberAI issues sai_ide_-prefixed customer keys; new keys last 30 days and are checked for scope and revocation on each call (authentication). One key per workload makes panel usage readable and revocation surgical.
Backoff that respects the error class
import random, time
RETRYABLE = {429, 502, 503, 504}
def backoff_seconds(attempt, base=0.5, cap=30.0):
# full jitter: spread clients so they do not align
return min(cap, base * (2 ** attempt)) * random.random()
def should_retry(status):
return status in RETRYABLE
For 429: wait, then retry with a hard attempt ceiling. For 502/503/504: limited backoff. For 401/400/403/404/415: fix the request—do not loop. For 402: open the panel; do not hammer the API. Gateway-oriented notes also appear under rate limits.
Per-key budgets and workspace balance
The agent and the API share the same workspace balance (pricing). A concurrency bug is also a cost bug: parallel workers can reserve or spend faster than a human notices. Practical budgets:
- Max in-flight per key (e.g. low single digits for interactive, higher only after measurement).
- Max daily requests or tokens per key (enforce in your worker, not only “hope”).
- Staging keys isolated from production.
- After deploy, watch panel request status and token breakdown.
API base path remains /api/siberai/v1 on siberai.net with model siber-v3 (quickstart). Wrong host or model produces different errors; do not classify them as rate limits.
Designing the client
- Single flight-control module owned by the platform team.
- Metrics: accepted, 429 count, p95 wait time, in-flight gauge.
- Kill switch: pause batch queues without revoking interactive keys.
- On interrupt mid-call: reconcile usage before retry.
Product home: SiberAI.
Interactive clients should fail fast with a clear “capacity” message when the local queue is full, instead of opening unbounded threads. Batch systems should checkpoint work items so a 429 storm can resume without re-sending every prompt. Review panel usage after raising concurrency—balance and rate limits show up together.
When you share a postmortem, include key id, 429 rate, and the concurrency cap you settled on. Omit prompts that may contain customer data. The goal is a boring, measurable ceiling—not maximum theoretical throughput.
Operational review cadence
Once a week, skim panel usage for the batch key: 429 rate, 402 events, and whether interactive keys stayed healthy. If batch concurrency was raised, write down the old and new caps in the same change ticket. Capacity changes without a recorded ceiling tend to creep until the next incident.
Pair this with a staging soak test: fixed prompt length, fixed max_tokens, rising parallelism until 429 appears, then set production slightly below that point. Re-run after gateway or client upgrades—limits you measured last quarter may not hold.
FAQ
Q: Can I avoid 429 by opening many API keys on the same workspace?
A: Keys help isolate workloads and revocation, but the workspace still has balance and gateway behaviour. Splitting keys is for blast-radius and observability, not for ignoring documented 429 handling.
Q: Is every retry safe after a timeout?
A: No. If the call may have started, check usage first. This API does not guarantee fully idempotent automatic production retries.
Q: Where should I start reading?
A: Rate limits, errors, and quickstart.
Yorumlar
Yorum Gönder