Skip to main content
Version: Next

Dynamic Quotas Using Response Headers

Dynamic Quotas Using Response Headers empower granular quota management by dynamically adjusting limits based on response's header values. This capability ensures tailored traffic allocation while respecting overall system limits.

  • Dynamic Response Headers: Fields such as remaining_header, reset_time_header, and retry_after_header provide real-time feedback to API consumers.
  • Flexible Configuration: Supports both fixed_window and concurrent strategies with dynamic quota settings.
  • Efficient Resource Management: Allocates resources dynamically based on the response's header values.

Dynamnic Quotas with Fixed Window Strategy

/etc/lunar-proxy/quotas/{fileName}.yaml
quotas:
- id: RegionalQuota
filter:
url: api.global-website.com/* # Apply to all API endpoints under this URL pattern
strategy:
fixed_window:
dynamic: # Dynamic Response Header-Based Configuration
remaining_header: X-RateLimit-Remaining
reset_time_header: X-RateLimit-Reset
retry_after_header: Retry-After

internal_limits:
- id: PremiumRegionQuota
parent_id: RegionalQuota
filter:
headers:
- key: x-user-region
value: premium-region
strategy:
fixed_window:
static:
max: 10000 # Premium region quota
interval: 1
interval_unit: day

- id: BasicRegionQuota
parent_id: RegionalQuota
filter:
headers:
- key: x-user-region
value: basic-region
strategy:
fixed_window:
static:
max: 5000 # Basic region quota
interval: 1
interval_unit: day

Dynamnic Quotas with Concurrent Strategy

Dynamic quotas can also be applied to the concurrent strategy, enabling fine-grained control over simultaneous connections.

/etc/lunar-proxy/quotas/{fileName}.yaml
quotas:
- id: ConcurrentQuotaBySubscription
filter:
url: api.subscription-website.com/*
strategy:
concurrent:
max_request_count: 200 # Maximum concurrent requests
remaining_header: X-Concurrent-Remaining

Key Components of Dynamic Quotas

FieldDescriptionMandatory/OptionalExample
strategy.fixed_window.dynamic.remaining_headerHeader indicating remaining quota.OptionalX-RateLimit-Remaining
strategy.fixed_window.dynamic.reset_time_headerHeader indicating when the quota resets.OptionalX-RateLimit-Reset
strategy.fixed_window.dynamic.retry_after_headerHeader indicating retry-after details.OptionalRetry-After
strategy.concurrent.remaining_headerHeader indicating remaining concurrent requests.OptionalX-Concurrent-Remaining
filter.headers.keyHeader key used for filtering requests.Optionalx-user-region
filter.headers.valueHeader value used for filtering requests.Optionalpremium-region

Benefits

  • Avoid Hard-Coding Quota Values: Fully rely on API response headers for rate limits, eliminating the need to hard-code numbers.
  • Adapt to Provider Rules: Some API providers only return response headers without supplying explicit quota values. This adaptation ensures compliance with their rules.