docs

Retries

What OSMEXO does for you

When a model fails to answer, OSMEXO tries again before you see an error. You get an error only when the request still cannot be served. Nothing extra is charged for these attempts: you pay once, for the answer you receive.

A failed request is never charged.

What your client should retry

StatusRetry?How
429YesWait the number of seconds in Retry-After, then send the same request.
500, 502, 503, 504YesRetry with exponential backoff (1 s, 2 s, 4 s …), up to 3–5 attempts. Use Retry-After when it is present.
409 idempotency_conflict with retry_afterYesThe first request with this key is still running. Wait, then ask again.
400, 401, 403, 404, 413, 415NoThe request, key or model id needs to change. The same request fails the same way.
402NoAdd credits or raise the budget that stopped it. See API Keys.

The official openai SDKs already retry 429 and 5xx with backoff (maxRetries / max_retries, default 2).

Streaming

A streamed request can only be retried for you before the first token reaches your client. If it cannot be served at all, you get a normal JSON error with the proper status code, not a broken stream.

After the first token, the stream cannot be restarted, because your client already holds part of an answer. A failure at that point ends the stream with an error chunk and [DONE]. Only the tokens you received are charged. See Streaming.

The same rule applies to speech audio: a failure after the first byte ends the response early.

Idempotency keys

An image costs real money, and a retry after a network error could produce and bill a second one. Send an Idempotency-Key header on image and speech requests to make retries safe:

bash
curl "https://api.osmexo.com/v1/images/generations" \
  -H "Authorization: Bearer $OSMEXO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-4821" \
  -d '{ "model": "openai/gpt-image-1", "prompt": "A lighthouse in a storm" }'
SituationResult
Same key, same body, the first request finishedThe stored answer is returned again with header Idempotent-Replayed: true. Nothing is generated or charged twice.
Same key, same body, the first request is still running409 idempotency_conflict with retry_after (seconds). Ask again later.
Same key, different body409 idempotency_conflict. Use a new key.
Key longer than 255 characters400 validation_failed.

Keys belong to your organization. Use a UUID or a stable id of your own (an order id, a message id), so retries from any of your servers land on the same result.

Checklist

  • Retry 429 and 5xx; do not retry other 4xx without changing something.
  • Honour Retry-After.
  • Cap your retries, and show the error to the caller after the last one.
  • Send an Idempotency-Key for anything that generates an image or audio.
  • If a stream ends with an error chunk after partial output, decide per use case whether to ask again or show what arrived.