GPT Image-2 - Text to Image
This page is generated from the upstream official OpenAPI documentation. Endpoints, parameters and examples match the official docs; brand and API domain are replaced with ModelFold.
Endpoint
POST /jobs/createTask
Full URL: https://ai.modelfold.online/v1/jobs/createTask
Authentication: every request must include the
Authorization: Bearer <API_KEY>header.
Create Task
Use this endpoint to create a new text-to-image generation task.
- Get Task Details — After submission, use the unified query endpoint to check task progress and retrieve results
TIP
For production use, we recommend providing the callBackUrl parameter so your service can receive completion notifications instead of polling for task status.
Related Resources
- Model Marketplace — Explore all available models and capabilities
- Common API — Check account credits and usage
Request Parameters
Body (application/json)
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | The model name used for generation. This field is required. This endpoint must use the gpt-image-2-text-to-image model. Default:"gpt-image-2-text-to-image"。 Allowed values:gpt-image-2-text-to-image。 示例:gpt-image-2-text-to-image。 |
callBackUrl | string | No | Callback URL for task completion notifications. Optional parameter. If provided, the system will send a POST request to this URL when the task completes, whether it succeeds or fails. If omitted, no callback notification will be sent. To ensure callback security, see Webhook Verification Guide. 示例:https://your-domain.com/api/callback。 |
input | object | Yes | Input parameters for the text-to-image task. |
input.prompt | string | Yes | Text prompt. Required, maximum 20,000 characters. 示例:A cinematic night city poster with neon reflections on a rainy street.。 |
input.aspect_ratio | string | No | The aspect ratio of the generated image is set to auto by default. Note: for 2K resolution, the following aspect ratios are not supported: 5:4, 4:5, 3:1, 1:3, and 9:21. for 4K resolution, the following aspect ratios are not supported: 3:1, 1:3, and 9:21. Allowed values: auto / 1:1 / 3:2 / 2:3 / 4:3 / 3:4 / 5:4 / 4:5 / 16:9 / 9:16 / 2:1 / 1:2 / 3:1 / 1:3 / 21:9 / 9:21。 示例:auto。 |
input.resolution | string | No | Output resolution: 1K, 2K or 4K. Set this field explicitly. 2K does not support 5:4, 4:5, 3:1, 1:3 or 9:21; 4K does not support 3:1, 1:3 or 9:21. The background parameter is only available at 1K. Allowed values:1K / 2K / 4K。 示例:1K。 |
input.background | string | No | Image background Note: This parameter is only supported when the resolution is 1K. Allowed values: transparent / opaque / auto。 示例:transparent。 |
Request Example
bash
curl -X POST "https://ai.modelfold.online/v1/jobs/createTask" \
-H "Authorization: Bearer $MODELFOLD_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2-text-to-image",
"callBackUrl": "https://your-domain.com/api/callback",
"input": {
"prompt": "A cinematic night city poster with neon reflections on a rainy street.",
"aspect_ratio": "auto"
}
}'json
{
"model": "gpt-image-2-text-to-image",
"callBackUrl": "https://your-domain.com/api/callback",
"input": {
"prompt": "A cinematic night city poster with neon reflections on a rainy street.",
"aspect_ratio": "auto"
}
}Response
200 — Request successful
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
code | integer | 否 | Status code of the request. The HTTP status is 200 even when the request fails, so always check this field: 200 means success; any other value means the request failed and msg describes the reason. Common values: 401 invalid or missing API key; 402 insufficient credits; 429 rate limit exceeded; 422 or 500 the request could not be processed (read msg and check your parameters before retrying). 可选值:200 / 401 / 402 / 404 / 422 / 429 / 433 / 455 / 500 / 501 / 505。 示例:200。 |
msg | string | 否 | Response message, error description upon failure 示例:success。 |
data | object | 是 | — |
data.taskId | string | 是 | The task ID can be used with the "Get Task Details" endpoint to query the task status. 示例:dc1928bfcbc77cb6c85f3359a9c718b3。 |
json
{
"code": 200,
"msg": "success",
"data": {
"taskId": "task_gptimage_1765180586443"
}
}Callback
onImageGenerated
Callback URL: {$request.body#/callBackUrl} (the callBackUrl in the request body).
Sent when the task succeeds or fails.
Callback body parameters
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
code | integer | 否 | 200: success. 501: failure; see data.failCode and data.failMsg. Allowed values:200 / 501。 示例:200。 |
msg | string | 否 | Status message 示例:Playground task completed successfully.。 |
data | object | 否 | — |
data.completeTime | integer | 否 | Task completion time, represented as a Unix timestamp in milliseconds 示例:1786432830000。 |
data.costTime | integer | 否 | Processing time in seconds. Present on both success and failure callbacks. 示例:83。 |
data.createTime | integer | 否 | Task creation time, represented as a Unix timestamp in milliseconds 示例:1786432746000。 |
data.creditsConsumed | number | 否 | Credits consumed by the task; 0 for failed tasks. 示例:3。 |
data.model | string | 否 | Image generation model used for the task 示例:gpt-image-2-text-to-image。 |
data.param | string | 否 | Parameters submitted when creating the task, in JSON string format 示例:{"input":"{\"aspect_ratio\":\"auto\",\"prompt\":\"A cinematic night city poster with neon reflections on a rainy street.\"}","callBackUrl":"https://your-domain.com/api/callback","model":"gpt-image-2-text-to-image"}。 |
data.resultJson | string | 否 | Image generation result in JSON string format. resultUrls contains the list of generated image URLs. Present only when state is success. 示例:{"resultUrls":["https://tempfile.aiquickdraw.com/images/chatgpt/file_000000002b24820caef9f1684a4f4747.png"]}。 |
data.state | string | 否 | Task status Allowed values:success / fail。 示例:success。 |
data.taskId | string | 否 | Task ID 示例:ed578231bfed231f0884c564579a965d。 |
data.updateTime | integer | 否 | Use completeTime as the completion time; updateTime may equal createTime. 示例:1786432830000。 |
data.failCode | string | 否 | Failure code, a numeric string such as "400" or "500". Present only when state is fail. 示例:500。 |
data.failMsg | string | 否 | Failure reason. Present only when state is fail. 示例:<error detail>。 |
Success
json
{
"code": 200,
"msg": "Playground task completed successfully.",
"data": {
"taskId": "ed578231bfed231f0884c564579a965d",
"model": "gpt-image-2-text-to-image",
"state": "success",
"param": "{\"input\":\"{\\\"aspect_ratio\\\":\\\"auto\\\",\\\"prompt\\\":\\\"A cinematic night city poster with neon reflections on a rainy street.\\\"}\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"model\":\"gpt-image-2-text-to-image\"}",
"resultJson": "{\"resultUrls\":[\"https://tempfile.aiquickdraw.com/images/chatgpt/file_000000002b24820caef9f1684a4f4747.png\"]}",
"completeTime": 1786432830000,
"createTime": 1786432746000,
"costTime": 83,
"creditsConsumed": 3,
"updateTime": 1786432830000
}
}Failure
json
{
"code": 501,
"msg": "Playground task failed.",
"data": {
"taskId": "ed578231bfed231f0884c564579a965d",
"model": "gpt-image-2-text-to-image",
"state": "fail",
"param": "{\"input\":\"{\\\"aspect_ratio\\\":\\\"auto\\\",\\\"prompt\\\":\\\"A cinematic night city poster with neon reflections on a rainy street.\\\"}\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"model\":\"gpt-image-2-text-to-image\"}",
"failCode": "500",
"failMsg": "<error detail>",
"completeTime": 1786432830000,
"createTime": 1786432746000,
"costTime": 83,
"creditsConsumed": 0,
"updateTime": 1786432830000
}
}