Skip to contentFREE until Nov 30 · hy4-flash:free · $0 for every account · Try it →
API v1Updated 2026-11-14

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#

ModelEndpointUse
hunyuan-image-alphaPOST /v1/images/generationsGenerate an image from a prompt.
hunyuan-image-alpha-editPOST /v1/images/editsEdit 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#

POST /v1/images/generations
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.png

Edit 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.

POST /v1/images/edits
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.png

Parameters#

FieldValuesNotes
modelimage model idRequired.
prompt1–32,000 charactersRequired.
n1One image per request.
sizeauto or WxHEach edge ≤ 4096 px, total ≤ 16,777,216 px.
qualityauto, low, medium, highOptional.
output_formatpng, jpeg, webpOptional, default png.
output_compression0–100jpeg/webp only.
backgroundauto, opaque, transparentOptional.
imagePNG, JPEG or WebP fileEdits 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 200 status is not proof of success. A request that fails after the early header ends with the usual error object {"error":{...}} under status 200. Always check for error before reading data.
  • Set your client timeout to at least 330 seconds (for example curl --max-time 330, or timeout=330 in the OpenAI SDK).
  • Responses that finish within 15 seconds keep their real status code (for example 402 or 429) and the billing headers.
Failure after the early header (status 200)
      {"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_timeout and is not charged.
  • Generated images larger than 20 MiB are withheld (502).
  • Send an Idempotency-Key header to make retries safe: reusing a key never triggers a second generation or a second charge, and returns 409 idempotency_key_reused because 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#

StatusCodeMeaning
400content_policy_violationThe model declined the prompt or image. Not charged.
400unsupported_parameterA field outside the supported set was sent.
400unsupported_endpointThe model does not support this image operation.
402insufficient_balanceYour PAYG balance is too low for this image.
200request_timeoutThe image was not ready within 300 seconds. Not charged. Arrives in the body after the early header (see Long requests).
409idempotency_key_reusedThis Idempotency-Key was already used.
413image_too_largeThe source image exceeds the size or pixel limits.
429image_concurrency_limitAnother image request from your account is still running.