Query Task
Use this endpoint to poll a task until it reaches success or fail.
Endpoint
GET /api/v1/jobs/recordInfo?taskId=task_xxxHeaders
Authorization: Bearer sk-your-api-keyExample
curl "https://aigptimage.com/api/v1/jobs/recordInfo?taskId=task_xxx" \
-H "Authorization: Bearer sk-your-api-key"Example responses
When the task is still running:
{
"code": 200,
"msg": "success",
"data": {
"taskId": "5064bd1a-025a-490b-b28f-6a9fa12eb88a",
"model": "gpt-image-2-text-to-image",
"state": "waiting",
"param": "{\"model\":\"gpt-image-2-text-to-image\",\"input\":{\"prompt\":\"A cinematic portrait of a robot painter\"}}",
"resultJson": null,
"failCode": null,
"failMsg": null,
"costTime": null,
"completeTime": null,
"createTime": 1777474689024
}
}When the task succeeds:
{
"code": 200,
"msg": "success",
"data": {
"taskId": "task_xxx",
"model": "gpt-image-2-text-to-image",
"state": "success",
"param": "{\"model\":\"gpt-image-2-text-to-image\",\"input\":{\"prompt\":\"A cat\"}}",
"resultJson": "{\"resultUrls\":[\"https://cdn.example.com/result.png\"]}",
"failCode": null,
"failMsg": null,
"costTime": 32241,
"completeTime": 1777460000000,
"createTime": 1777459967759
}
}When the task fails:
{
"code": 200,
"msg": "success",
"data": {
"taskId": "5f6ff8ea-ae97-4bb8-af5e-752ef4e96c0d",
"model": "gpt-image-2-text-to-image",
"state": "fail",
"param": "{\"model\":\"gpt-image-2-text-to-image\",\"input\":{\"prompt\":\"360 equirectangular panorama, first-person view standing on stage at a massive concert with Michael Jackson performing, huge crowd cheering with hands raised, bright stage lights, smoke, dramatic spotlight, ultra realistic, cinematic concert atmosphere, immersive perspective, high detail, 2:1 aspect ratio, 4096x2048, no distortion\"}}",
"resultJson": null,
"failCode": "400",
"failMsg": "Sorry, but the image we created may violate OpenAI's content policies.",
"costTime": null,
"completeTime": null,
"createTime": 1777475010433
}
}States
| State | Meaning |
|---|---|
waiting | The task is pending or processing |
success | The task completed successfully |
fail | The task failed or was canceled |
Response fields
| Field | Type | Description |
|---|---|---|
data.taskId | string | Task ID |
data.model | string | Public model ID |
data.state | string | Task status: waiting, success, fail |
data.param | string | Original create task request parameters as a JSON string |
data.resultJson | string | null | Result JSON string. Usually contains resultUrls when successful |
data.failCode | string | null | Failure code when the task fails |
data.failMsg | string | null | Failure message when the task fails |
data.costTime | integer | null | Task duration in milliseconds after completion |
data.completeTime | integer | null | Completion timestamp in milliseconds |
data.createTime | integer | Creation timestamp in milliseconds |
Result format
When state is success, resultJson is a JSON string:
{
"resultUrls": ["https://cdn.example.com/result.png"]
}When state is fail, check:
failCode: platform error code returned for the failed taskfailMsg: human-readable failure reason
The HTTP request itself can still return 200 while the task state is fail. The final task result must be determined from data.state.