Chat API
Read this page as MarkdownIn this section: Errors
Errors
See every Chat API status, along with its cause and fix.
The envelope
Every error uses the OpenAI JSON shape, including 413 errors raised before body parsing and errors raised mid-stream. The exception is an OAuth bearer that fails its check, which gets the RFC 6750 shape, {"error": "invalid_token", "error_description": "access token expired"}.
{"error": {"message": "api key revoked or unknown", "type": "invalid_request_error", "code": "invalid_api_key"}}A 401 includes WWW-Authenticate: Bearer realm="askmiles", error="invalid_token" with an error_description; a 401 for a missing bearer carries Bearer realm="askmiles" alone. This lets OAuth-aware SDKs apply the same retry logic for either bearer type. A 429 carries Retry-After. Every error response is no-store except one raised before the request reaches the endpoint, such as the 413.
One more error skips both shapes: a plain-text 403 from Cloudflare, returned before Miles sees the request when the User-Agent is a stock Python-urllib. Use a client library.
The table
| Status | type | code or message | Cause | Fix |
|---|---|---|---|---|
| 400 | invalid_request_error | request body must be a JSON object | The body was not an object | Send {"model": "miles", "messages": [...]} |
| 400 | invalid_request_error | names the field | A role other than system/user/assistant, an image or audio part, a malformed messages entry, a last message that is not user, a message over 5,000 characters, or a conversation over 130,000 characters in total | Remove the part or trim the messages; only text content is read |
| 401 | invalid_request_error | invalid_api_key | The personal API key was revoked or never existed, or its account was deleted | Mint a new key |
| 401 | none (RFC 6750 body) | invalid_token | The OAuth access token expired, was revoked, or is not a Miles credential | Refresh the token, or authorize again |
| 401 | none (RFC 6750 body) | invalid_request | No bearer token was sent | Send a personal key or a miles:chat token |
| 403 | none (RFC 6750 body) | insufficient_scope | The OAuth token lacks miles:chat | Authorize again with miles:chat |
| 403 | invalid_request_error | connections_paused | The account paused its AI app connections. An OAuth token gets the same code in the RFC 6750 body | The user turns them back on at Settings → Connected AI Apps; nothing to re-mint |
| 413 | invalid_request_error | The data value transmitted exceeds the capacity limit. | The body exceeded the 2 MB size cap | Trim history; Miles reads only the new question and the last 26 earlier messages anyway |
| 429 | rate_limit_exceeded | rate limited, retry after Ns | The per-minute window is full. GET /v1/models has its own such window, separate from the one completions use | Wait Retry-After; safe to retry |
| 429 | rate_limit_exceeded | concurrency limited, retry after 2s | Another turn is running on this grant or on another grant of the same account, or the service is at its shared ceiling | Reduce parallelism, then retry |
| 429 | rate_limit_exceeded | You've reached today's usage limit. Please try again later. | The account's daily spend allowance is full. This is not the per-minute window and does not clear in a minute | Wait Retry-After, which is an hour here; the allowance is a rolling 24 hours, so capacity returns as earlier spend ages out |
| 429 | insufficient_quota | You've used this month's budget. It resets on …, or a trial-budget message during a Membership trial | The account's monthly budget is spent | Wait Retry-After, which is the seconds until the reset date and can be days, so do not retry on the usual 429 schedule. Members get a much larger monthly budget |
| 500 | server_error | the pipeline failed to answer | Miles could not produce an answer | Retry once; if it repeats, the outage is on Miles' side |
| 504 | timeout_error | the request took too long to answer | A non-streaming turn passed 90 seconds | Retry with stream: true, which has no turn timeout |
The endpoint holds no state, so retrying a 429 or 504 cannot leave a partial write. A 400, 401, or 403 returns the same answer until its cause changes.
Mid-stream
After a stream opens, an error arrives in one final data: event with the envelope above, and the stream closes with no data: [DONE]. The stream's HTTP status is already 200, so read the event.
Catalog and MCP errors
See Catalog errors for the keyless catalog API's {"error": "message"} shape. MCP tool refusals arrive as isError results with a structured code. The Quotas and refusals page documents them. The Error codes reference has an anchor for every type and code in this endpoint's envelope and every MCP and tool refusal code. invalid_token, invalid_request and insufficient_scope are RFC 6750 bearer errors, and WWW-Authenticate carries invalid_token and insufficient_scope. They have no Miles refusal-code entry. This page is their only documentation.