Overview
Image generation and editing via OpenAI GPT-4o image capabilities. Excels at precise instruction-following, photorealistic rendering, and multi-step image editing tasks.
Primary Endpoint
/api/v1/userGptImage/startGenerate images from text or edit existing images using GPT Image (4o Image) model. **Features:** - Text-to-Image generation - Image-to-Image editing (supports up to 16 reference images) - High-fidelity visuals with accurate text rendering **Output:** - Images are stored in R2 storage and expire after 3 days - GPT Image 1.5/2 default to JPEG. GPT Image 2.5/2.6 preserve the upstream PNG for auto and transparent backgrounds. ### Request - Send a valid bearer token. The server evaluates the operation in the authenticated caller's access context. - Send an `application/json` body. Required fields: `name`, `prompt`. - API-token callers may include `webhook_url` and `webhook_token` for best-effort terminal-state notifications; ordinary JWT/cookie calls ignore these fields. ### Behavior - This is an asynchronous operation: a successful submission creates a task and returns before processing finishes. - Persist the returned task identifier and use the corresponding detail or list operation to observe progress. - Treat the detail endpoint as the source of truth even when webhook delivery is enabled. ### Response - A `200` response confirms task acceptance; it does not by itself mean media generation has completed. - Retain the returned identifier and wait for a documented terminal status before using output URLs. - JSON object responses, including error responses, normally carry a top-level `trace_id` string for this request; include it when contacting support. It is not a task identifier. - Do not infer undocumented fields or statuses; clients should tolerate additional response properties. ### Errors - `401` — Unauthorized - Invalid or missing JWT token. - `422` — Content moderation rejected the `input_images`. Code `1003` means confirmed minor content. Code `1004` means suspected minor content. For `1004`, confirm the input and retry with `minor_suspected_skip: true`. ### Related Operations - `GET /api/v1/userGptImage/list` — Get GPT Image task list. - `GET /api/v1/userGptImage/detail/{id}` — Get task details. - `DELETE /api/v1/userGptImage/{id}` — Delete GPT Image task. Authentication: set header Authorization: Bearer <token> (supports user JWT or sk_ API token).
Request Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| ai_sharing_consent | object | No | Consent receipt for newer native apps. Legacy native requests may omit this field and continue without a consent record. If present, null, malformed, expired or incomplete receipts return AI_SHARING_CONSENT_REQUIRED before generation. Valid receipts cover all actual AI recipients, including safety providers and intermediaries, and constrain later fallback. Content safety checks remain required for native requests. Web and legacy API behavior is unchanged. When supplied, receipts must include KIE, OpenAI, and ByteDance as the fallback provider for technical failures. |
| ai_sharing_consent.version | enum: 2026-11-12 | Yes | - |
| ai_sharing_consent.recipients | array<string> | Yes | - |
| name | string | Yes | Name of the image generation task |
| prompt | string | Yes | Text prompt (2.6 Flare/Sunburst: max 32000 chars; 2.6 Economy and 2.5: max 20000; older models: 3000 in the web form) |
| creation_mode | enum: text-to-image | image-edit | No | Optional compatibility field for history and mode reporting; callers may omit it. The server ignores any supplied value and records `image-edit` when `input_images` contains a valid HTTP(S) image URL, otherwise `text-to-image`. It is not forwarded to the model provider. |
| input_images | array<string> | No | Array of input image URLs for image-to-image editing (up to 16 images) |
| model | enum: gpt-image-1.5 | gpt-image-2 | gpt-image-2.5-flare | gpt-image-2.5-sunburst | gpt-image-2.6-flare | gpt-image-2.6-sunburst | gpt-image-2.6-economy | No | Model variant. GPT Image 2.6 offers Flare, Sunburst, and Economy; Economy supports 1K only. Version 2.6 precharges an estimated price and settles against Kie creditsConsumed after completion.; default: "gpt-image-1.5" |
| aspect_ratio | enum: auto | 1:1 | 9:16 | 21:9 | 16:9 | 4:3 | 3:2 | 3:4 | 2:3 | 27:16 | 16:27 | 9:8 | 8:9 | 5:4 | 4:5 | 2:1 | 1:2 | 9:21 | 3:1 | 1:3 | No | GPT Image 1.5 supports 1:1/3:2/2:3. Version 2.5 supports its legacy extended ratios; 2.6 Flare/Sunburst support the 16 Kie ratios including 5:4, 2:1 and 3:1. Economy supports auto/1:1/16:9/9:16/3:2/2:3/21:9/4:3.; default: "1:1" |
| quality | enum: low | medium | high | xhigh | max | auto | No | GPT Image 1.5 supports medium/high; GPT Image 2.6 Flare/Sunburst supports all listed values. Economy has fixed quality.; default: "medium" |
| output_format | enum: png | jpeg | webp | gif | svg | No | GPT Image 2.6 Flare/Sunburst supports all listed formats. Economy supports png or gif for text-to-image, png only for image-to-image.; default: "png" |
| resolution | enum: 1K | 2K | 4K | No | GPT Image 2: auto is limited to 1K; 1:1+4K is normalized to 2K. GPT Image 2.5/2.6 Flare and Sunburst legacy ratios 27:16/16:27/9:8/8:9 are normalized to 1K. GPT Image 2.6 transparent background and Economy are limited to 1K.; default: "1K" |
| save_as_png | boolean | No | Preserve the upstream image without re-encoding. GPT Image 2 defaults to false. GPT Image 2.5 defaults to true and requires preservation for auto or transparent backgrounds; opaque background allows false for JPEG. GPT Image 1.5 always uses JPEG. |
| background | enum: auto | opaque | transparent | No | GPT Image 2.5/2.6. For 2.6, transparent background supports PNG/WebP and image-edit GIF.; default: "auto" |
| force_generate | boolean | No | Force generation even if NSFW content is detected |
| minor_suspected_skip | boolean | No | Confirm retry after the suspected-minor soft block; hard blocks remain enforced.; default: false |
| webhook_url | string | No | HTTPS URL to receive task.completed / task.failed notifications. Best-effort delivery, single attempt, no retries; clients should treat the detail API as the source of truth.; maxLength: 2048 |
| webhook_token | string | No | Optional plaintext token returned in the X-A2e-Webhook-Token header so receivers can verify the request originated from a2e.; maxLength: 256 |
Request schema and conditional rules
{
"allOf": [
{
"type": "object",
"properties": {
"ai_sharing_consent": {
"type": "object",
"description": "Consent receipt for newer native apps. Legacy native requests may omit this field and continue without a consent record. If present, null, malformed, expired or incomplete receipts return AI_SHARING_CONSENT_REQUIRED before generation. Valid receipts cover all actual AI recipients, including safety providers and intermediaries, and constrain later fallback. Content safety checks remain required for native requests. Web and legacy API behavior is unchanged. When supplied, receipts must include KIE, OpenAI, and ByteDance as the fallback provider for technical failures.",
"required": [
"version",
"recipients"
],
"properties": {
"version": {
"type": "string",
"enum": [
"2026-11-12"
]
},
"recipients": {
"type": "array",
"items": {
"type": "string"
},
"example": [
"A2E",
"Alibaba Cloud",
"KIE",
"OpenAI",
"ByteDance"
]
}
}
},
"name": {
"type": "string",
"description": "Name of the image generation task"
},
"prompt": {
"type": "string",
"description": "Text prompt (2.6 Flare/Sunburst: max 32000 chars; 2.6 Economy and 2.5: max 20000; older models: 3000 in the web form)"
},
"creation_mode": {
"type": "string",
"enum": [
"text-to-image",
"image-edit"
],
"description": "Optional compatibility field for history and mode reporting; callers may omit it. The server ignores any supplied value and records `image-edit` when `input_images` contains a valid HTTP(S) image URL, otherwise `text-to-image`. It is not forwarded to the model provider."
},
"input_images": {
"type": "array",
"items": {
"type": "string"
},
"description": "Array of input image URLs for image-to-image editing (up to 16 images)"
},
"model": {
"type": "string",
"enum": [
"gpt-image-1.5",
"gpt-image-2",
"gpt-image-2.5-flare",
"gpt-image-2.5-sunburst",
"gpt-image-2.6-flare",
"gpt-image-2.6-sunburst",
"gpt-image-2.6-economy"
],
"default": "gpt-image-1.5",
"description": "Model variant. GPT Image 2.6 offers Flare, Sunburst, and Economy; Economy supports 1K only. Version 2.6 precharges an estimated price and settles against Kie creditsConsumed after completion."
},
"aspect_ratio": {
"type": "string",
"enum": [
"auto",
"1:1",
"9:16",
"21:9",
"16:9",
"4:3",
"3:2",
"3:4",
"2:3",
"27:16",
"16:27",
"9:8",
"8:9",
"5:4",
"4:5",
"2:1",
"1:2",
"9:21",
"3:1",
"1:3"
],
"default": "1:1",
"description": "GPT Image 1.5 supports 1:1/3:2/2:3. Version 2.5 supports its legacy extended ratios; 2.6 Flare/Sunburst support the 16 Kie ratios including 5:4, 2:1 and 3:1. Economy supports auto/1:1/16:9/9:16/3:2/2:3/21:9/4:3."
},
"quality": {
"type": "string",
"enum": [
"low",
"medium",
"high",
"xhigh",
"max",
"auto"
],
"default": "medium",
"description": "GPT Image 1.5 supports medium/high; GPT Image 2.6 Flare/Sunburst supports all listed values. Economy has fixed quality."
},
"output_format": {
"type": "string",
"enum": [
"png",
"jpeg",
"webp",
"gif",
"svg"
],
"default": "png",
"description": "GPT Image 2.6 Flare/Sunburst supports all listed formats. Economy supports png or gif for text-to-image, png only for image-to-image."
},
"resolution": {
"type": "string",
"enum": [
"1K",
"2K",
"4K"
],
"default": "1K",
"description": "GPT Image 2: auto is limited to 1K; 1:1+4K is normalized to 2K. GPT Image 2.5/2.6 Flare and Sunburst legacy ratios 27:16/16:27/9:8/8:9 are normalized to 1K. GPT Image 2.6 transparent background and Economy are limited to 1K."
},
"save_as_png": {
"type": "boolean",
"description": "Preserve the upstream image without re-encoding. GPT Image 2 defaults to false. GPT Image 2.5 defaults to true and requires preservation for auto or transparent backgrounds; opaque background allows false for JPEG. GPT Image 1.5 always uses JPEG."
},
"background": {
"type": "string",
"enum": [
"auto",
"opaque",
"transparent"
],
"default": "auto",
"description": "GPT Image 2.5/2.6. For 2.6, transparent background supports PNG/WebP and image-edit GIF."
},
"force_generate": {
"type": "boolean",
"description": "Force generation even if NSFW content is detected"
},
"minor_suspected_skip": {
"type": "boolean",
"default": false,
"description": "Confirm retry after the suspected-minor soft block; hard blocks remain enforced."
}
},
"required": [
"name",
"prompt"
]
},
{
"$ref": "#/components/schemas/WebhookInput"
}
]
}Response Fields
- code: enum: 0
- data: object
- data._id: string
- Task ID for detail and batch polling.
- data.name: string
- data.prompt: string
- data.is_downloaded: boolean
- data.is_previewed: boolean
- data.current_status: string
- Persisted task state; use the concrete task family schema for its allowed values and terminal states.
- data.createdAt: string
- data.updatedAt: string
- data.expirationDate: string
- data.remainingDays: number
- data.isExpired: boolean
- data.coins: number
- data.hasRefundCoin: boolean
- Whether charged credits were refunded.
- data.failed_code: string
- data.failed_message: string
- data.failed_reason: string
- Public failure category when available.
- data.creation_mode: string
- data.image_url: string
- data.image_urls: array<string>
- data.result_image_url: string
- data.result_image_urls: array<string>
- data.input_images: array<string>
- data.refund_pending: boolean
- True means refund pending resolution and takes precedence over hasRefundCoin. Explicit false is preserved; omitted when unknown, including legacy records without a stored flag.
- data.nsfw_detected: enum: true
- data.message: string
- trace_id: string
- Trace ID of this HTTP request. Include it when contacting support about this request. It is generated per request and is not a task identifier; use the returned task `_id` to query results.
Request Example
curl -X POST "https://headswap.app/api/v1/userGptImage/start" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "My Task",
"prompt": "high quality, clear, cinematic"
}'Related Endpoints
Responses
Task started successfully or NSFW content detected
Unauthorized - Invalid or missing bearer token
Content moderation rejected the `input_images`. Code `1003` means confirmed minor content. Code `1004` means suspected minor content. For `1004`, confirm the input and retry with `minor_suspected_skip: true`.