Text-to-image and image editing, compatible with the OpenAI Images API. Available models include gpt-image-2 and grok-imagine-image — billed per image.
from openai import OpenAI
client = OpenAI(base_url="https://cn.chatapi.app/v1", api_key="sk-xxxxxxxx")
resp = client.images.generate(
model="gpt-image-2",
prompt="An orange cat running through a neon city, cyberpunk style",
n=1,
size="1024x1024",
)
print(resp.data[0].url)
curl https://cn.chatapi.app/v1/images/generations \
-H "Authorization: Bearer sk-xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "An orange cat running through a neon city, cyberpunk style",
"n": 1,
"size": "1024x1024"
}'
| Parameter | Type | Notes |
|---|---|---|
model | string | Required. Image model name |
prompt | string | Required. Image description |
n | int | Number of images to generate |
size | string | Size, e.g. 1024x1024 |
Upload the source image and a prompt as multipart/form-data to edit it:
curl https://cn.chatapi.app/v1/images/edits \
-H "Authorization: Bearer sk-xxxxxxxx" \
-F model="gpt-image-2" \
-F image="@input.png" \
-F prompt="Replace the background with a seaside sunset"
Third-party unreviewed pool (NSFW allowed, minors strictly prohibited). Called through POST /v1/images/generations (edit models also accept /v1/images/edits) and returned synchronously, usually in 10–40 s. Keys routed to the Multimedia vendor, or in "all models" mode, can call them (these models exist only in the Multimedia group). Billed per image; b64_json by default, or a CDN URL (kept 7 days) with response_format=url.
| Model / mode | Price (USD/image) | Size / options |
|---|---|---|
face-swapGenerate | $0.033 | image: target image, then the face image |
head-swapGenerate | $0.026 | image: target image, then the head image |
qwen-image-2.1Generate | $0.026;2K $0.051 | resolution: 1K / 2K; aspect_ratio: 1:1 / 16:9 / 9:16 / 4:3 / 3:4 / 3:2 / 2:3 |
qwen-image-editGenerate | $0.102 | source image required |
seedream-5.0-lite-image-editImage edit | $0.077 | resolution: 2K / 3K / 4K; aspect_ratio: 1:1 / 4:3 / 3:4 / 16:9 / 9:16 / 3:2 / 2:3 / 21:9; source image required |
seedream-5.0-lite-text-to-imageText to image | $0.077 | resolution: 2K / 3K / 4K; aspect_ratio: 1:1 / 4:3 / 3:4 / 16:9 / 9:16 / 3:2 / 2:3 / 21:9 |
seedream-5.0-pro-image-editImage edit | $0.154 | aspect_ratio: 1:1 / 4:3 / 3:4 / 16:9 / 9:16 / 3:2 / 2:3 / 21:9; source image required |
seedream-5.0-pro-text-to-imageText to image | $0.154 | aspect_ratio: 1:1 / 4:3 / 3:4 / 16:9 / 9:16 / 3:2 / 2:3 / 21:9 |
z-imageGenerate | $0.033 | size WxH (e.g. 1024x1536) |
z-image-proGenerate | $0.038 | size WxH (e.g. 1024x1536) |
curl https://cn.chatapi.app/v1/images/generations \
-H "Authorization: Bearer sk-xxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"model":"seedream-5.0-lite-text-to-image","prompt":"a lighthouse at dusk, oil painting","resolution":"2K","aspect_ratio":"16:9","response_format":"url"}'
Pass public image URLs or base64 data: URIs in image (string or array); data URIs are uploaded automatically. For edit models (*-image-edit, qwen-image-edit) the first image is the source; for face / head swap the first is the target and the second is the face / head. The console's Media Workbench generates in the browser.
Image generation commonly takes 1–5 minutes upstream, and can exceed 10 minutes for high resolutions or under load. The server does not cap total request duration, so set your client timeout to at least 900 seconds (1800 recommended); otherwise your client will give up early (the job still completes and is billed).
# Python (the openai SDK defaults to 600 s, which cuts off long images)
client = OpenAI(base_url="https://apicdn.xycai.us/v1", api_key="sk-...", timeout=1800)
# Node.js (milliseconds)
const client = new OpenAI({ baseURL: "https://apicdn.xycai.us/v1", apiKey: "sk-...", timeout: 1800000 })
# curl
curl --max-time 1800 ...
When a non-streaming request has been waiting for about 45 seconds, the server sends HTTP 200 and then a space at the start of the body every few seconds to keep the connection alive; the final JSON follows the spaces. Standard JSON parsers (Python json, JS JSON.parse, official SDKs) ignore leading whitespace, so nothing needs to change; if you parse bytes yourself, trim leading whitespace first.
If such a request ultimately fails, the HTTP status is still 200 and the error is in the body's error field. Check the error field to decide success, not just the status code. For long chat tasks, prefer stream: true.
{
"created": 1748600000,
"data": [
{"url": "https://.../generated.png"}
]
}
grok-imagine-video is a video model billed per second. See the console for submission details.