Images
Generate and edit images with POST /v1/images/generations and POST /v1/images/edits. Results are returned inline as base64 and never stored.
The Images endpoints accept the familiar Images API request shape and return the generated image inline as b64_json. zrouter does not host image URLs and keeps no server-side history: prompts, source images and results exist only for the duration of the request.
Models#
| Model | Endpoint | Use |
|---|---|---|
hunyuan-image-alpha | POST /v1/images/generations | Generate an image from a prompt. |
hunyuan-image-alpha-edit | POST /v1/images/edits | Edit one image you upload, following a prompt. |
Each model supports one operation only: calling the edit model on /v1/images/generations, or the generate model on /v1/images/edits, returns 400 unsupported_endpoint. The live list and prices are in the Model Catalog; a model that is not listed returns 404 model_not_found. Image models are rejected on text endpoints and text models on image endpoints.
Generate an image#
curl --max-time 330 https://api.zrouter.dev/v1/images/generations \
-H "Authorization: Bearer $ZROUTER_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"model":"hunyuan-image-alpha","prompt":"A lighthouse at dusk, watercolor","size":"1024x1024","output_format":"png"}' \
-o response.json
jq -r '.error // empty' response.json # a failure can arrive with status 200, see below
jq -r '.data[0].b64_json' response.json | base64 --decode > image.pngEdit an image#
Send the source image as a multipart/form-data upload with the edit model. zrouter checks and re-encodes the image before it reaches the model; remote image URLs are not accepted.
curl --max-time 330 https://api.zrouter.dev/v1/images/edits \
-H "Authorization: Bearer $ZROUTER_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-F model=hunyuan-image-alpha-edit \
-F prompt="Make the sky orange" \
-F [email protected] \
-o response.json
jq -r '.data[0].b64_json' response.json | base64 --decode > edited.pngParameters#
| Field | Values | Notes |
|---|---|---|
model | image model id | Required. |
prompt | 1–32,000 characters | Required. |
n | 1 | One image per request. |
size | auto or WxH | Each edge ≤ 4096 px, total ≤ 16,777,216 px. |
quality | auto, low, medium, high | Optional. |
output_format | png, jpeg, webp | Optional, default png. |
output_compression | 0–100 | jpeg/webp only. |
background | auto, opaque, transparent | Optional. |
image | PNG, JPEG or WebP file | Edits only. Exactly one file, ≤ 10 MiB. Remote URLs are rejected. |
response_format=url, stream, partial_images and mask are not supported and return 400 unsupported_parameter. Unknown fields are rejected rather than forwarded.
Long requests#
An image can take up to 300 seconds. So that proxies do not close a quiet connection, a request that is still running after 15 seconds receives 200 with Content-Type: application/json straight away, then one space character every 15 seconds until the result is ready. The JSON follows those spaces.
- Leading whitespace is valid JSON: parse the whole body once it is complete. Do not read the first byte as the start of the object.
- A
200status is not proof of success. A request that fails after the early header ends with the usual error object{"error":{...}}under status200. Always check forerrorbefore readingdata. - Set your client timeout to at least 330 seconds (for example
curl --max-time 330, ortimeout=330in the OpenAI SDK). - Responses that finish within 15 seconds keep their real status code (for example
402or429) and the billing headers.
{"error":{"message":"Image request timed out. You were not charged.","type":"timeout_error","code":"request_timeout","param":null,"request_id":"<request id>"}}Limits#
- One active image request per account; a second concurrent request returns
429 image_concurrency_limit. - A request that is not done within 300 seconds ends with
request_timeoutand is not charged. - Generated images larger than 20 MiB are withheld (
502). - Send an
Idempotency-Keyheader to make retries safe: reusing a key never triggers a second generation or a second charge, and returns409 idempotency_key_reusedbecause results are not stored.
Billing#
These models have a fixed price per image, shown in the catalog (image_price.per_image_usd). Each delivered image is charged at that price from your PAYG balance. Token Plans do not apply to image models. Requests that fail, time out or are declined are not charged. The response has no token usage object.
When the response finishes within 15 seconds it carries x-zrouter-billing: settled and the charge in x-zrouter-payg-debit-usd. When the early header was already sent (requests longer than 15 seconds), those billing headers are not present: the charge is still recorded and appears in Usage in the dashboard and in the Usage API.
Image-specific errors#
| Status | Code | Meaning |
|---|---|---|
| 400 | content_policy_violation | The model declined the prompt or image. Not charged. |
| 400 | unsupported_parameter | A field outside the supported set was sent. |
| 400 | unsupported_endpoint | The model does not support this image operation. |
| 402 | insufficient_balance | Your PAYG balance is too low for this image. |
| 200 | request_timeout | The image was not ready within 300 seconds. Not charged. Arrives in the body after the early header (see Long requests). |
| 409 | idempotency_key_reused | This Idempotency-Key was already used. |
| 413 | image_too_large | The source image exceeds the size or pixel limits. |
| 429 | image_concurrency_limit | Another image request from your account is still running. |