Errors, retry policy and request IDs
Classify error codes, read retry-safety fields and use optional idempotency only where it is enabled.
Also available as Markdown · all agent guides in one file
Key points
- Branch on codes, status and the retry-safety fields, not on message text. Keep the request ID for diagnostics.
- Repeat a POST automatically only when
safe_to_retryistrueor under an acceptedIdempotency-Key. Idempotency-Keyworks only when the operator configuresAETHER_IDEMPOTENCY_DIR. It is not exactly-once execution at the provider.
- For OpenAI-style endpoints inspect
error.code,error.type,error.paramanderror.hint; keeperror.request_idor theX-Request-IDresponse header for diagnostics. /v1/messagesuses the Anthropic envelope withtype: errorand a top-levelrequest_id; the same diagnostic fields are inside itserrorobject.- Branch on codes, status and the fields below, not on message text.
- Do not log credentials or full sensitive prompts.
{
"error": {
"message": "Insufficient credits for this request.",
"type": "insufficient_quota",
"code": "insufficient_credits",
"param": null,
"hint": "Add credits to the wallet used by this key. For shared projects, contact the project owner.",
"request_id": "req_example",
"retryable": false,
"retry_after_ms": null,
"safe_to_retry": true,
"execution_status": "not_started",
"usage_may_have_occurred": false
}
}Retry-safety fields
| Field | Meaning |
|---|---|
retryable | The cause is classified as temporary. It says nothing about whether repeating is safe or free. |
retry_after_ms | The wait in milliseconds, mirrored from Retry-After (delta seconds or HTTP date), or null when unknown. It does not promise free capacity after the wait. |
safe_to_retry | Repeating this request cannot cause a second generation by it, because the error happened before any provider attempt or the request was a read (GET, HEAD, OPTIONS). After any provider attempt of a write request it is false, even for 429 or a connection error. |
execution_status | not_started (no provider attempt) or unknown. |
usage_may_have_occurred | true means usage is possible, not that a charge is confirmed. |
Inside an SSE stream the HTTP status is already sent; read these fields from the error event.
Decide what to retry
| Status or code | Action |
|---|---|
| 400/413/422 | Fix the request, size or endpoint. wrong_endpoint can supply error.endpoints. |
404 model_not_found | Refresh model discovery; do not keep retrying the same ID. |
| 401 | Fix missing_authorization, invalid_api_key or conflicting_authorization. |
| 403 | Resolve key/account/project/model access or billing state. Do not work around restrictions by changing identity. |
Budget and quota codes daily_limit_reached, monthly_limit_reached, project_member_daily_limit_reached, project_member_monthly_limit_reached, insufficient_credits and devpass_daily_limit_reached | Require budget, quota reset or user action. Many use 403; do not classify by status alone or assume every limit is a transient 429. |
Transient rate_limit_exceeded, provider_rate_limit_exceeded and devpass_rpm_limit | Wait at least retry_after_ms or Retry-After when supplied. Use bounded exponential backoff with jitter when no delay is supplied. |
502 provider_unavailable, 503 temporary service failures and 504 upstream_timeout | May warrant a bounded retry, but only repeat a POST automatically when safe_to_retry is true or under an accepted Idempotency-Key. |
sandbox_disabled and configuration/access errors | Need corrective action, not repeated generation calls. |
- Retry policy belongs to the client; Aether performs no client retries beyond its internal provider fallback.
- SDKs may already retry automatically; avoid multiplying application and SDK retry loops.
Repetition and partial output
- Aether may try more than one configured provider before returning a result.
- A timeout, disconnect or failed stream does not prove that no work ran or that no usage accrued; if no response arrives at all, the outcome is unknown.
X-Request-IDis for correlation, not deduplication: sending the same ID again does not prevent a second execution.- Set a total time/attempt budget and decide explicitly about possible repeated work and cost before retrying a POST.
- Keep a separate ID per client attempt and record the returned request ID.
- For stream errors inspect events even after HTTP 200; discard incomplete tool calls and treat previously received text as partial.
- Never automatically rerun external tool side effects just because generation was retried.
Optional idempotency for generation
Operator prerequisite
TheIdempotency-Key header is honoured only when the operator configures AETHER_IDEMPOTENCY_DIR on the API server; production enablement is not asserted here.- Without it, a supplied key is rejected with 400
idempotency_not_supportedbefore any provider call, never silently ignored. - Supported: regular API keys and non-streaming JSON POSTs without a query string to
/v1/chat/completions,/v1/responses,/v1/messages,/v1/images/generationsand/v1/videos. - Streaming, background mode, multipart/audio and other generation endpoints return
idempotency_not_supported.
- The sandbox offers no idempotency guarantee.
Idempotency key and fingerprint
- Send the header once: 1–128 characters, first alphanumeric, then ASCII letters, digits and
_.:-. Otherwiseidempotency_invalid_key. - A key is bound to your user, project and API key.
- Path, JSON body and the
anthropic-version,anthropic-beta,x-aether-usageandacceptheaders form its fingerprint; a different request under the same key returns 409idempotency_conflict.
Idempotency responses
| Response | Meaning | Client action |
|---|---|---|
First accepted call: X-Aether-Idempotency: created | — | — |
X-Aether-Idempotency: replayed and X-Aether-Original-Request-ID | A finished JSON result is replayed with the same status and body, without a new provider call or charge. An error after a provider may have run, such as a timeout, is stored and replayed too; its Retry-After never starts a new attempt under that key. | — |
| An error that cannot have run or cost anything | It is not stored and leaves the key free: a rejected request, or every provider refusing it (a 4xx status other than 408, or 501, 503 or 529) or failing before the connection opened. | Repeat it with the same key. |
409 idempotency_conflict | A different request under the same key. | — |
409 idempotency_in_progress with Retry-After: 2 | Still running, or unknown after a crash. An entry stays in progress for at most 30 minutes, then fails closed to idempotency_result_unavailable; the key is not released for a new operation before its 24 hours end. | Poll only with the same key and an identical request; a new key can start a second billed operation. |
409 idempotency_result_unavailable | The result cannot be replayed, for example over 1 MiB, not JSON, a dropped connection, a server restart while it ran or no result after 30 minutes; it is not executed again. | — |
503 idempotency_store_unavailable with Retry-After: 1 | No new dispatch, but an earlier operation under this key cannot be ruled out. It also covers a store that is shutting down or an account over its store limit of 10,000 entries or 256 MiB. | Do not fall back to a request without the key. |
400 idempotency_not_supported | No store is configured, or the request is not supported. | — |
- Store writes of one account run one after another.
- When another worker holds that account's lock, the server waits a bounded time measured from arrival: up to 2 seconds to accept the request, otherwise 503
idempotency_store_unavailable; up to 10 seconds to record the result, otherwise the entry stays unresolved (idempotency_in_progress, fail closed). - A lock whose owner crashed is taken over automatically, at once when its process is gone on the same host and otherwise after 30 seconds.
- Finished results are kept for 24 hours after completion; afterwards the same key starts a new operation.
- Every call rechecks account, key, project, model and budget permissions, so a replay can still be rejected.
No exactly-once guarantee
The guarantee is at most one provider call per accepted key, identity and retention window that can have run and cost anything, including internal fallbacks. It is not exactly-once execution at the provider, not a free retry and not a transaction between provider, billing and the store.A fallback provider is still tried after an unbilled refusal; after a timeout, a timeout or server error status such as 408, 500, 502 or 504, a lost connection or a success no other provider is tried.
A video replay restores only the job-creation response.
Look up your own request
GET /v1/requests/<request_id> with the same regular API key returns stored HTTP metadata for up to 100 completed requests of that key with this public request ID: timestamp, endpoint, method, model, status, result (success, error or cancelled), error_code, streaming, duration_ms and known token and credit values, plus truncated and coverage.
- Unknown, foreign and expired IDs all return
found: falsewithentries: []. - Even project owners see only rows of the key used.
- Retention is at most 30 days.
- This is delayed metadata, not a live status, response retrieval or video job status.
- A stream that failed after HTTP 200 can show
result: error. found: falsedoes not prove that a request never ran, so it cannot replacesafe_to_retryor anIdempotency-Key.