# Errors

> The error shape, every error code, and what to do about each.

Errors use the OpenAI shape, so SDKs raise their usual exceptions:

```json
{"error": {"message": "no ready miner serves this model", "type": "invalid_request_error", "code": "no_miner_available"}}
```

When a session was started before the error, `error.session_id` is set. Look it up with `GET /v1/sessions/{id}` to see every attempt and any channel that was opened.

| HTTP | `code` | Meaning | What to do |
| - | - | - | - |
| 202 | (not an error) | `object: "chat.completion.pending"`: no verified reply within the response deadline. The session continues. | Poll `GET /v1/sessions/{id}` until `reply` is set, or use `stream: true`. |
| 400 | `invalid_json`, `model_required`, `messages_required`, `invalid_message`, `invalid_max_tokens` | The body is not valid. | Fix the request. The message says which field. |
| 400 | `unsupported` | The request asks for something not supported: `tools`, or `n` above 1. | Remove the field. |
| 400 | `invalid_provider`, `invalid_sort`, `invalid_payer`, `invalid_address` | A `provider`, `flop.payer` or address value is wrong. | See [routing](/docs/routing/) and [payer modes](/docs/payer-modes/). |
| 400 | `escrow_limit` | The escrow for this request would pass the maximum per request. | Lower `max_tokens` or shorten the prompt. |
| 401 | `unauthorized` | Missing, unknown or revoked key, or the payer mode needs a wallet key. | Check the `Authorization` header. Create a key on the [account page](/account/). |
| 401 | `invalid_challenge`, `challenge_expired`, `challenge_used`, `invalid_signature` | Sign-in failed. | Ask for a new challenge and sign it with the same address. |
| 402 | `insufficient_balance` | Your prepaid balance cannot cover the request. The error carries `available` and `required`. | [Top up](/docs/fees/) or lower `max_tokens`. |
| 402 | `insufficient_funds` | In grant mode, your wallet cannot cover the escrow. | Fund your wallet. |
| 402 | `grant_required`, `grant_expired`, `grant_expiring`, `grant_revoked`, `grant_exhausted`, `grant_not_usable`, `grant_per_tx_limit` | Grant mode, and the grant cannot pay for this request. | Sign a new grant on the [account page](/account/), or raise its caps. |
| 404 | `model_not_found` | Unknown model id. | Use an id from `GET /v1/models`. |
| 404 | `miner_not_found`, `session_not_found`, `key_not_found`, `not_found` | Unknown miner, session, key or path. | |
| 403 | `forbidden` | The request did not come through the public endpoint. | Use the documented base URL. |
| 409 | `too_many_keys` | This wallet has the most active keys allowed. | Revoke one first. |
| 200, in a stream | `stream_mismatch` | The streamed text differs from the verified reply. | Use `verified_content` from the error chunk. |
| 413 | `body_too_large` | The request body is too large. | Shorten the prompt. |
| 429 | `rate_limited`, `too_many_concurrent`, `grant_daily_cap`, `demo_budget_exhausted` | A rate, concurrency, grant daily or demo limit was reached. | Wait for the `Retry-After` header, or use a wallet key. |
| 503 | `all_attempts_failed` | Every miner tried failed before producing output. It is 503, not 502, because OpenAI SDKs retry 502 at once and each retry can cost an on-chain fee. | Wait for `Retry-After`, or choose other miners. |
| 503 | `no_miner_available` | No ready miner matches the model and your `provider` rules. | Check the [ready miners](/miners/?reach=ready) or relax `provider`. |
| 503 | `payer_underfunded`, `daily_cap_reached`, `delegate_unfunded`, `payer_unavailable` | The router's wallet cannot pay right now, or hit its daily cap. | Retry later. |
| 503 | `shutting_down` | The service is restarting. | Retry in a few seconds. |

This list follows the server at the time of writing; [`/openapi.json`](/openapi.json) is the reference. Treat an unknown 5xx as retryable after a pause, and any 4xx as a problem with the request.

429 and 503 responses carry a `Retry-After` header.

## Retries

The router already retries on another miner when an attempt fails before any output. A reply that started is never retried, so a client-side retry can open a second channel. Retry only on errors, not on slow replies: a normal reply takes 15 to 50 s on devnet. Set your client timeout to at least 120 s.

```python
client = OpenAI(base_url="https://api.floprouter.com/v1", api_key=key, timeout=120, max_retries=1)
```
