Create image task
Create an asynchronous image generation task and poll polling_url for completion.
POST /api/v1/image-tasks
For long-running tasks such as Jimeng image generation. Creation persists the task in the local queue and returns a virtual task ID; background workers submit, poll, store results, and finalize billing. Use Create images for immediate image responses.
Back to Images endpoint listRequest parameters
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | GlobalRouter image model ID, such as jimeng_t2i_v31. |
prompt | string | Yes | Image generation prompt. |
input_references | object[] | No | Reference image list; each entry contains type=image_url and image_url.url. |
n | integer | No | Number of images, defaulting to 1; the maximum depends on model capability configuration. |
size | string | No | Image dimensions in WxH format or a supported model tier, such as 2K for Seedream. Do not combine with resolution or aspect_ratio; see notes below for GHYZ dimensions. |
aspect_ratio | string | No | Aspect ratio: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 16:9, or 9:16. |
resolution | string | No | Resolution tier: 1K, 2K, or 4K; send with aspect_ratio. See the notes below for supported sizes. |
quality | string | No | Quality level, such as auto, low, medium, or high. |
seed | integer | No | Random seed. |
output_format | string | No | Output format, such as png, jpeg, or webp. |
response_format | string | No | Return url or b64_json. |
provider.provider_id | string | No | Select a provider, such as doubao_gr. Once selected at creation, the same provider is used for submission and polling. |
provider.options | object | No | The current asynchronous endpoint does not forward this object. Use the synchronous endpoint for advanced Seedream options. Do not include AK/SK. |
webhook_url | string | No | HTTPS webhook URL. Completion and failure notifications are delivered through the background outbox. |
metadata | object | No | Client metadata. Omit req_key; the server derives it from model + provider_model_id. |
Request examples
curl "https://api.globalrouter.com/api/v1/image-tasks" \
-H "Authorization: Bearer $GR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "生成一张 16:9 的模型网关控制台产品插图,白色背景,简洁科技风,画面中有一块显示实时延迟曲线的面板。",
"provider": { "provider_id": "ghyz" },
"size": "2048x1152",
"n": 1,
"response_format": "url",
"quality": "high"
}'Response fields
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | GR virtual image task ID, such as imgtask_xxx. |
object | string | Yes | Always image.task. |
status | string | Yes | Status such as queued, submitting, submitted, in_progress, completed, failed, or expired. |
model | string | Yes | Requested model. |
provider | string | Yes | Provider fixed at creation. |
polling_url | string | Yes | Relative URL for polling task status. |
data | object[] | No | Image details returned after completed. |
data[].url | string | No | Image URL. |
data[].b64_json | string | No | Base64 image content. |
usage | object | No | Usage summary after the background polling worker finalizes billing. |
error | object | No | Failure reason. |
Response example
{
"id": "imgtask_xxx",
"object": "image.task",
"status": "queued",
"model": "gpt-image-2",
"provider": "ghyz",
"polling_url": "/api/v1/image-tasks/imgtask_xxx",
"created_at": 1770000000,
"updated_at": 1770000000,
"data": [],
"usage": {
"billing_status": "unreserved"
},
"metadata": {
"client_request_id": "client-001"
}
}Errors
| HTTP | Code | Description |
|---|---|---|
| 400 | ROUTER_IMAGE_TASK_PROVIDER_RELATION_NOT_FOUND | The model has no available provider binding, or provider_model_id/req_key is missing. |
| 429 | ROUTER_IMAGE_TASK_QUEUE_FULL | The tenant or API key asynchronous image queue is full. |
| 503 | ROUTER_IMAGE_TASK_QUEUE_DISABLED | The asynchronous image task queue is disabled. |
Notes
- The server derives req_key from model and provider_model_id; normal clients do not need to supply it.
- The task provider is fixed in image_tasks.provider_id; polling does not reroute by model.
- The following sizes apply to GHYZ asynchronous image-to-image (model=gpt-image-2); other models use their capability configuration.
- 1K (9 sizes): 1:1 1024x1024, 2:3 1024x1536, 3:2 1536x1024, 3:4 1152x1536, 4:3 1536x1152, 4:5 1216x1520, 5:4 1520x1216, 16:9 1536x864, 9:16 864x1536.
- 2K (9 sizes): 1:1 2048x2048, 2:3 1344x2016, 3:2 2016x1344, 3:4 1536x2048, 4:3 2048x1536, 4:5 1600x2000, 5:4 2000x1600, 16:9 2048x1152, 9:16 1152x2048.
- 4K (9 sizes): 1:1 2880x2880, 2:3 2336x3504, 3:2 3504x2336, 3:4 2448x3264, 4:3 3264x2448, 4:5 2560x3200, 5:4 3200x2560, 16:9 3840x2160, 9:16 2160x3840.
- You may send only resolution and aspect_ratio: resolution is 1K, 2K, or 4K; aspect_ratio is 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 16:9, or 9:16. The server calculates the size (for example, resolution=2K + aspect_ratio=16:9 yields 2048x1152). With size=auto, the upstream provider determines the size.
- Size constraints: dimensions must be multiples of 16, the longest side must not exceed 3840, the aspect ratio must not exceed 3:1, and total pixels must be between 655360 and 8294400. Requests exceeding these limits fail during upstream submission, with final task status failed.
- Billing has two output-pixel tiers: up to 2360000 pixels and above 2360000 pixels. For example, 2048x1152 (2359296 pixels) and 2048x2048 (4194304 pixels) fall into different tiers.