← Concepts

阅读中文版本

API Rate-Limit Headers

Rate-limit headers tell clients how much quota remains and when it resets, so they can back off before receiving a 429 instead of retrying blindly.

api

Definition

Rate-limit headers are response metadata that expose the applied quota policy, the remaining budget, and the reset window, letting clients pace requests and handle 429 responses deterministically.

Context and scope

Use them on any API with per-key, per-tenant, or per-IP quotas, especially when clients retry automatically or run batch jobs against shared capacity.

Common misconceptions

  • Rate-limit headers enforce the limit; they only describe it and can be stale
  • Every API exposes the same fields; vendor prefixes and drafts differ
  • A client should hardcode the limit instead of reading the advertised policy

Anti-patterns

  • Returning 429 with no Retry-After or quota metadata
  • Advertising a generous limit while a hidden burst limiter rejects traffic earlier
  • Using rate-limit headers as a security control instead of a cooperative signal

Related concepts

Related examples

Authoritative source

https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers/

Why headers exist

A quota without feedback turns clients into guessers. They either hammer the API until a 429 arrives or back off far more than necessary. Rate-limit headers close that loop by describing the policy and the remaining budget on every response, including successful ones.

How the fields work

The IETF draft defines two structured fields. RateLimit-Policy advertises the quota, for example RateLimit-Policy: "default";q=100;w=60, meaning 100 requests per 60-second window. RateLimit reports current state, such as RateLimit: "default";r=12;t=38, where 12 requests remain and the window resets in 38 seconds. Earlier drafts and many commercial APIs use X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset, which are conventional but not standardized.

When the quota is exhausted, return 429 Too Many Requests with Retry-After (RFC 9110) so clients know when a retry is safe. Keep the two mechanisms consistent: Retry-After should not contradict the reported reset.

When to use them

Expose headers whenever clients share a quota or run unattended jobs. They are most valuable for SDKs and integrations, which can adapt concurrency dynamically instead of hardcoding a constant. For a single internal caller with a fixed contract, the headers add little.

Trade-offs

Detailed headers leak your policy shape and can help an attacker tune traffic just below the threshold. Very precise remaining values also create herd effects when thousands of clients see the same reset second, so jittered resets and Retry-After randomization help. Proxies and CDNs may strip or cache the fields, so verify they survive the edge.

Example and misconceptions

A batch client reads RateLimit: "default";r=0;t=17 and schedules its next call after 17 seconds plus jitter, avoiding a retry storm. A naive client ignores the field, retries immediately, and receives another 429.

The key misconception is that headers are enforcement. Enforcement lives on the server; headers are advisory telemetry that clients may ignore. Design the server to stay correct when they do.

Related concepts: Rate Limiting, Retry Budget, and API Gateway.