- reading the error object instead of the status alone
- deciding which errors to retry
- backing off with jitter and honoring
Retry-After - setting retry budgets
- logging the right fields
Streaming requests can also fail after the HTTP
200 response has started, once your user may already be reading partial output. Those failures need lower retry ceilings and a different recovery strategy. See Handling Streaming Failures. This page and that one share the same rules for reading error.retryable and the same retry budgets.The Retry Rule
One rule covers every Gloo AI endpoint, streaming or not:- Retry only what the error marks retryable (
error.retryable: true, or a dropped connection). Never retry4xxauthentication, validation, or billing errors. - Background work (batch jobs, ingestion, anything no one is watching): at most 5 requests in total, including the first. Wait for
Retry-Afterfirst; otherwise waitmin(2^(attempt-1), 30)seconds plus jitter. - Someone is waiting (interactive requests and live streams): at most 2 retries, with short backoff capped at a couple of seconds. See Handling Streaming Failures.
- When
Retry-Afteris longer than the caller can wait, such as the 30 seconds a3003 / SERVICE_UNAVAILABLEusually asks for, don’t wait: fail fast with a clear message, or hand the work to a background job. - Honor
X-RateLimit-*headers when present, but don’t assume a response includes them.
Read the Error, Not Just the Status
Completions and Responses errors include a structurederror object. Use it for programmatic handling instead of parsing human-readable messages. See AI Error Object for every field.
- Branch on
error.retryablefirst. It says whether retrying the same request may succeed. Useerror.nameorerror.codeto tell exactly what happened. - Log
error.nameanderror.code, not just the status. The status gives only the category; the name and code give you precise alerting and debugging. - On the direct endpoints, branch on the
X-Gloo-Error-Codeheader andretryable, not on the status alone. Showmessageto your end users, and logdeveloper_messagefor yourself. Never parsemessageordeveloper_message: their wording can change; the codes do not. See Direct Endpoint Errors. - Use
detailto pinpoint validation failures. For422responses, thedetailarray tells you exactly which field failed:locis the field path,msgis the reason, andinputis the value you sent.
Which Errors to Retry
Retry only transient failures, and only when the request is safe to send again.
Not every
429 is retryable. Read the error object before you decide.
Network failures with no response, such as connection timeouts and dropped connections, are likely transient: retry them with the same backoff and budget, and keep your user informed while you do.
Backoff with Jitter
Wait longer between each attempt, and add random jitter so many clients that failed at the same moment don’t all retry at the same moment.- If the response has
Retry-After, wait at least that long. On the direct endpoints the same wait is also in the error body asretry_after. If that is longer than the caller can wait, fail fast or defer the work instead. - Otherwise, use exponential backoff with jitter, capped so a single wait never grows without bound:
min(2^(attempt-1), 30)seconds plus jitter for background work, a couple of seconds at most when someone is waiting. - Stop retrying and surface the error when the error is not retryable, the budget is spent, or the limit requires an account or configuration change.
X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset when present, but don’t assume a 429 includes them; they aren’t part of a universal Gloo API response contract.
Retry Example
This pseudocode follows the background budget: at most five total requests, including the first. It retries only when the response metadata, endpoint policy, and request safety all permit it, gives precedence toRetry-After, and excludes spending-limit errors.
5xx responses: let 5xx statuses through the first check alongside 429, and the error.retryable check after parse_error decides whether to retry.
Retry Budgets
Every retry loop needs a ceiling, and a user waiting on a screen needs a much smaller one than a background job.
Stop early the moment an error reports
retryable: false, whatever the remaining budget.
Make Requests Safe to Retry
A retry sends the same request again. Before you retry, make sure doing it twice is harmless:- Requests that change data, such as uploads, need a way to detect a duplicate. See Duplicate Upload Results for how ingestion reports content it already has.
- Tool calls with side effects, such as sending an email, should carry idempotency keys or operation IDs so a replayed call can be detected and dropped. See Tool Calls and Side Effects.
Batch and Ingestion Jobs
Jobs that send many requests in a row, such as uploading a content library, should:- Control call frequency with delays between API calls, and back off when a rate limit arrives.
- Retry failed items with the same budget, and report success or failure for each item.
- Track progress so you can see each item’s processing status.
- Validate content before sending it, so a validation error is caught once instead of on every retry.
Log What Support Needs
For every failed request, log:error.name,error.code,error.fault, anderror.retryable- the
trace_idfrom the error object (on the direct endpoints, alsoX-Request-Id, which every response carries) - the attempt number and the wait before it
- the endpoint and model you called
error.name, and response times so you can see a rising failure rate before your users report it.
Open a ticket with the trace_id for persistent inference issues. If inference errors continue after retrying with backoff, contact Support in Gloo AI Studio (bottom of the sidebar; see Get help) and include the error response’s trace_id so we can trace the exact request.
Summary
Next steps
Handling Streaming Failures
Retry, continuation, and partial-output UX for interrupted streams.
Errors Reference
Every status code, error code, and the AI error object.
Rate Limits
Spending limits, endpoint quotas, and provider rate limits.
API Key Security
Storing, using, and replacing API keys safely.

