Error Codes
All API errors return a JSON response with adetail field:
Status codes
Common errors and fixes
Authentication errors (401)
Authorization: Bearer sk_YOUR_KEY (include the Bearer prefix).
Validation errors (400)
message in your request body.
Unsupported file type (415)
.doc upload returns the same 415:
.pdf, .docx, .txt, .rtf, .md, .html, .htm. Convert legacy .doc files to .docx first. RTF is supported as an upload input only; it is not an export target. Catch 415 (Unsupported Media Type) separately from 400 when handling upload-validation failures.
Rate limit (429)
Retry-After header (seconds until the request can succeed) and branch on the 429 status and the X-Usage-Limit / X-Usage-Used / X-Usage-Remaining headers rather than the detail string (the wording may change). Check the usage object in chat responses to monitor remaining operations. A plain-text 429 with no Retry-After is an infrastructure surge response, not an application error; back off with jitter and retry (see Rate Limits).
Timeout (504)
Both the synchronous/v1/chat and the async /v1/chat/async endpoints apply a 30-minute wall-clock cap to a turn, but they surface the timeout differently:
Synchronous /v1/chat: the gateway’s own request limit is about as long as the cap but counts from when the request arrives, so a sync call that runs that long is normally cut off at the gateway first (or by your own client’s timeout, earlier). You then get an HTTP 504 with a generic body, not JSON, so don’t parse it. The turn is not lost, so don’t send the request again: its outcome is kept for 1 hour in the session’s job list (GET /v1/sessions/{session_id}/jobs, MCP get_session_jobs). Pick the job whose created_at matches your call and poll it with GET /v1/jobs/{job_id} until it ends. Changes applied before the cap stay in the document.
Only when the turn’s own cap fires while the connection is still open do you get the application’s 504, a JSON body whose detail starts like this:
/v1/chat/async does not return a 504 on the poll — the job completes and the friendly summary below is persisted as the job’s AI response (read it from the job result):
/v1/chat/async) for long operations — it streams intermediate progress events as the work runs and supports human-in-the-loop approval. Split large requests into smaller turns (one section per turn).
Request too large (413)
The 413 response covers two distinct cases — caller-too-large and document-too-large for the chosen export format — with a structured JSON detail body so clients can react appropriately. Caller payload exceeds the transport limit:A much smaller ~32 MiB platform limit sits in front of the application. A body over that ceiling is rejected at the gateway with a generic error page (HTML), not this structured JSON body — so don’t try to parse it as JSON. Keep request bodies well under that limit; for large exports, switch to the upload-then-export pattern below.
POST /v1/documents/export/email-request instead — the file will be rendered in the background and emailed as a 7-day signed download link. See Email fallback for very large documents.
Validation errors (422)
format is now a strict enum on /v1/documents/export. Use one of "docx", "pdf", "html", "markdown", "txt". The value "doc" is accepted as a legacy alias and will be removed in a future release.
session_id may contain only letters, digits, and the characters _, -, and ., up to a maximum of 256 characters. Drop spaces, slashes, and other punctuation from the id you choose.
Not found (404)
/v1/jobs to list active jobs.
Revert conflicts (409)
/v1/jobs/{job_id} or watch the SSE stream until you see final), or cancel it via POST /v1/jobs/{job_id}/cancel before retrying revert.