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.
- Dynamic Response Headers: Fields such as remaining_header,reset_time_header, andretry_after_headerprovide real-time feedback to API consumers.
- Flexible Configuration: Supports both fixed_windowandconcurrentstrategies 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
| Field | Description | Mandatory/Optional | Example | 
|---|---|---|---|
| strategy.fixed_window.dynamic.remaining_header | Header indicating remaining quota. | Optional | X-RateLimit-Remaining | 
| strategy.fixed_window.dynamic.reset_time_header | Header indicating when the quota resets. | Optional | X-RateLimit-Reset | 
| strategy.fixed_window.dynamic.retry_after_header | Header indicating retry-after details. | Optional | Retry-After | 
| strategy.concurrent.remaining_header | Header indicating remaining concurrent requests. | Optional | X-Concurrent-Remaining | 
| filter.headers.key | Header key used for filtering requests. | Optional | x-user-region | 
| filter.headers.value | Header value used for filtering requests. | Optional | premium-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.