What triggers failover
The gateway moves to another candidate on these failures:- Authentication failures: HTTP 401 or 403 because the provider rejected the key. A 401 or 403 for any other reason stops the request.
- Rate limits: HTTP 429.
- Server errors: HTTP 500 and above.
- Request timeouts: HTTP 408, or the attempt exceeding your per-request timeout.
- Network failures: connection errors, DNS failures, and TLS errors.
Failover order
Where the gateway goes next depends on how the attempt failed.
Model candidates come from the
model field first, then the models array in order:
gpt-4o, also expands to every provider that serves that model. The model author’s own provider goes first, then resellers such as OpenRouter. A provider:model ID, such as openai:gpt-4o, reaches only that provider.
To fail over to a different model, list it in the
models array, or set it up as a fallback model.Retrying the same provider
When a provider answers 429 or 503 with aRetry-After header, the gateway waits and retries the same backend instead of moving on.
It does that only when the wait is 5 seconds or less, only when the wait still fits inside your total timeout, and at most twice per request.
Otherwise it treats the response as a rate limit or a server error and moves to the next candidate.
What bounds the retrying
Two timeouts and an attempt cap bound every request:
Streams work differently after the first byte. See Streaming responses.
Set the timeouts for your account in Account Settings, or through the Configuration API.
When the total timeout is reached, failover stops even if candidates remain, and the gateway returns
ERR_NGROK_3810.
Failures that never reach failover
Some requests fail before the gateway makes any upstream attempt. These return immediately, and the response carries noNgrok-AIG-Attempts header:
- The request body could not be parsed.
- The model is unknown, or the model address is malformed.
- The requested provider or model is blocked by the access key configuration’s access scope.
- No provider key is available for the requested provider.
- The account has no credits. This happens even if you use your own provider keys.
Best practices
- Attach several provider keys per provider so an exhausted credential fails over instead of failing the request. See Multi-key failover.
- List candidates from more than one provider so a provider-wide outage has somewhere to go.
- Set timeouts to match your latency budget. A total timeout that is too tight cuts failover short; one that is too loose makes a slow failure look like a hang.
- Record
Ngrok-AIG-Request-Idfrom every response so you can look a failure up afterwards. See Debug failed requests.
Next steps
Error Codes
Error codes, causes, and solutions
Debug failed requests
Diagnose a failure from the response