How it works
The path every request takes through Gateway, from API key to provider and back
Every request passes through the same pipeline. Knowing the order explains most behavior you’ll see: why a request was rejected before reaching a provider, and which routing policy applied.
The request path
- Authenticate. The API key identifies your organization. Management keys (
mgmt_) can’t call model endpoints. - Attribute. The request resolves to a project (from a project API key, the
project_idfield, or theX-Project-Idheader) and, for resellers, a customer. - Check spend. Organization credit, the project’s budget, and the key’s spend limit are all enforced now; an exhausted one returns
402before any provider is called. - Filter. Blocklist, geo-location, and zero data retention rules reject the request or remove non-compliant vendors.
- Route. A routing policy is resolved (precedence below), then Gateway picks the vendor and model from the policy’s candidates by capability and current health.
- Protect. Context compression trims oversized histories; DLP and prompt injection scanning can block with
422. - Call, with failover. Provider throttles and outages trigger failover to the next candidate; client errors don’t.
- Meter. The response is normalized to one shape with the served
model,vendor, andusageincluding per-callcost, and spend is recorded at every scope.
Every rejection along the way has a stable code; see Errors.
Which routing policy applies
Highest precedence first:
- An explicit
routing_policy_idon the request (Embedded Routing, withcustomer) - The customer’s default policy
- The project’s policy
- The organization’s default policy
- No policy: the request’s
modelis used directly
Naming an exact provider/model bypasses the policy; omitting model or sending default_routing hands the choice to it. See Using routing policies.
Why the order matters
Spend gates run before provider calls, so a blocked request costs nothing. Filters run before routing, so a policy can’t pick a vendor your compliance settings exclude. And attribution runs first, which is why a project API key alone gets you the project’s policy and budget with no per-request configuration.