Errors & billing
Distinguish rejected requests, failed tasks and unknown outcomes, and understand balance holds and settlement.
Request errors and task failures
Check the HTTP status first. A rejected model-task request can return an error object such as:
{
"error": {
"message": "The request contains an invalid parameter.",
"type": "invalid_request_error",
"code": "invalid_parameter"
}
}Use the status and public error.code, not exact message text. Where present, param, allowed_values or suggested_models help you fix the request. Different endpoints do not guarantee identical error enums: keep an unknown-error branch and consult the selected OpenAPI.
An accepted task can fail later. A successful GET (HTTP 200) with status: "failed" is a terminal task failure, not a successful generation. Model tasks expose error.code and message, and may include issues; video task failures only guarantee error.message. A network timeout leaves the outcome unknown.
HTTP recovery guide
| Status | Meaning and next step |
|---|---|
| 400 | Invalid request: check the model ID, required fields, types and allowed values. invalid_request_id requires 1–128 letters, digits, _ or -. native_model_unavailable means the model uses another endpoint: read its openapi_url and suggested_models. |
| 401 | invalid_api_key: check the Bearer header and key. |
| 402 | insufficient_balance: a new task was not created. Top up enough to cover any debt and the required hold. Keep the same ID and request for an unchanged async retry; do not parse amounts from message text. |
| 403 | Check model permission (access_denied), disabled key (api_key_disabled) or allowed IPs (api_key_ip_not_allowed). |
| 404 on POST | model_not_found: this ID cannot be called with this key. Do not resend unchanged; use an ID from suggested_models or the live catalog and check its contract. |
| 404 on task GET | task_not_found: verify the original key and ID. If submission may not have arrived, resend the identical async POST with the same ID instead of polling forever. |
| 404 on artifact GET | artifact_not_found: wait for completed, use the submitting key and download only indexes declared in output. Do not start a new generation to fix a download error. |
| 409 | request_id_conflict: the ID was already used with another body or key (a different spelling of the model ID counts). Keep the original bytes for retries; use a new ID for a new generation. task_not_cancellable means a model task is no longer waiting in the queue; keep polling its returned status. |
| 429 | For rate_limit_exceeded, back off. api_key_quota_exhausted needs a quota change or another authorized key. too_many_active_tasks means the image-task active/settling limit or the model-task queue limit was reached; wait, then resend an unchanged async request with the same ID. Model tasks beyond the running limit normally queue first. |
| 5xx | Temporary failure, such as auth_unavailable, model_route_unavailable, channel_unavailable or upstream_unavailable. Async POST retries keep the same ID and body with backoff; failed GETs retry the same GET. For video or synchronous-image POSTs, inspect logs before deciding whether to resubmit. |
Terminal asynchronous task failures
Once status is failed, stop polling. These outcomes release the hold in full; another generation needs a new X-Request-Id. The old ID keeps returning the failed task.
error.code | Meaning and recovery |
|---|---|
generation_timeout | No result within 15 minutes after acceptance, or submission still unconfirmed after 15 minutes. The platform ends the task without charging you; later provider costs are borne by the platform. Try a new task if needed. |
upstream_unavailable | The generation service did not accept submission. Wait before creating a new task; this does not mean the input was invalid. This terminal outcome differs from an HTTP 5xx while submission is uncertain. |
invalid_parameters | Model-task input was rejected. Fix fields listed in error.issues, each with a field path and rule (for example unsupported_value, file_format, duration or content_policy). Raw provider diagnostics are not the contract. |
cancelled | You cancelled a model task while it was waiting in the queue; it was never sent to the model. |
queue_timeout | A model task waited in the platform queue for 5 minutes without starting. Try later. |
model_unavailable_while_queued | The model went offline or its route changed while queued. A new task will use the current route. |
insufficient_balance | While queued, other actual charges made the balance negative. This task never started. Top up to cover the debt before creating a new task. |
Use the same key to cancel a waiting model task with POST /v1/model-tasks/{id}/cancel. It returns status: "failed" with code cancelled; cancellation is unavailable once dispatch has begun. Image tasks do not currently support cancellation. Video deletion/cancellation follows its own schema; deleting a completed record does not refund a successful generation.
Poll every 5 seconds with a finite waiting budget: 25 minutes for model tasks, 20 minutes for image tasks. Queue position is an estimate; task objects may gain fields, so ignore unknown fields. Reaching the client deadline only stops waiting: save the ID and check later, rather than switching providers or resubmitting with a new ID.
Balance holds and final charges
The live catalog and selected model schema are the price source. Read pricing.basis, rules, usage, tokens and prepayment where present; do not treat this guide's sample request as a fixed price quote.
fixedormeasuredpricing follows the matching rules, currency, metric and unit. Images may be charged per image; videos may use output tokens. Do not apply one model's formula to another.- For
usage, settlement follows actual usage.pricing.usagepublishes a unit price where available (for example per image, megapixel orthousand_characters).conditional: truemeans the price is for default settings and other settings can change it. Without a public unit price, use actual cost;pricing.typical, if present, is an estimate, not a rate. pricing.tokens, where present, lists USD per 1 million tokens for the kinds actually billed, such astext_input,image_input,input,text_output,image_outputorcache_read. Other token rules use their ownpriceandunit: charge = tokens × price ÷ unit. Readx-billing-basisfor model-specific alignment or dimensions.pricing.prepaymentis held at submission, including while a task waits in the queue.amountis the maximum hold per request, or per requested image whenperisimage. The balance must be at least the greater of $0.01 and the calculated hold.- With
scales_with, hold =price× max(Unicode code points in the declaredfield, 1) ÷per, rounded up to $0.000001 and capped atamount. An undeclared top-level field, another top-level text longer than 64 characters without anenum/const, or more than 64 characters of text inside another top-level list/object causes the fullamountto be held. Withoutscales_with, holdamount(per requested image when specified). - Speech priced per
thousand_charactersis prorated to actual input length, including spaces, punctuation and tags. Withoutscales_with, the hold uses the maximum accepted text length; with it, the request's text length determines the hold. - Settlement charges actual usage in full: unused hold is released and any excess is debited from the balance. A hold is not a spending cap; balance can become negative. New requests return 402 until a top-up covers the debt.
- Confirmed rejection, generation failure or successful cancellation before dispatch is not charged. Uncertain submission, a disconnected client, stopped polling or a missing download is not proof of failure. Multiple-image billing follows actual results, not automatically the maximum image count requested.
- Task completion can precede settlement and log updates. Check settled usage and cost in Usage logs; a result may already exist while its charge is still being reconciled. Status queries and refreshing image-task result links do not create another generation charge.
Retry decision
Model tasks and asynchronous image tasks: save the ID before submitting. On connection failure, a lost response, retryable HTTP 429 or 5xx, resend with the same ID, original key and unchanged body (byte-identical for model tasks). Once a task is terminally failed, inspect the cause and use a new ID only if you want a new generation. Correct validation or permission errors before retrying.
Synchronous images and videos: these POSTs do not deduplicate by request ID. Automatic retries may generate and charge again. With a video ID, continue querying it; without a response, inspect matching usage logs and allow for delayed settlement. If the outcome remains unknown, investigate before resubmitting.
Downloads: retry the same file GET on a transient error. For image tasks, refresh an expired signed URL by querying the completed task within its result lifetime. Model tasks use their authenticated artifact endpoint and model-specific output. Save results promptly; closing the page or losing a URL does not reverse a successful charge.
Troubleshooting checklist
- Record the endpoint, HTTP status, public error and task/request ID. Never share the key or signed media URLs.
- Check Usage logs, API key permissions and quota, and Balance.
- Re-read the live catalog and selected model's OpenAPI for listing status, ID, endpoint and fields.
- Query and download with the same API key that submitted the task.
- Follow Quickstart for a complete current image-task example. If unresolved, provide the redacted facts above for support; do not repeatedly create new paid tasks.