Enhancement Proposal: Rate Limiting Support in OpenAPI Specification #5258
Replies: 3 comments 3 replies
-
|
Thanks for starting this conversation @stefvp , I have a few questions to try to understand the driver here. What led you to identify rate limiting as a specific feature? Is there prior art in this area that should be part of the context for this proposal? |
Beta Was this translation helpful? Give feedback.
-
|
Hi @lornajane Several factors led me to focus on rate limiting: Security perspective: API consumer perspective: API developer / platform perspective: Regarding prior art: For example, the draft RFC on RateLimit headers This proposal builds on similar ideas but shifts the focus to design and machine readability. This idea is to make rate limiting policies both explicit and processable by tooling, rather than implicit or descriptive. |
Beta Was this translation helpful? Give feedback.
-
|
@handrews > but better modeling for HTTP headers is planned for 3.3, so that should no longer be an issue. Sorry, is there a discussion thread specifically on this or is it buried in another thread? Thanks. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
This post proposes adding a standardized way to describe rate limiting policies in the OpenAPI Specification (OAS). Currently, rate limiting is widely implemented in API gateways and frameworks, but it is not formally represented in OAS, leading to fragmented and non-interoperable solutions.
Motivation & Use Cases
Rate limiting is a fundamental API protection and traffic management mechanism. However, it is typically configured outside of the API specification, resulting in a disconnect between API design and runtime behavior.
Key use cases:
Client awareness
API consumers cannot discover rate limits programmatically, leading to trial-and-error or reliance on external documentation.
Tooling & automation
Code generators, API gateways, and documentation tools cannot uniformly interpret rate limiting policies.
Consistency across environments
Different gateways (e.g., cloud providers, reverse proxies, frameworks) implement rate limiting differently, making portability difficult.
Security & governance
Rate limiting is part of API security posture but is not captured alongside authentication/authorization in OAS.
Proposed Solution
Introduce a standardized rate limiting definition using an
x-vendor extension as a first step, with the goal of eventual standardization.Example
RateLimit Object Definition
A
RateLimitobject describes the algorithm, scope, and enforcement parameters of a rate limiting policy.The object is introduced as the value of the
x-rateLimitextension.fixedWindow,slidingWindow,tokenBucket.timeWindow. Must be greater than 0.PT1M,PT1H).Key Object Definition
The
Keyobject defines how requests are grouped for rate limit enforcement.It extracts a value from the incoming request and associates all requests with the same value to a shared rate limiting counter.
The design mirrors OpenAPI parameter identification (
inandname) to allow policies to reference request elements already defined in the API specification.ip,header,query,path,cookie.api-key,userId). Not required whenin = ip.Rate Object Definition
The
Rateobject defines a generic rate expression and is used by the token bucket algorithm.PT1S,PT1M).Justification
By introducing a standardized rate limiting model, OpenAPI can:
This enhances both API design-time and runtime consistency.
Alternatives Considered
1. Status quo (no specification support)
Rate limiting remains external to OAS and implemented in gateways or middleware.
2. Documentation-only approach
Describe rate limits in
descriptionfields.3. Runtime headers only (e.g.,
RateLimit-*)Expose limits via HTTP response headers.
4. Gateway-specific extensions
Use provider-specific configurations (e.g., AWS, Azure).
Evidence / Early Implementation
This proposal has been prototyped using:
x-rateLimitextensions embedded in OpenAPI documentsThis demonstrates that:
Open Questions
Next Steps
Beta Was this translation helpful? Give feedback.
All reactions