API Rate Limiting Strategies for GPU Inference
Protect inference services with bounded concurrency, per-customer budgets, backpressure, and retry-safe request handling.
By Hostnot GPU ·
An inference application's limiter should protect three resources: admission rate, active compute and money. A request counter alone cannot distinguish a short prompt from a long generation. This guide describes controls for your own backend; Hostnot GPU's actual upstream contract is documented separately in serverless rate-limit handling.
Select the unit before selecting an algorithm
- Requests: contain bursts and abusive retries with an arrival-rate budget.
- Active operations: use a semaphore or worker pool to cap concurrent generations.
- Input and output: validate body size, message count and requested output length before dispatch.
- Spending: track estimated in-flight exposure and settled usage in a consistent currency.
A queue length is a separate bound. If a job's estimated wait consumes its deadline, reject or defer it before paid dispatch. A million pending promises are not useful backpressure. Use per-tenant queues where a large batch must not starve interactive requests.
Choose a limiter for the traffic pattern
A fixed window is simple but allows boundary bursts. A sliding window smooths the accounting boundary at greater state cost. A token bucket admits limited bursts while constraining sustained arrivals; a leaky-bucket style scheduler spaces departures. None of these alone bounds the number of long-running operations, so pair the chosen arrival control with a concurrency cap.
Coordinate state across replicas sharing one platform key. Use atomic admission, an expiry policy and a defined behavior when the coordination store is unavailable. An in-memory limiter on each replica multiplies the intended allowance as you scale. For spending-sensitive work, decide explicitly whether loss of shared state should block dispatch rather than quietly admitting unlimited jobs.
Make retries part of admission
Count retries against the same budgets as first attempts. The Hostnot GPU limiter may return 429 with RATE_LIMITED and Retry-After; upstream inference 429s may lack delay guidance. Parse both supported Retry-After forms, wait at least the valid delay, and use bounded jittered backoff when no valid delay exists.
Keep retry ownership in one layer. If the SDK, worker and frontend all retry independently, a single action can fan out into many operations. Preserve the original idempotency key for the same logical generation, but do not mistake it for guaranteed cached-response replay. Fix 400, 401, 403, 402 and configuration conflicts instead of scheduling unchanged retries.
Observe fairness and overload explicitly
Record queue wait, active count, rejected admissions, deadline expiry, HTTP latency, 429 ratio and useful completion rate. Aggregate by safe tenant identifiers without keys or prompts. Separate locally rejected work from work actually sent upstream, or cost and reliability reports will be misleading.
Use a local stub to test bursts at window boundaries, concurrent replicas, very slow requests, canceled queued jobs, invalid headers and uncertain delivery. Assert that dispatch never exceeds the chosen concurrency cap and that expired jobs never reach the stub. No paid generation is needed to prove these mechanics. Once implementing the real adapter, follow the strict API schema and the error decision tree.