status: "failed" when the request was accepted but the Canvas could not finish. Handle both.
HTTP status codes
See Errors in the API reference introduction for the conventions shared by every endpoint.
The error body
Errors are JSON objects with acode, a human-readable message, the HTTP status and name: "Error". Some errors add a details field with more information about what was rejected.
status and code rather than on message, which is meant for people and may change.
Failed runs
When an asynchronous run cannot finish, the HTTP call that created it still returned200. The failure shows up later as status: "failed" in the run you poll with GET /v2/chat/completions/{id}, in the payload posted to your webhook_url, and in GET /v1/completion-run. Treat failed as terminal: a run does not leave that status by itself.
The fields a failed run carries about the cause of the failure are not documented here. The run is also visible in the Canvas Usage, where you can inspect its inputs.
What is safe to retry
GET /v2/chat/completions/{id},GET /v1/completion-runandGET /v3/files/{id}are read-only. Retry them freely, for example on a network timeout or a5xx.POST /v2/chat/completionsstarts a run. Each accepted request creates a new run with its own ID and is counted in your usage, so a blind retry after a timeout may run the Canvas twice. No idempotency key is documented for this endpoint. If the request was rejected with a4xx, no run was created and you can send a corrected request.POST /v3/filesonly reserves an upload URL and a file ID. Retrying it creates another ID, which is harmless as long as you reference the one you actually uploaded to.
POST /v2/chat/completions (you never received the response), tag each request with an identifier of your own, such as order-123, and query GET /v1/completion-run?tags=order-123 before sending it again. If a run with that tag exists, read its result instead of creating a new one. See Listing past runs.
When you do retry a 5xx or a network error, wait between attempts and add some randomness to the delay, so that many clients failing at once do not retry at the same moment.
Rate limits and concurrency limits for the Completion API are not documented here. If you receive a status code that indicates throttling, slow down and retry after a delay.
Avoiding errors before they happen
- Send every variable the Canvas marks as required, using the names shown in Connect via API. The
variablesDefinitionsof a run’smetadatainGET /v1/completion-runlist each variable with itstype(file,textormixed) and whether it isrequired. - Wrap file URLs in an object with
file_url, and check that the file is in a supported format and reachable from the internet (or uploaded with/v3/files). - Use only one of
canvas_id,version_idandapplication_id, and only combineenvironment_namewithcanvas_id. - Do not send
streamorasyncwithapplication_id: tasks are always asynchronous. - Keep the
x-compatibility-dateheader on the file endpoints that require it. See Compatibility date.