quota-rate-limit-pattern

Implement three-layer API gateway quota and rate limiting with distinct 429 reason codes.

Updated Apr 4, 2026
One-click install
npx skills add https://github.com/saintgo7/claude-skills --skill quota-rate-limit-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: quota-rate-limit-pattern
Source: https://github.com/saintgo7/claude-skills/tree/main/quota-rate-limit-pattern
Command: npx skills add https://github.com/saintgo7/claude-skills --skill quota-rate-limit-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the problem of incorrectly throttling API traffic by handling rate limits (burst), concurrent in-flight requests, and daily token quotas with distinct mechanisms so you can reliably prevent overload and return actionable 429 errors.

Core Features & Use Cases

  • 3-layer rate limiting: Combines slowapi RPM limits, asyncio Semaphore concurrency admission, and DB-backed daily token checks to cover different failure modes.
  • Reason-code 429 responses: Returns HTTP 429 with a structured error payload and a specific code for rpm_limit, concurrent_limit, or daily_token_limit so clients can retry appropriately.
  • Operational visibility: Integrates a Prometheus counter that labels rejections by reason, enabling fast debugging of which layer is blocking traffic.
  • Distributed-environment guidance: Documents limits of worker-local enforcement and the required Redis/admission-controller alternatives when moving beyond single-worker deployments.

Quick Start

Ask your AI to generate a gateway quota module that enforces slowapi RPM, per-user asyncio concurrency slots, and a DB daily token SUM check, returning OpenAI-compatible 429 error responses with code set to the exact rejected layer.

Frequently Asked Questions about quota-rate-limit-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement rate limiting and quota enforcement in a FastAPI gateway?

FastAPI gateway rate limiting can be implemented using a three-layer strategy: slowapi for burst RPM limits, asyncio Semaphore for concurrent in-flight admission, and DB-based daily token accumulation, returning distinct 429 reason codes for each layer.

How do I return OpenAI-compatible 429 errors for different rate limits?

OpenAI-compatible 429 errors require a structured error payload with a specific code field. You return distinct codes like rpm_limit, concurrent_limit, or daily_token_limit so clients can identify the exact quota layer blocking their request and retry appropriately.

Can I use asyncio Semaphore to limit concurrent requests in an ASGI gateway?

Yes, asyncio Semaphore limits concurrent in-flight requests in ASGI gateways by controlling admission slots per user. This prevents backend overload from simultaneous connections, operating distinctly from slowapi RPM burst rate enforcement and daily token quota checks.

What is the best way to track API rate limit rejections for Prometheus monitoring?

Tracking API rate limit rejections in Prometheus involves integrating a counter that labels rejections by reason code, such as rpm_limit, concurrent_limit, or daily_token_limit, enabling fast debugging of which quota layer is actively blocking traffic.

Does worker-local rate limiting work in distributed FastAPI deployments?

Worker-local rate limiting does not scale reliably for distributed FastAPI deployments because enforcement is isolated per worker. Moving beyond a single-worker setup requires Redis or an admission-controller alternative to coordinate quota and concurrency limits globally.

Why do I need separate mechanisms for burst rate, concurrency, and daily token quotas?

Separate mechanisms for burst rate, concurrency, and daily token quotas handle different failure modes: slowapi RPM manages sudden bursts, asyncio Semaphore controls active in-flight requests, and DB accumulation tracks long-term daily token overages reliably.