Create advanced Works with: Any AI

API Rate Limiting and Quota Design

Decision tree

Define fair usage limits and the enforcement logic.

The Open buttons send the prompt text as currently shown below to that site only when you click. Fill in the placeholders first.

Define fair usage limits and the enforcement logic for my API. API purpose and consumers: [API_AND_CONSUMERS]. Cost of requests (cheap or expensive endpoints): [REQUEST_COSTS]. Traffic profile and peak: [TRAFFIC]. Plans or tiers: [PLANS]. Infrastructure (gateway, cache, language): [INFRASTRUCTURE].

Use this tree:
1. What are we protecting: stability, cost, fairness between customers, or abuse prevention? Pick the main goal for each endpoint class.
2. Identify the limit key: API key, user, IP address, or tenant. IF clients share IPs THEN avoid IP-only limits.
3. Choose an algorithm: fixed window (simple, bursty at boundaries), sliding window (smoother), token bucket (allows bursts), or leaky bucket (smooth output). Recommend one per use case with the reasons.
4. Set numbers: derive limits from capacity and plan (show arithmetic), with a burst allowance and different costs for expensive endpoints.
5. Quotas: daily or monthly caps for plans, and how overages work.
6. Responses: status 429 with a Retry-After header and rate limit headers; a clear JSON error.
7. Client guidance: backoff with jitter, caching, and batching.
8. Observability: per-customer dashboards and alerts; an exemption and increase-request process.

Provide pseudocode or code for the chosen algorithm with a shared store, tests for boundary behavior, and a documentation snippet for developers.

Fill in before use

Optional: type your details and the prompt above updates. Nothing is saved or sent.

Replace each bracketed placeholder with your own details, then paste into Any AI or another assistant.

Related prompts