Image generation and editing
OpenAI-compatible text-to-image, image edit, and image variation endpoints, callable with API Keys.
Generation, editing, and variations all use Authorization: Bearer sk-tp-... and share the same Key authentication, rate limiting, and billing pipeline as chat completions.
Image generation
- Auth:
Authorization: Bearer sk-tp-... - Content-Type:
application/json
Request body
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Platform image model name, see Models |
| prompt | string | Yes | Image description prompt |
| n | number | No | Number of images, defaults to 1 |
| size | string | No | Image size, e.g. 1024x1024; allowed values depend on the model |
| response_format | string | No | url (default) or b64_json |
| Other params | - | No | Passed through per the OpenAI protocol and model support |
Response
OpenAI Images JSON: a data array where each item contains url or b64_json. The url is provided by the upstream provider and is usually valid for 24 hours; download and store it promptly.
Image edits
- Auth:
Authorization: Bearer sk-tp-... - Content-Type:
multipart/form-data
| Field | Type | Required | Description |
|---|---|---|---|
| image | file | Yes | Source image; repeat the image field to send multiple images, support depends on the model |
| mask | file | No | Mask image; transparent areas are edited |
| model | string | Yes | Platform image model name |
| prompt | string | Yes | Edit description |
| n | number | No | Number of images, defaults to 1 |
| size | string | No | Output size |
| response_format | string | No | url (default) or b64_json |
Image variations
- Content-Type:
multipart/form-data imageis required (single file);model,n,size, andresponse_formatare optional- Response and billing match image generation
Direct reference-image upload (optional)
Get a presigned URL, upload the file straight to object storage, then use the returned url as a request parameter.
- Auth:
Authorization: Bearer sk-tp-... - Content-Type:
application/json - Body:
{ "filename": "ref.png", "size": 102400 }(PNG/JPG/WEBP/GIF only, max 10MB) - Response:
{ key, url, uploadUrl, headers, expiresIn }
Send the file with PUT to uploadUrl and include the Content-Type from headers; then use url.
Billing
- Generation, edits, and variations are billed per returned image at "yuan per image"; the model must use per-call pricing.
- Responses include
X-Cost-Yuan(cost) andX-Bill-Units(image count) headers.
Pre-checks
- Key valid and not revoked (including all parents), account active → otherwise
401 - Model exists and is live (
LIVE), priced per call with a unit price → otherwise400 - Edit/variation request missing an
imagefile → otherwise400 - Balance above zero and Key chain quota not exhausted → otherwise
402
Errors
For error format and troubleshooting see FAQ · Error codes. Upstream errors are passed through unchanged; if the model or channel does not support edits/variations, the upstream error is returned to the caller.