## Overview

Hunyuan Image Generation is a series of image generation models launched by Tencent Hunyuan. This document describes how to call the Hunyuan image generation model Hy-Image-3.0 (`hy-image-v3`) through TokenHub: generate images synchronously from text prompts, with support for custom dimensions, generation seeds, automatic prompt rewriting, and image watermark footnotes.

> **Note:**
> 
> This API uses **synchronous calls**: a single request directly returns the generated result, without the need to submit tasks or poll.
> 

### Prerequisites
- You have [registered a Tencent Cloud](https://www.tencentcloud.com/document/product/378/17985) account and activated the TokenHub service.

- You have obtained an API Key from the [TokenHub console](https://console.tencentcloud.com/tokenhub/apikey).

- Enable postpaid billing for the corresponding model in [Console - Online Inference - Vision Models](https://console.tencentcloud.com/tokenhub/inference?serviceType=VISION).

   > **Note:**
   > 
   > In all examples below, replace YOUR_API_KEY with your own API Key. The authentication method is the request header Authorization: Bearer YOUR_API_KEY.
   > 

### Model list

|Model Name|model Parameter Value|Supported Capability|Prompt Limit|Size Range|Brief Description|
|---------|---------|---------|---------|---------|---------|
|Hy-Image-3.0|`hy-image-v3`|Text-to-image/reference-based image generation (synchronous)|8192 characters|Width and height [512, 2048], area ≤ 1024×1024|Supports automatic prompt rewriting, 37 preset sizes, and custom watermark footnotes.|
|Hy-Image-3.5-Preview|`hy-image-v3.5-preview`|Text-to-image/reference-based image generation/multi-turn editing (synchronous)|100k tokens|Width and height ∈ [256, 8192], area ≤ 16777216 (4K, 4096×4096)|Uses the Chat/Messages protocol, supports multimodal input, multi-turn editing context, external search enhancement, automatic size determination by area tier, and up to 4K output.|

## Hy-Image-3.0 Image Generation

### 1. API Description

Enter a text prompt to generate an image synchronously. If `size` is not passed and a size or aspect ratio is specified in the prompt, the model selects the closest match from 37 preset combinations. If neither is specified, the model predicts automatically. For details, see [Appendix: Hy-Image-3.0 Preset Size List](https://www.tencentcloud.com/document/product/1300/83708#hy-image-3.0-.E9.A2.84.E8.AE.BE.E5.B0.BA.E5.AF.B8.E5.88.97.E8.A1.A8).

**API:** `POST https://tokenhub-intl.tencentcloudmaas.com/v1/wand/hunyuan-image/v3-generation`

### 2. Input Parameters
<table>
<tr>
<td rowspan="1" colspan="1" >Parameter Name</td>

<td rowspan="1" colspan="1" >Required</td>

<td rowspan="1" colspan="1" >Type</td>

<td rowspan="1" colspan="1" >Description</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >model</td>

<td rowspan="1" colspan="1" >Yes</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Model ID. Value: <code>hy-image-v3</code></td>
</tr>

<tr>
<td rowspan="1" colspan="1" >prompt</td>

<td rowspan="1" colspan="1" >Yes</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Text used for image generation, with a length of up to 8192 characters.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >images</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >array[string]</td>

<td rowspan="1" colspan="1" >Reference images, 0 to 3. Supports image URLs or Base64.<br>Format: png / jpeg / jpg. Size per image: ≤ 10 MB.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >size</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Generated size, format: <code>${width}x${height}</code>.<br>Constraints: ① Width and height are both within the range of [512, 2048] pixels; ② The product of width and height (image area) does not exceed 1024×1024 pixels.<br>If not specified, the model selects/predicts from 37 preset combinations. For details, see <a href="https://www.tencentcloud.com/document/product/1300/83708#hy-image-3.0-.E9.A2.84.E8.AE.BE.E5.B0.BA.E5.AF.B8.E5.88.97.E8.A1.A8">Appendix: Hy-Image-3.0 Preset Size List</a>.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >seed</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >integer</td>

<td rowspan="1" colspan="1" >Generation seed, range: [1, 4294967295]. Takes effect only when the number of generated images is 1. If not specified or set to 0, a random seed is used by default.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >footnote</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Custom watermark content, limited to 16 characters (regardless of Chinese or English), generated in the lower right corner of the image.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >revise</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >boolean</td>

<td rowspan="1" colspan="1" >Whether to rewrite the prompt.</td>
</tr>
</table>

### 3. Sample Request
``` bash
# Text-to-Image
curl -X POST 'https://tokenhub-intl.tencentcloudmaas.com/v1/wand/hunyuan-image/v3-generation' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "hy-image-v3",
  "prompt": "An orange kitten on the windowsill looks toward the camera",
  "size": "1024x1024"
}'
```

### 4. Output Parameters

|Parameter Name|Type|Description|
|---------|---------|---------|
|id|string|id of this request.|
|created|integer|Unix timestamp.|
|data|list|Array of returned image generation content.|
|data[n].url|string|The generated image URL is temporary and valid for 12 hours. Download and save it promptly.|
|data[n].revised_prompt|string|The revised prompt, returned only when revise is enabled.|
|request_id|string|Unique request identifier used for troubleshooting.|
|tokenhub_usage|object|Token usage consumption.|
|tokenhub_usage.total_tokens|integer|Number of tokens consumed by this task, used for billing/reconciliation.|

### 5. Sample Response
``` json
{
  "id": "4-WandImage-a786becfdc80433b8cff4aa344c8fd3d",
  "created": 1785125529,
  "data": [
    {
      "url": "https://aigc-image.cos.myqcloud.com/xxx/result.png",
      "revised_prompt": "An orange kitten sits on a sun-drenched windowsill, turns to look at the camera, with detailed fur and a blurred background"
    }
  ],
  "request_id": "3aec3299-06ad-4654-8b45-c57b823a15d2",
  "tokenhub_usage": {
    "total_tokens": 1024
  }
}
```

The returned url is a temporary address valid for 12 hours. Because the address requires authentication, accessing it directly through the browser address bar may be rejected. We recommend downloading it in one of the following ways:
``` bash
curl -o generated_image.png 'https://aigc-image.cos.myqcloud.com/xxx/result.png'
```

Or use an HTTP client in your code to download and save it to local storage.

### 6. Error Codes

|HTTP Status Code|Description|Handling Recommendation|
|---------|---------|---------|
|400|The request format is incorrect.|Check the field types/values in the request body (such as size constraints, prompt length, and model name).|
|401|Authentication failed.|Check whether the API_KEY is valid and whether Authorization uses the Bearer format.|
|422|Input or output moderation failed (blocked by content safety).|Input or output triggers content safety moderation. Adjust the prompt or business policy.|
|429|The number of concurrent requests exceeds the limit.|The concurrency limit is reached. Retry with backoff and control the concurrency of calls.|
|500|Internal error.|A server exception occurs. Retry the request. If failures persist, contact technical support and provide the request_id.|

## Hy-Image-3.5-Preview Image Generation (Text-to-Image / Image-to-Image / Multi-Round Editing)

### 1. API Description

Input one or more rounds of context (text + optional reference images) using the Chat/Messages protocol to generate images synchronously. If `size` is not passed, the model determines the final width and height based on the prompt semantics and the `generate_max_pixels` area tier. If `size` is passed, the image is generated at the specified size, with a maximum supported resolution of 4096×4096 (4K).

**API:** `POST https://tokenhub-intl.tencentcloudmaas.com/v1/wand/hunyuan-image/v35-generation`

### 2. Input Parameters

#### 2.1 Top-Level Parameters
<table>
<tr>
<td rowspan="1" colspan="1" >Parameter Name</td>

<td rowspan="1" colspan="1" >Required</td>

<td rowspan="1" colspan="1" >Type</td>

<td rowspan="1" colspan="1" >Description</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >model</td>

<td rowspan="1" colspan="1" >Yes</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Model ID. Value: <code>hy-image-v3.5-preview</code></td>
</tr>

<tr>
<td rowspan="1" colspan="1" >messages</td>

<td rowspan="1" colspan="1" >Yes</td>

<td rowspan="1" colspan="1" >array[object]</td>

<td rowspan="1" colspan="1" >Content of multiple conversation turns, arranged in chronological order from oldest to newest.<br>The server takes the last message with <code>role=user</code> in the array as the current image generation instruction, and passes through the remaining objects as historical context for multi-turn editing. For element structure, see section 2.2 messages element structure.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >size</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Generated size, format: <code>${width}x${height}</code>.<br>Constraints:<br>1. Both width and height are positive integers, with a value range of [256, 8192].<br>2.  The width × height (area) must not exceed 16777216, which means the maximum supported resolution is 4096×4096 (4K).<br>If this parameter is not passed or an empty string is passed, the model determines the size based on the prompt semantics and <code>generate_max_pixels</code>. If a specific value is passed, the image is generated at the specified size. To generate a 4K output, directly pass <code>"size": "4096x4096"</code>.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >seed</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >integer</td>

<td rowspan="1" colspan="1" >Generation seed, int64 type, range: [0, 2^63-1]. If set to 0 or not specified, the server assigns a random value. Negative values are rejected.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >generate_max_pixels</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >integer</td>

<td rowspan="1" colspan="1" >Specifies the target area of the generated image in pixels. Takes effect only when <code>size</code> is not passed.<br>Supports 3 enumeration levels: <code>1048576</code> (1K, 1024×1024), <code>2359296</code> (1.5K, default), and <code>4194304</code> (2K). If a non-enumeration intermediate value is passed, it is classified to the nearest area level.<br>Note: The highest level of this parameter is 2K. To achieve a higher resolution, use <code>size</code> instead.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >resize_max_pixels</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >integer</td>

<td rowspan="1" colspan="1" >Maximum area of the input reference image in pixels. If the original image area is less than or equal to the threshold, the image is passed through as is. If the original image area is greater than the threshold, the image is proportionally scaled to approximately the threshold before being fed into the model, to control context token consumption caused by large images (4K/6K).<br>If not specified, the default value is <code>1048576</code> (1024×1024).</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >session</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Session ID, used for consistent hash scheduling in inference services. Multiple requests within the same session are routed to the same inference instance, improving the KV-cache hit rate. For multi-turn conversations, keep the same session value throughout the entire session.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >footnote</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Custom watermark content, up to 16 characters (calculated by utf8.RuneCount, regardless of Chinese or English), generated in the lower right corner of the image.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >use_search_tool</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >object</td>

<td rowspan="1" colspan="1" >External search enhancement switch. The structure is fixed as <code>{"value": true}</code> or <code>{"value": false}</code>. Disabled by default.</td>
</tr>
</table>

#### 2.2 Structure of the messages Element

The structure of each element in messages[n] is as follows:
<table>
<tr>
<td rowspan="1" colspan="1" >Parameter Name</td>

<td rowspan="1" colspan="1" >Required</td>

<td rowspan="1" colspan="1" >Type</td>

<td rowspan="1" colspan="1" >Description</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >role</td>

<td rowspan="1" colspan="1" >Yes</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Role. Supported values: <code>user</code> / <code>assistant</code> / <code>tool</code>.<br>The tool role appears only when feeding the previous image generation result back as the context for the next round.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >content</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >array[object]</td>

<td rowspan="1" colspan="1" >The specific content of this round. For the element structure, see section 2.3 "content Element Structure".<br><code>assistant</code> can be omitted when only triggering tool calls without sending text.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >reasoning</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Used only for multi-round backfeeding when <code>role=assistant</code>. Passes through the original chain-of-thought text from the previous response.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >tool_calls</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >array</td>

<td rowspan="1" colspan="1" >Used only for multi-round backfeeding when <code>role=assistant</code>. The element structure follows the standard OpenAI tool_call: <code>{id, type:"function", function:{name, arguments}}</code>, where <code>arguments</code> is a JSON string.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >tool_call_id</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Used only for multi-round backfeeding when <code>role=tool</code>. Must match the previous <code>assistant.tool_calls[i].id</code> character by character.</td>
</tr>
</table>

#### 2.3 Structure of the content Element

The structure of each element in messages[n].content[m] is as follows:
<table>
<tr>
<td rowspan="1" colspan="1" >Parameter Name</td>

<td rowspan="1" colspan="1" >Required</td>

<td rowspan="1" colspan="1" >Type</td>

<td rowspan="1" colspan="1" >Description</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >type</td>

<td rowspan="1" colspan="1" >Yes</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Content type, <code>text</code> or <code>image_url</code>.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >text</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Used when <code>type=text</code>, indicating specific text.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >image_url</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >object</td>

<td rowspan="1" colspan="1" >Used when <code>type=image_url</code>, with the structure <code>{"url": "..."}</code>.<br>Supports http(s) public network URLs or <code>data:image/...;base64,...</code> format. Size per image: ≤ 20 MB. Total number of images: ≤ 20. If the limit is exceeded, the server automatically truncates by round from farthest to nearest.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >is_generate</td>

<td rowspan="1" colspan="1" >No</td>

<td rowspan="1" colspan="1" >bool</td>

<td rowspan="1" colspan="1" >Fill in <code>true</code> only when feeding the generated image content back with <code>role=tool</code>, marking it as the image produced by the generate tool in the previous round. Do not pass this parameter in other scenarios.</td>
</tr>
</table>

### 3. Sample Request

**Single-Round Text-to-Image (4K Output)**
``` bash
# Text-to-Image
curl -X POST 'https://tokenhub-intl.tencentcloudmaas.com/v1/wand/hunyuan-image/v35-generation' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "hy-image-v3.5-preview",
  "size": "4096x4096",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "Draw a golden retriever running on the beach in warm evening light" }
      ]
    }
  ]
}'
```

**Single-Round Reference-Based Image Generation (Text + Reference Image)**
``` bash
# Reference-Based Image Generation
curl -X POST 'https://tokenhub-intl.tencentcloudmaas.com/v1/wand/hunyuan-image/v35-generation' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "hy-image-v3.5-preview",
  "session": "demo-session-001",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "Draw a cat in the style of this image" },
        { "type": "image_url", "image_url": { "url": "https://your-domain/dog.png" } }
      ]
    }
  ]
}'
```

**Multi-Round Editing** (Append the three messages from `assembled_history` in the previous response as-is).
``` json
{
  "model": "hy-image-v3.5-preview",
  "session": "demo-session-001",
  "messages": [
    { "role": "user", "content": [
        { "type": "text", "text": "Draw a cat in the style of this image" },
        { "type": "image_url", "image_url": { "url": "https://your-domain/dog.png" } }
    ]},
    {
      "role": "assistant",
      "content": [{ "type": "text", "text": "I will use the generation tool to create the image as required." }],
      "reasoning": "The user wants to draw a cat in the style of the dog...",
      "tool_calls": [{
        "id": "generate@call_0",
        "type": "function",
        "function": { "name": "generate", "arguments": "{\"recaption\":\"a cat in similar style...\"}" }
      }]
    },
    {
      "role": "tool",
      "tool_call_id": "generate@call_0",
      "content": [
        { "type": "image_url", "image_url": { "url": "http://hunyuan-image-result-tob-1258344703.cos.ap-guangzhou.myqcloud.com/xxx/cat.png" } }
      ]
    },
    {
      "role": "assistant",
      "content": [{ "type": "text", "text": "The image you requested has been completed." }]
    },
    { "role": "user", "content": [
        { "type": "text", "text": "Change the cat to a Ragdoll and the background to a fireplace" }
    ]}
  ]
}
```

### 4. Output Parameters
<table>
<tr>
<td rowspan="1" colspan="1" >Parameter Name</td>

<td rowspan="1" colspan="1" >Type</td>

<td rowspan="1" colspan="1" >Description</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >id</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Trace ID of this request, unique within the entire stream.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >object</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Fixed <code>image.chat.completion.chunk</code>.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >created</td>

<td rowspan="1" colspan="1" >integer</td>

<td rowspan="1" colspan="1" >Unix timestamp in seconds.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >model</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Internal version identifier returned by the actual upstream service (for example, <code>HY-Image-3.5-Preview-4090-Tob-vX.Y</code>). It changes with upstream releases and is not equivalent to <code>hy-image-v3.5-preview</code> passed in the request body. It is for reference only, and clients are not advised to use this field for business branch decisions.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >round</td>

<td rowspan="1" colspan="1" >integer</td>

<td rowspan="1" colspan="1" >LLM round to which this frame belongs, counted from 0.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >choices</td>

<td rowspan="1" colspan="1" >list</td>

<td rowspan="1" colspan="1" >Fixed length of 1.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >choices[0].delta</td>

<td rowspan="1" colspan="1" >object</td>

<td rowspan="1" colspan="1" >Main image carrier, with the structure <code>{"type":"image", "image":{"url":"...", "width":..., "height":..., "source":"generate", "tool_call_id":"generate@call_0"}}</code>.<br><code>choices[0].delta.image.url</code> <strong>is the final delivery URL of this image generation, and clients should read this field first.</strong></td>
</tr>

<tr>
<td rowspan="1" colspan="1" >choices[0].finish_reason</td>

<td rowspan="1" colspan="1" >string \| null</td>

<td rowspan="1" colspan="1" >In a successful final frame, it is often <code>null</code> (the upstream service sends the image as the last delta frame and then closes the stream directly without sending an additional completion frame). Only in cases of content security interception / business errors will it be a non-null value such as <code>error</code>.<br>To determine whether the request is successful, the business side is advised to check whether <code>choices[0].delta.image.url</code> exists, rather than <code>finish_reason</code>.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >usage.total_tokens</td>

<td rowspan="1" colspan="1" >integer</td>

<td rowspan="1" colspan="1" >Total number of tokens consumed by this task (based on the upstream service; v3.5 currently does not split prompt/completion).</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >tokenhub_usage.total_tokens</td>

<td rowspan="1" colspan="1" >integer</td>

<td rowspan="1" colspan="1" >token consumption used for billing/reconciliation on the TokenHub gateway side, generally consistent with <code>usage.total_tokens</code>.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >request_id</td>

<td rowspan="1" colspan="1" >string</td>

<td rowspan="1" colspan="1" >Unique request identifier used for troubleshooting.</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >assembled_history</td>

<td rowspan="1" colspan="1" >list</td>

<td rowspan="1" colspan="1" >Message sequence assembled by the server for the next round of context injection, with a structure identical to the <code>messages</code> element in the request body, typically consisting of 3 objects:<br>1. <code>role=assistant</code> (contains <code>reasoning</code> + <code>tool_calls</code>, describing the reasoning and tool calls for this round)<br>2. <code>role=tool</code> (contains the intermediate URL of the image generated by the tool, with <code>tool_call_id</code> consistent with ①)<br>3. <code>role=assistant</code> (contains only closing text, such as "The image you requested is complete.")<br><strong>For multi-turn editing, directly append the array as is to the next round of</strong> <code>messages</code><strong>.</strong></td>
</tr>

<tr>
<td rowspan="1" colspan="1" >error</td>

<td rowspan="1" colspan="1" >object</td>

<td rowspan="1" colspan="1" >Only carried in failed final frames, in OpenAI style <code>{type, code, message, request_id}</code>.</td>
</tr>
</table>

> **Note:**
> 
> **Difference between the two image URLs:**
> 
> - `choices[0].delta.image.url`: **Final delivered image URL** (hosted at `aigc-output-image-file-*.cos.ap-guangzhou.myqcloud.com`), which already includes watermarking/post-processing. We recommend that your business read this field first as the final image.
> - `assembled_history[].content[].image_url.url` (role=tool): **Intermediate artifact URL** (hosted at `hunyuan-image-result-tob-*.cos.ap-guangzhou.myqcloud.com`), which provides reusable historical context for the next round of multi-round editing. It must be appended during multi-round editing.
> Both are temporary signed URLs with a default validity period of 12 hours. Download and store them promptly.
> 

### 5. Sample Response

Success response:
``` json
{
  "id": "1374200352-WandImage-085edfe2367d4a688f68e813af3665a5",
  "object": "image.chat.completion.chunk",
  "created": 1789720599,
  "model": "HY-Image-3.5-Preview-4090-Tob-v1.2",
  "round": 0,
  "choices": [
    {
      "index": 0,
      "delta": {
        "type": "image",
        "image": {
          "url": "https://aigc-output-image-file-1326893053.cos.ap-guangzhou.myqcloud.com/xxx/main.png?...",
          "width": 4096,
          "height": 4096,
          "source": "generate",
          "tool_call_id": "generate@call_0"
        }
      },
      "finish_reason": null
    }
  ],
  "usage": { "total_tokens": 20000 },
  "tokenhub_usage": { "total_tokens": 20000 },
  "request_id": "a1c00d07-041b-4daa-bae0-b7eabf2bc33a",
  "assembled_history": [
    {
      "role": "assistant",
      "content": [{ "type": "text", "text": "I will use the generation tool to create the image as required." }],
      "reasoning": "The user instruction is \"dance\", which needs to be concretized into a specific visual representation...",
      "tool_calls": [
        {
          "id": "generate@call_0",
          "type": "function",
          "function": {
            "name": "generate",
            "arguments": "{\"recaption\":\"...\",\"image_width\":\"855\",\"image_height\":\"1226\",\"source_image_indices_list\":\"[\\\"rdnd\\\"]\"}"
          }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "generate@call_0",
      "content": [
        {
          "type": "image_url",
          "image_url": {
            "url": "http://hunyuan-image-result-tob-1258344703.cos.ap-guangzhou.myqcloud.com/text2image2/strategy/upload/xxx.png?..."
          }
        }
      ]
    },
    {
      "role": "assistant",
      "content": [{ "type": "text", "text": "The image you requested has been completed." }]
    }
  ]
}
```

Failure response (for example, content moderation interception):
``` json
{
  "id": "abc123",
  "object": "image.chat.completion.chunk",
  "created": 1785125530,
  "model": "HY-Image-3.5-Preview-4090-Tob-v1.2",
  "round": 0,
  "choices": [
    { "index": 0, "delta": {}, "finish_reason": "error" }
  ],
  "error": {
    "type": "invalid_request_error",
    "code": "content_filter",
    "message": "input moderation rejected",
    "request_id": "xxxxxxxx"
  }
}
```

The returned url is a temporary address valid for 12 hours. Because the address requires authentication, accessing it directly through the browser address bar may be rejected. We recommend downloading it in one of the following ways:
``` bash
curl -o generated_image.png 'https://aigc-output-image-file-1326893053.cos.ap-guangzhou.myqcloud.com/xxx/main.png?...'
```

Or use an HTTP client in your code to download and save it to local storage.

### 6. Error Codes

|HTTP Status Code|Description|Handling Recommendation|
|---------|---------|---------|
|400|The request format is incorrect.|Check the field types/values in the request body, such as size constraints, message structure, and model name.|
|401|Authentication failed.|Check whether the API_KEY is valid and whether Authorization uses the Bearer format.|
|422|Input or output moderation failed (blocked by content safety).|Input or output triggers content safety moderation. Adjust the prompt or business policy.|
|429|The number of concurrent requests exceeds the limit.|The concurrency limit is reached. Retry with backoff and control the concurrency of calls.|
|500|Internal error.|A server exception occurs. Retry the request. If failures persist, contact technical support and provide the request_id.|

## Appendix

### List of Preset Sizes for Hy-Image-3.0

If size is not passed, the model selects/predicts from the following 37 combinations. If size is passed, it must satisfy the constraints (width and height within the range of 512 to 2048, and the product less than or equal to 1024×1024). The format is "width x height":
<table>
<tr>
<td rowspan="1" colspan="1" >2048 x 512</td>

<td rowspan="1" colspan="1" >1984 x 512</td>

<td rowspan="1" colspan="1" >1920 x 512</td>

<td rowspan="1" colspan="1" >1856 x 512</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >1792 x 512</td>

<td rowspan="1" colspan="1" >1728 x 512</td>

<td rowspan="1" colspan="1" >1664 x 512</td>

<td rowspan="1" colspan="1" >1600 x 512</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >1536 x 512</td>

<td rowspan="1" colspan="1" >1472 x 576</td>

<td rowspan="1" colspan="1" >1408 x 640</td>

<td rowspan="1" colspan="1" >1344 x 704</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >1280 x 768</td>

<td rowspan="1" colspan="1" >1216 x 832</td>

<td rowspan="1" colspan="1" >1152 x 896</td>

<td rowspan="1" colspan="1" >1088 x 960</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >1024 x 1024</td>

<td rowspan="1" colspan="1" >960 x 1088</td>

<td rowspan="1" colspan="1" >896 x 1152</td>

<td rowspan="1" colspan="1" >832 x 1216</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >768 x 1280</td>

<td rowspan="1" colspan="1" >704 x 1344</td>

<td rowspan="1" colspan="1" >640 x 1408</td>

<td rowspan="1" colspan="1" >576 x 1472</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >512 x 1536</td>

<td rowspan="1" colspan="1" >512 x 1600</td>

<td rowspan="1" colspan="1" >512 x 1664</td>

<td rowspan="1" colspan="1" >512 x 1728</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >512 x 1792</td>

<td rowspan="1" colspan="1" >512 x 1856</td>

<td rowspan="1" colspan="1" >512 x 1920</td>

<td rowspan="1" colspan="1" >512 x 1984</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >512 x 2048</td>

<td rowspan="1" colspan="1" >768 x 1024</td>

<td rowspan="1" colspan="1" >720 x 1280</td>

<td rowspan="1" colspan="1" >1024 x 768</td>
</tr>

<tr>
<td rowspan="1" colspan="1" >1280 x 720</td>

<td rowspan="1" colspan="1" >-</td>

<td rowspan="1" colspan="1" >-</td>

<td rowspan="1" colspan="1" >-</td>
</tr>
</table>

### Reference Image Input Constraints

|Model|Supported Format|Single Image Size|Quantity|
|---------|---------|---------|---------|
|Hy-Image-3.0|png / jpeg / jpg, supports image URLs or Base64|≤ 10MB|0 to 3 images|
|Hy-Image-3.5-Preview|png / jpeg / jpg, supports image URLs or Base64|≤ 20MB|≤ Up to 20 images|

We recommend using a direct CDN link without authentication. If the domain is on a private network or requires authentication, contact the TokenHub team to add it to the allowlist.

## FAQs

#### **1. How to Choose Between the Two Models?**

Hy-Image-3.0 is a classic text-to-image API with a simple request body (prompt + size), suitable for single-round batch image generation and cost-sensitive integration scenarios. Hy-Image-3.5-Preview uses the Chat/Messages protocol and supports multi-image input, multi-round editing context, and chain-of-thought rewriting, delivering stronger text rendering, realism, and editing consistency. It supports up to 4K output, making it suitable for professional visual production scenarios such as posters, UI design, and product image editing.

#### **2. How to Generate 4K Images?**

Only Hy-Image-3.5-Preview supports this. Simply pass `"size": "4096x4096"`. The width and height must be within the range of 256 to 8192, and the area must not exceed 16777216. Other 4K-level aspect ratios (such as `"5461x3072"`) are also supported as long as they satisfy the area constraint. Note that the highest tier of `generate_max_pixels` is 2K (`4194304`), so to generate 4K output, you must use the `size` parameter.

#### **3. How to Use size / generate_max_pixels Together? (Hy-Image-3.5-Preview)**
- **Pass only** `size`: forces image generation at the exact width and height, overriding the model's autonomous decision. Use this method for 4K scenarios.

- `size` **+** `generate_max_pixels`: The final width and height are calculated by internal logic, which aims to stay as close as possible to the aspect ratio of `size` and the area tier of `generate_max_pixels`, selecting the optimal dimensions for model performance.

- **Pass only** `generate_max_pixels`: The default aspect ratio is 1:1, and the area is assigned to one of the 1K, 1.5K, or 2K tiers.

- **Pass neither**: The model decides autonomously based on the prompt semantics (defaulting to the 1.5K tier).

#### **4. How to Pass the size Parameter for Hy-Image-3.0?**

The format is `${width}x${height}` (for example, `1024x1024`). Both width and height must be within the range of 512 to 2048, and the area must not exceed 1024×1024. We recommend using the combinations in the appendix: Hy-Image-3.0 Preset Size List. If not passed, you can describe the aspect ratio in the prompt (for example, "landscape 16:9"), and the model will automatically select the closest preset size.

#### **5. When Does seed Take Effect? How to Reproduce?**

Hy-Image-3.0: The value range is [1, 4294967295]. It takes effect only when the number of generated images is 1. If not passed or set to 0, a random seed is used.

Hy-Image-3.5-Preview: The value range is [0, 2^63-1]. If set to 0 or not passed, the server randomly assigns a seed. Negative values will be rejected. To reproduce the same result, fix the seed + prompt + size.

#### **6. Should revise (prompt Rewriting) Be Disabled? (Hy-Image-3.0)**

When rewriting is enabled, the model automatically rewrites and optimizes the prompt to improve image generation quality, which takes about 11 seconds. We recommend disabling this feature only if you have already implemented your own prompt rewriting logic. Otherwise, image generation quality may be significantly affected.

#### **7. How to Assemble Context for Multi-Turn Editing? (Hy-Image-3.5-Preview)**

The `messages` in the (N+1)-th request = the `messages` from the N-th round (including the first user message) + the `assembled_history` from the N-th round response (typically three messages: assistant + tool + assistant) + the new user message for the current round. You do not need to aggregate SSE deltas yourself or assemble multi-level nested JSON, as the server has already prepared a ready-to-use object in `assembled_history`. For reference, see the concatenation format of the assistant / tool / assistant messages in the "Multi-Round Editing" request example above.

#### **8. Do Generated Image Links Expire?**

They will expire. The generated results from both models are temporary URLs with a validity period of 12 hours. Download and save them promptly after successful generation: For Hy-Image-3.0, use `data[n].url`. For Hy-Image-3.5-Preview, use `choices[0].delta.image.url` (the final delivered image for business use). If you need to retain historical context for the next round of editing, you can also save `assembled_history[].content[].image_url.url` (the intermediate product). All URLs are temporary signed URLs, so do not rely on them long-term.

