Group by header quota
Group by header quota allocates dynamic quota by grouping requests using the group_by_header field. This feature defines different rate limits for multiple user types while maintaining a shared total quota.
For example, if your company operates as a Consume on Behalf of (CoBo) company, this feature manages API traffic for multiple customers who each have their own API key but access the same API provider. Grouping requests per customer prevents any single customer from exhausting the entire quota, maintaining fair API access for all.
Scenarios
In this scenario, Company1, Company2, and Company3 each have their own API key but share the same quota for api.website.com/*. To ensure fair usage, you can use the group_by_header field to segment the quota based on the x-lunar-user-role header, which identifies which company each request belongs to.
In the example, the x-lunar-user-role header allocates quotas dynamically, allowing each company to make up to 12 requests per minute. This means that even though all companies access the same API, their requests are counted separately, ensuring that no single company can consume more than its fair share of the total quota.
The following configuration example demonstrates group-by-header quota segmentation:
quotas:
- id: HeaderBasedQuota
filter:
url: api.website.com/*
strategy:
fixed_window:
max: 12
interval: 1
interval_unit: minute
group_by_header: 'x-lunar-user-role'