Configure your API Quotas
Lunar.dev Quotas offer a flexible and centralized method for managing and configuring API quotas. These quotas can be both internal or provider-given, allowing users to set precise limits on API consumption. Quota management is defined in a quota.yaml
file, shared across all flows within a Lunar.dev Gateway, providing a scalable way to allocate and monitor API usage without shared state issues.
The Quota System is a key feature in this platform, enabling users to define quotas based on specific provider limits and internal limits based on your API consumption profile, such as monthly, daily, or other intervals. Quotas are dynamically updated as consumption occurs, ensuring real-time management across flows.
ποΈ API Quotas Configuration Template
Quota Configuration Template
ποΈ Custom API Quota
Custom API Quota enables dynamic quota allocation based on specific API call properties. Unlike traditional quotas that count the number of requests to an API provider, the fixedwindowcustom_counter strategy allows you to define custom metrics for quota limits.
ποΈ Filter by Header Quota
Filter by Header Quotas enable precise control over API usage by setting limits based on request headers, rather than just URLs. This allows for more flexible quota management, such as distinguishing between environments or customer tiers, ensuring resources are allocated efficiently and tailored to specific needs.
ποΈ Group by Header Quota
Group by Header Quota enables dynamic quota allocation by grouping requests using the groupbyheader field. This feature allows you to define different rate limits for various user types while maintaining a shared total quota.
ποΈ Dynamic Response Header Quota
Dynamic Response Header Quota empowers granular quota management by dynamically adjusting limits based on response's header values. This capability ensures tailored traffic allocation while respecting overall system limits.
Quota File Structureβ
The quota
section defines the main constraints on API usage by specifying rate limiting strategies. This primary quota acts as the overarching rule for API requests, applying to all requests that match specified filters (e.g., URLs, headers). Quota's Filter allow quotas to be applied conditionally based on endpoint patterns or request headers, making it adaptable to different usage scenarios and customer types.
The internal_limits
section is designed to set more specific constraints within the main quota by defining nested intenal limits that inherit from the main parent quota. Each internal limit can have its own filters and strategies, enabling precise control over distinct user groups or endpoints.
Benefits of Lunar.dev Quota Managementβ
- Real-time API Usage Monitoring: Automatically updated as quotas are consumed, ensuring accurate real-time usage statistics.
- Granular Control: Ability to set quotas based on URLs, headers, and user groups. Nested quotas allow for more detailed control over specific API resources.
- Scalability: Easily manage and track quotas across multiple API flows and user environments.
Quota Exampleβ
Hereβs an example of a quota configuration defined in a quota.yaml
file:
quotas:
- id: MyQuota
filter:
url: api.website.com/*
strategy:
fixed_window:
static:
max: 100
interval: 1
interval_unit: minute
```yaml title="/etc/lunar-proxy/quotas/{fileName}.yaml"
quotas:
- id: MyQuota
filter:
url: 15.459.124.21/*
strategy:
fixed_window:
static:
max: 100
interval: 1
interval_unit: minute