Image Generation

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.

Text-to-Image

POST https://cn.chatapi.app/v1/images/generations
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"
  }'

Request Parameters

ParameterTypeNotes
modelstringRequired. Image model name
promptstringRequired. Image description
nintNumber of images to generate
sizestringSize, e.g. 1024x1024

Image Editing

POST https://cn.chatapi.app/v1/images/edits

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"

Multimedia image models (unreviewed)

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 / modePrice (USD/image)Size / options
face-swap
Generate
$0.033image: target image, then the face image
head-swap
Generate
$0.026image: target image, then the head image
qwen-image-2.1
Generate
$0.026;2K $0.051resolution: 1K / 2K; aspect_ratio: 1:1 / 16:9 / 9:16 / 4:3 / 3:4 / 3:2 / 2:3
qwen-image-edit
Generate
$0.102source image required
seedream-5.0-lite-image-edit
Image edit
$0.077resolution: 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-image
Text to image
$0.077resolution: 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-edit
Image edit
$0.154aspect_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-image
Text to image
$0.154aspect_ratio: 1:1 / 4:3 / 3:4 / 16:9 / 9:16 / 3:2 / 2:3 / 21:9
z-image
Generate
$0.033size WxH (e.g. 1024x1536)
z-image-pro
Generate
$0.038size 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"}'
Reference / source images

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.

Timeouts for long-running requests

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 ...
Keep-alive whitespace while waiting

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.

Response Structure

{
  "created": 1748600000,
  "data": [
    {"url": "https://.../generated.png"}
  ]
}
Video Generation

grok-imagine-video is a video model billed per second. See the console for submission details.

All docs