How the Gateway selects a provider
The Gateway uses these inputs to select a provider for each request:
- Routing rules. A matching rule sets the target provider and model.
- The model name. A
provider/modelname sets the provider. A bare name goes to a provider when exactly one provider has a key that lists it. - Provider weights. When a virtual key allows more than one provider, the Gateway selects one by weight.
- Key weights. Among the keys of a provider, the Gateway selects a key by weight.
- Fallbacks. When the call fails, the Gateway tries each fallback in order.
Routing rules
A routing rule has these parts:
| Part | Meaning |
|---|---|
| Condition | An expression about the request, for example the model name |
| Target | The provider, and optionally the model, to use |
| Fallbacks | Other provider/model targets to try in order |
| Scope | Global, or one team, customer or virtual key |
| Priority | Lower numbers run first in a scope |
To create a rule, open Routing Rules in the console and select Create.
Fallbacks in a request
A request can list its own fallbacks:
{
"model": "provider-a/model",
"fallbacks": ["provider-b/model"],
"messages": [{"role": "user", "content": "..."}]
}
Budgets
A budget is a spending limit in US dollars. It resets after a period, for example 1d, 1w or 1M. You can set a budget on:
- A virtual key
- A team or a customer
- A provider or a model
The Gateway calculates the cost of each request from the token counts and the model price. When a budget is used up, the Gateway refuses requests with 402 until the budget resets.
Rate limits
A rate limit caps tokens, requests or both in a period. When a limit is reached, the Gateway refuses requests with 429 until the period resets.
Error types
| Status | Type | Cause |
|---|---|---|
| 401 | access_not_found | The virtual key does not exist or is revoked |
| 402 | budget_exceeded | A budget is used up |
| 403 | access_blocked | The virtual key is turned off or expired |
| 403 | model_blocked | The virtual key cannot use this model |
| 403 | provider_blocked | The virtual key cannot use this provider |
| 429 | rate_limited, token_limited, request_limited | A rate limit is reached |