AI Gateway Rate Limiting¶
The Studio platform implements a three-tiered rate limiting architecture at the API Gateway (Kong) level to ensure system stability, manage AI costs, and provide fair resource allocation across different tenants and users.
Architecture Overview¶
Rate limiting is enforced at three distinct levels for all AI-related endpoints:
- Global Level: Enforced across the entire service to prevent infrastructure overload.
- Tenant Level: Enforced per company/tenant to ensure that one tenant's usage doesn't impact others.
- User Level: Enforced per individual user to prevent accidental or malicious runaway scripts.
Rate Limit Tiers¶
| Tier | Scope | Identifier | Default Limit | Purpose |
|---|---|---|---|---|
| Global | Service-wide | Service ID | 1000 req/min | Infrastructure protection |
| Tenant | Per Tenant | X-Tenant-Id | 100 req/min | B2B Resource isolation |
| User | Per User | X-User-Id | 10 req/min | Personal usage safety |
[!NOTE] These limits apply specifically to high-cost AI operations such as Chat and Analysis. Standard API endpoints may have different or no limits.
How it Works¶
When a request is made to an AI endpoint:
- Authentication: The gateway verifies the user's JWT.
- Identity Extraction: The OPA plugin extracts the
userIdandtenantIdfrom the JWT claims and injects them as internal headers (X-User-Id,X-Tenant-Id). - Tiered Evaluation:
- Kong checks the Global limit for the service.
- Kong checks the Tenant limit based on the
X-Tenant-Idheader. - Kong checks the User limit based on the
X-User-Idheader.
- Enforcement: If any tier's limit is exceeded, the request is rejected immediately.
Error Handling¶
When a rate limit is exceeded, the gateway returns a structured 429 Too Many Requests response.
Example Response¶
Headers¶
Every rate-limited response includes a Retry-After header indicating how many seconds to wait before retrying.
Future Customization¶
Currently, rate limits are globally defined for all tenants. Future updates will allow:
- Variable Tiering: Assigning different limits to different tenants based on their subscription plan.
- Dynamic Adjustments: Automatically increasing limits during peak audit periods.
- Dashboard Visibility: Real-time monitoring of rate limit usage per tenant in the Admin UI.