Skip to main content

Quickstart

The native image endpoint is synchronous by default. Set the Boolean field async to true to create a background task. This example uses qwen-image-2.0.

How Do You Discover Async Media Models and Get Their Schemas?

The discovery flow has two steps. First, retrieve text-to-image or text-to-video models that support the async APIs from the public model catalog. Then use a model’s model_id to retrieve the request Schema for its endpoints.

List Models That Support the Async APIs

The model catalog uses the same data source as Playground. Use type=image_generation for text-to-image models and type=video for text-to-video models. Adding schema_checked=true limits the list to models with a published and reviewed request Schema.
Both requests use the same endpoint. The type filter currently accepts one value, so request each model type separately. The response has the shape {success, message, data}. The following fields in data are relevant to async media integrations.

Get the Request Schema for One Model

Supported fields, enumerations, and numeric ranges can vary by model. Before submitting an image or video request, use the public endpoint below to retrieve the available endpoints and request JSON Schemas for the selected model.
The response has a modality of image or video. Each item in the endpoints array describes one available calling protocol. A model may return both /ai/v1 endpoints and OpenAI-compatible /v1 endpoints. OpenAI-compatible endpoints may not yet support the latest models, so prefer the /ai/v1 endpoints. For async task APIs, select the item whose path is /ai/v1/images/generations or /ai/v1/videos, then use its request.schema. Do not depend on the position of an item in the endpoints array. The following commands extract the request Schema for each async task endpoint.
The endpoint returns 404 model_not_found when the model does not exist or has no discoverable endpoints. It returns 500 endpoints_unavailable when endpoint data is temporarily unavailable.

How Do You Create Image Tasks?

Synchronous Images

When async is omitted or set to false, the endpoint waits for generation to finish and returns a task object:
Synchronous image tasks also save a task record. If the client connection is interrupted or the creation response is lost, use GET /ai/v1/images to find the corresponding task.

Asynchronous Images

When async is set to the Boolean value true, the endpoint returns a task object immediately and generation continues in the background:
Use GET /ai/v1/images/{id} to query an asynchronous image task. After completion, request the content_url from each output item directly. The URL already contains the corresponding image result_id.
async in an image request must be a Boolean. webhook_url and webhook_events_filter can only be used with async: true.

Standard Image Fields


Media Task Object

Image and video endpoints return the following structure:
Media output item:

Status Reference

Clients can query every 15 seconds until the status becomes completed, failed, or cancelled. The 15-second interval is a client polling recommendation, not a server protocol limit.

How Do You Query Media Tasks?

Get Media Details

Media detail endpoints can return an updated task status, so use the corresponding image or video detail endpoint for media polling.

List Media Tasks

If the creation response is lost, use the corresponding media list to recover the task ID:
Media lists return task snapshots at query time and do not actively update task status.

How Do You Use the Unified Task API?

The unified task API supports the following filters:
Unified task details:
A unified output item for a media task:
For a single-artifact task, request /ai/v1/tasks/{id}/content directly. For a multi-artifact task, request /ai/v1/tasks/{id}/content/{result_id}. Omitting the result ID returns 400 result_id_required.
Unified task list, detail, and content endpoints are isolated by the Bearer token used to create the task. Other API Keys under the same account cannot read the task.

How Do You Download Media Results?

Download Images

After an image task is completed, request output[].content_url from the media task object for each result:
The media download path for images is /ai/v1/images/{id}/content/{result_id}. The media task object does not expose result_id separately, so clients can use content_url directly. When b64_json is not empty, decode that field directly from Base64.

How Do You Use Webhooks?

Asynchronous images and videos support task-level webhooks:
webhook_url can be up to 512 characters and cannot point to localhost, private networks, or other restricted addresses. When webhook_events_filter is omitted, the platform sends completed, failed, and cancelled. When explicitly provided, the array must not be empty or contain duplicates, and it must be used with webhook_url. When webhook_url is omitted from the request, asynchronous image and video tasks try to use the default callback URL configured for the account. An invalid account default is ignored and does not prevent task creation.

Callback Request

results appears only when results have been archived. Downloads still require a Bearer token.

Retries and Deduplication

The platform uses at-least-once delivery, so the same event may be delivered more than once:
  • HTTP 2xx indicates successful receipt.
  • HTTP 5xx, network errors, or timeouts trigger a retry.
  • HTTP 3xx and 4xx are not retried.
  • Up to 6 delivery attempts are made, with retry intervals of 1, 4, 16, 64, and 256 seconds.
The receiver should store event_id and return 2xx immediately when the same event is received again.
Task-level webhooks do not include a separate signing secret. If signature verification is required, configure an account-level webhook subscription and retain task detail queries as the method for confirming results.

Error Responses and Error Codes

This section applies to /ai/v1/images/* and image tasks. For video errors, see the video API.
  • Current request failure: A non-2xx HTTP status means the current creation, query, or download request failed. See HTTP Request Failures.
  • Task execution failure: The query returns HTTP 200, but the task has status=failed, with the cause recorded in its error. See Task Execution Failures.
  • Output read failure for an individual list row: The list returns HTTP 200, but a task includes output_error. See Individual List Output Read Failures.
The message columns below contain the English response messages. The description columns explain their meaning and how to handle them. Parameter validation errors show generic messages; actual responses may identify specific fields and constraints. Clients should identify error types by code and should not depend on matching the full message.

Report an HTTP 5xx Error

When a request returns HTTP 5xx, submit feedback and include error.tid.

HTTP Request Failures

The HTTP statuses below apply when the current request fails directly. For execution failures after a task has been created, see the Task Execution Failures table below.

Request Parameters and Media Input

Size Limits
  • Media size: Image tasks that exceed the limit return image_too_large. See the error message or error.details.max_bytes for the exact limit.
  • Total request size: request_too_large means the HTTP request body exceeds 32 MiB, including text, parameters, and inline media encoding. When only a URL is provided, the URL itself counts toward the request body size, and the referenced file must still meet the model’s media limits.
  • Actual size: error.details.actual_bytes is provided only when the full size is confirmed. When media is read from a URL and reading stops at the limit, this field may be omitted.
Supported Formats Supported formats depend on the selected model. First check error.details.allowed_mime_types or the format list in the error message. If no list is provided, consult the model’s Schema. Message Placeholders
  • {media_kind}: The actual media type. When the type is confirmed, the messages for invalid_media_data and media_url_unreachable also use image or video.
  • {max_bytes}: The size limit in bytes. If the image limit is unknown, the response is The image is too large. Reduce the image size and try again.
  • {allowed_formats}: The list of allowed formats. Format error messages may append Use one of: {allowed_formats}.

Generation Requests and Returned Results

Account and Permissions

Service Availability and Rate Limits

provider_unavailable indicates a positively identified model provider failure. A generic 429 or 4xx status alone cannot establish an account quota, content moderation, or parameter issue.

Task Queries and Result Downloads

Task Execution Failures

After a task is successfully created, generation failures are reported through status=failed and the task’s error. A successful query still returns HTTP 200.
Media input errors may also appear in failed tasks. Their codes have the same meanings as in the media input table above; successful queries still return HTTP 200. For media size errors, the message ends with submit a new task., instructing you to reduce the media size before submitting a new task. output_blocked indicates an explicit block with no usable image returned, and no generation fee is charged for this attempt. Existing content moderation billing rules apply to output_policy_violation. Refer to billing records for historical charges.

Individual List Output Read Failures

Individual rows in image and video task lists may include output_error:
This field indicates that the row’s output could not be read for this request. The list still returns HTTP 200, with output=[] for that row. Its original id, status, error, and pagination remain unchanged, and other readable tasks are unaffected. Even when status=completed, check output_error before deciding whether the result can be read. Contact support with output_error.tid. If the field has no tid, provide the request ID from the current response headers. This error does not change task status or charges, and does not trigger a Webhook. Image and video lists preserve any expires_at already retrieved. Rows whose output could not be read in the unified /ai/v1/tasks list may return expires_at=null; the original retention period still applies to those results. This handling applies only when an individual row’s output cannot be read and no fallback is available. A query failure for the entire batch in the unified tasks API still returns an HTTP error; the same type of failure when reading task details still returns HTTP 500. Related documentation: Image API · Video API · Async Tasks

Complete example

These examples create an asynchronous task, poll it, and save every returned image.