Forty-six minutes to take-off. Fog has rolled over the sleigh-route planner and it has stopped answering. Sprocket is sweating through his hat.
- Sprocket
The route planner is throwing 503s! Santa leaves at midnight and right now his map is blank.
- Tinsel
Is the provider down, or just having a moment?
- Sprocket
Does it matter? I was going to wrap the call in a
while True. - Tinsel
Put the loop down. Three fields: a timeout so nothing hangs, retries for the hiccup, a fallback on another provider for the outage.
- Rudolph
Visibility zero over OpenAI. Diverting to Azure. Cargo lands in one piece.
- clientYour app
- orq.aiAI Routertimeout · retry · fallbacks
- 1503 ×42fallbackprimaryopenai/gpt-6.2-soldownfallbackazure/gpt-6-sol
How it works
Tinsel’s fix fits on one request. Requests to /responses and /chat/completions (and embeddings, rerank and decisions) can carry three extra fields. They work in this order:
- Timeout.
timeout.call_timeoutsets a time limit in milliseconds for each call. A call that runs past it is cancelled and fails with408. The router always retries408, and408is a default fallback code. - Retries.
retry.count(0 to 5) tries the same model again when the provider answers with one of the codes inon_codes. The router always adds408to that list, so a call that hits your timeout is retried too. The wait between tries grows each time (up to 1s, 2s, 4s, …) and is randomised, so a thousand clients do not all retry in the same instant. If the provider sends aRetry-Afterheader, the router waits that long instead, up to 60 seconds. - Fallbacks. When the retries run out on a fallback code (by default
408,429,500,502,503,504and529), the router moves to the next model infallbacksand starts again, with the same retry rules. Setfallback_on_codesto choose those codes yourself.
Your app gets back one normal response, from whichever model answered. It never sees the failed attempts.
Try it with curl
curl -X POST https://my.orq.ai/v3/router/responses \
-H "Authorization: Bearer $ORQ_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-6.2-sol",
"input": "Plan the sleigh route",
"retry": {"count": 3, "on_codes": [429, 500, 502, 503, 504]},
"timeout": {"call_timeout": 5000},
"fallbacks": [{"model": "azure/gpt-6-sol"}]
}'
Or from the OpenAI SDK
The fields are not part of the OpenAI request types, so pass them in extra_body:
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["ORQ_API_KEY"],
base_url="https://my.orq.ai/v3/router",
)
response = client.responses.create(
model="openai/gpt-6.2-sol",
input="Plan the sleigh route",
extra_body={
"retry": {"count": 3, "on_codes": [429, 500, 502, 503, 504]},
"timeout": {"call_timeout": 5000},
"fallbacks": [{"model": "azure/gpt-6-sol"}],
},
)
print(response.output_text)
Good timeout values
From the docs’ recommended values:
| Use case | call_timeout |
|---|---|
| Real-time features | 5,000 ms |
| Chat applications | 15,000 ms |
| Streaming (time to first token) | 30,000 ms |
| Batch processing | 60,000 ms |
Without a timeout, one non-streaming call may take up to 12 minutes.
If you send no retry at all, the router still retries twice on the usual error codes. Errors like 400 or 401 are not in the default retry codes: trying again will not fix a bad request or a wrong key.
Streaming
The router only retries or falls back before any output arrives (text, reasoning or a tool call). Once text is streaming to your user, a failure ends the stream with an error instead of starting over halfway through a sentence.
On the Anthropic endpoint (/v3/anthropic), only timeout is read from the request. Retries stay at the default of two on the default codes, and fallbacks come from Routing Rules.
Nice list
- Pair a short
call_timeoutwith a fallback. A hanging call becomes a408, which is retried and then falls back, so the wait is bounded by timeout × attempts instead of the 12-minute default. - Set
call_timeoutto what your user will wait for: the docs suggest 5,000 ms for real-time features and 15,000 ms for chat. - Keep the chain short. The docs recommend at most three fallback models, with similar capabilities.
Naughty list
- Sending
retrywithon_codesbut nocount. Aretryobject withoutcountmeans zero retries: one call per model. - Wrapping the call in your own retry loop. The router already retries twice by default, so three tries in your loop can become nine calls to the provider.
- Setting
fallback_on_codes: [400]and expecting the defaults to stay. A custom list replaces them, so429and503stop falling back. - Expecting
fallbacksto rescue a wrong model id.404and403are not default fallback codes, so the error comes straight back.
Elf's challenge
Roll in your own fog: send "timeout": {"call_timeout": 1} with no fallbacks. What status comes back, and how many attempts did the router make?
Stuck? Ask Tinsel for a hint
A timeout answers HTTP 408 with code timeout_error. 408 is in the default retry codes, and with no retry object the router retries twice, so expect three attempts before the error reaches you. The response does not list the attempts; the count comes from the default of two retries.
Christmas crackerWhy did Sprocket's while True get coal this year?Pull it for the punchline
It kept retrying 400s. Some requests are just naughty.