> ## Documentation Index
> Fetch the complete documentation index at: https://www.usenotra.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Cold starts and retries

> What happens when writer-0.1 starts after being idle, which errors to retry, and how to configure retries and timeouts in the OpenAI SDKs for long waits.

## Cold starts

After about 5 idle minutes the model scales down, and the next request starts it again. The gateway holds that request for up to 75 seconds while the model starts, then answers it as usual; a streamed request receives nothing until the model is ready. If the model needs longer (a cold start can take 1 to 9 minutes), the request gets 503 `model_starting`. Retry every `retry-after` seconds for up to 10 minutes; the OpenAI SDKs' default retries give up sooner.

Most starts finish within the 75-second hold, so the first answer just takes longer. Keep your client timeout above that; the [SDK settings](#sdk-settings) below already are.

When the hold runs out, the response has a `retry-after` header of 30 seconds and this body:

```json theme={"system"}
{
  "error": {
    "message": "writer-0.1 is starting after being idle. This can take up to about 10 minutes. Retry in 30 seconds.",
    "type": "server_error",
    "param": null,
    "code": "model_starting"
  }
}
```

The Playground waits and retries for you, and says that the model is starting.

## Retry `model_starting` in your code

```ts theme={"system"}
// Retries 503 model_starting for up to 10 minutes.
async function withColdStart<T>(call: () => Promise<T>): Promise<T> {
  const deadline = Date.now() + 10 * 60_000;
  for (;;) {
    try {
      return await call();
    } catch (error) {
      const starting =
        error instanceof OpenAI.APIError && error.code === "model_starting";
      if (!starting || Date.now() > deadline) throw error;
      const seconds = Number(error.headers?.get("retry-after") ?? 30);
      await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
    }
  }
}

const response = await withColdStart(() =>
  client.responses.create({ model: "writer-0.1", input: "Write a changelog entry for faster search." })
);
```

## Which errors to retry

If the model service fails before it sends anything, for example when its GPU is replaced, the gateway retries the call once after a second or two. It never retries once part of the answer has been sent, and a retried request is billed once.

Errors at 429, 502, 503 and 504 are worth retrying; the others need a change to the request, the key or the balance first.

| Status | Code | What to do |
| - | - | - |
| 400 | `invalid_request` | Fix the request; `param` names the field. |
| 400 | `unsupported_parameter` | Remove the parameter that `param` names. |
| 400 | `context_length_exceeded` | Shorten the prompt so there is room for the answer. |
| 401 | `invalid_api_key` | Check the key and the Authorization header. |
| 402 | `insufficient_credits` | Add credits in the console, or lower the maximum answer length. |
| 404 | `model_not_found` | Use a model from `GET /v1/models`. |
| 405 | `method_not_allowed` | Use POST for generation and GET for models. |
| 413 | `request_too_large` | Send at most 1.45 MB of JSON. |
| 429 | `rate_limit_exceeded` | Wait for `retry-after` seconds; the `x-ratelimit-*` headers show the limits. |
| 400, 413, 422, 502 | `upstream_error` | At 400, 413 or 422 the model backend rejected the request: fix it. At 502, retry with exponential backoff. |
| 504 | `upstream_timeout` | Retry with exponential backoff, or stream the answer. |
| 503 | `model_starting` | Retry after `retry-after` seconds for up to 10 minutes. |
| 503 | `model_overloaded` | Retry after `retry-after` seconds. |
| 503 | `model_unavailable` | Retry later. |
| 503 | `service_unavailable` | Key checks or billing are unavailable; retry. |

Failed requests don't use credits, so retrying them costs nothing.

## SDK settings

OpenAI's SDKs retry 429 and 5xx responses on their own, twice by default with short backoff. That covers brief overloads but gives up on a cold start long before the model is ready, so wrap calls like the example above.

Set the client timeout above the gateway's 720-second model deadline, for example 750 seconds, or stream. Otherwise the SDK can time out and retry a long answer that was still being written.

Every response has an `x-request-id` header. Include it when you contact support.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.