> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apiyi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 텍스트-이미지 API 레퍼런스

> Tencent Hunyuan Hy-Image 3.5 Preview 텍스트-이미지 API 레퍼런스 및 플레이그라운드 — hy-image-v3.5-preview-2k / -4k, 2048/4096 고정 출력, 기본값은 b64_json이며 선택적으로 CDN URL 지원

> [!NOTE]
>
> 오른쪽의 대화형 플레이그라운드에서는 실시간 테스트를 지원합니다. **Authorization**에 API 키를 입력하고(형식: `Bearer sk-xxx`), `model`을 선택하고, `prompt`을 입력한 다음, 필요에 따라 `response_format`을 선택하여 전송합니다. **`size`은 입력하지 마십시오**. 두 모델 모두 출력 크기가 고정되어 있습니다.

> [!TIP]
>
> **이 페이지를 사용하는 경우**: 순수한 텍스트-이미지 생성입니다. prompt만 있으면 됩니다. 참조 이미지 생성 또는 편집에는 [참조 이미지 API](https://docs.apiyi.com/ko/api-capabilities/hunyuan-image/image-edit.md)를 사용하십시오.

> [!WARNING]
>
> **⚠️ 알아야 할 세 가지 사항**
>
> * **`size`은 모델에 의해 재정의됩니다**: `-2k`은 항상 2048×2048을 반환하고 `-4k`은 항상 4096×4096을 반환합니다. `size`로 해상도를 변경하려고 하지 마십시오.
> * **`n`은 1로 고정됩니다**: 2 또는 3을 전달해도 이미지 한 장만 반환되며 한 번만 과금됩니다. 여러 이미지를 생성하려면 동시 요청을 전송하십시오.
> * **응답은 기본적으로 base64입니다**: 2K 응답은 약 6~~8.4MB이고 4K 응답은 17.6~~20MB입니다. 웹에 표시하려면 `response_format: "url"`을 전달하십시오.

## 코드 예시

### Python (OpenAI SDK)

```python theme={null}
from openai import OpenAI
import base64

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://api.apiyi.com/v1",
    timeout=120.0  # 120s for 2K; use 240s for 4K
)

resp = client.images.generate(
    model="hy-image-v3.5-preview-2k",
    prompt="A cinematic Chinese movie poster with the title \"Between Mountains and Seas\" centered, deep blue night sky and golden mountains, premium finish",
    # Do not pass size; responses default to b64_json
)

with open("out.png", "wb") as f:
    f.write(base64.b64decode(resp.data[0].b64_json))
```

### Python (원시 요청)

```python theme={null}
import base64
import os
import requests

response = requests.post(
    "https://api.apiyi.com/v1/images/generations",
    headers={"Authorization": f"Bearer {os.environ['APIYI_API_KEY']}"},
    json={
        "model": "hy-image-v3.5-preview-2k",
        "prompt": "An orange cat wearing sunglasses on a wooden windowsill, afternoon sunlight, cinematic shallow depth of field",
        "response_format": "b64_json",
    },
    timeout=120,
)
response.raise_for_status()

with open("out.png", "wb") as f:
    f.write(base64.b64decode(response.json()["data"][0]["b64_json"]))
```

### cURL

```bash theme={null}
curl -X POST "https://api.apiyi.com/v1/images/generations" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "hy-image-v3.5-preview-2k",
    "prompt": "A minimalist coffee shop poster with the headline \"Autumn Limited\" at the top, warm brown palette",
    "response_format": "b64_json"
  }' | python3 -c "import sys,json,base64; open('out.png','wb').write(base64.b64decode(json.load(sys.stdin)['data'][0]['b64_json']))"
```

### Node.js (네이티브 fetch)

```javascript theme={null}
import fs from 'node:fs';

const resp = await fetch('https://api.apiyi.com/v1/images/generations', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${process.env.APIYI_API_KEY}`
    },
    body: JSON.stringify({
        model: 'hy-image-v3.5-preview-4k',
        prompt: 'A serene Japanese garden with cherry blossoms, koi pond, golden hour',
        response_format: 'b64_json'
    }),
    signal: AbortSignal.timeout(240000)  // 240s for 4K
});

const { data } = await resp.json();
fs.writeFileSync('out.png', Buffer.from(data[0].b64_json, 'base64'));
```

### 브라우저 JavaScript (URL 모드)

```javascript theme={null}
{/* Demo only. Use a backend proxy in production to avoid leaking the key. */}
const resp = await fetch('https://api.apiyi.com/v1/images/generations', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer sk-your-api-key'
    },
    body: JSON.stringify({
        model: 'hy-image-v3.5-preview-2k',
        prompt: 'A cinematic poster with the title "Between Mountains and Seas", deep blue night sky and golden mountains',
        response_format: 'url'  // Return a CDN URL instead of a 6–26 MB base64 string
    })
});

const { data } = await resp.json();
document.getElementById('img').src = data[0].url;
```

## 매개변수

| 매개변수 | 유형 | 필수 | 기본값 | 설명 |
| - | - | - | - | - |
| `model` | 문자열 | 예 | — | `hy-image-v3.5-preview-2k` (2048×2048) 또는 `hy-image-v3.5-preview-4k` (4096×4096) |
| `prompt` | 문자열 | 예 | — | 중국어 또는 영어로 작성하는 prompt입니다. 이미지에 표시해야 하는 텍스트는 따옴표로 묶습니다 |
| `response_format` | 문자열 | 아니요 | `b64_json` | `b64_json` 또는 `url`입니다. 잘못된 값은 오류 없이 base64로 대체됩니다 |
| ~~`size`~~ | — | — | — | **모델에 의해 재정의됩니다**. 전달하지 마십시오 |
| ~~`n`~~ | — | — | — | **1로 고정됩니다**. 다른 값을 지정해도 이미지 하나만 반환됩니다 |
| `images` / `image` | — | — | — | 텍스트-이미지 변환에는 필요하지 않습니다. [참조 이미지 API](https://docs.apiyi.com/ko/api-capabilities/hunyuan-image/image-edit.md)를 사용하십시오 |

> [!TIP]
>
> 제약 조건 및 허용 값은 플레이그라운드 필드 설명을 참조하십시오. `quality`, `style` 및 `output_format`은 효과가 없으므로 전송하지 마십시오.

## 응답 형식

기본값 `response_format: "b64_json"`:

```json theme={null}
{
  "created": 1795534600,
  "id": "tsk_01m8736tvsqp2t27p0k53hjn7z",
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAADwf7zU..."
    }
  ],
  "usage": {
    "prompt_tokens": 1000,
    "total_tokens": 1000,
    "input_tokens": 1000,
    "output_tokens": 0
  }
}
```

`response_format: "url"` 사용 시:

```json theme={null}
{
  "created": 1795534600,
  "id": "tsk_01m8736tvsqp2t27p0k53hjn7z",
  "data": [
    {
      "url": "https://hdcdn.agisuitepro.com/o/2026/11/24/example.png"
    }
  ],
  "usage": {
    "prompt_tokens": 1000,
    "total_tokens": 1000,
    "input_tokens": 1000,
    "output_tokens": 0
  }
}
```

> [!WARNING]
>
> **응답 참고 사항**
>
> * `b64_json`은 **`data:image/png;base64,` 접두사가 없는 일반 base64**입니다. 직접 디코딩하여 PNG로 변환합니다.
> * 2K PNG는 약 4.4–5.7MB이고 base64 응답은 6–8.4MB입니다. 4K PNG는 12.6–18.9MB이고 base64 응답은 17.6–20MB입니다.
> * `url`은 `hdcdn.agisuitepro.com`에서 안정적인 URL을 반환합니다. HEAD는 200을 반환하고 `<img>`은 작동하지만, CORS 프리플라이트는 403을 반환하므로 브라우저의 `fetch` / 캔버스 액세스에는 서버 측 프록시가 필요합니다.
> * `usage`은 플레이스홀더이며 과금 대사에 사용할 수 없습니다.

> [!NOTE]
>
> **`usage`은 과금 대상 데이터가 아닙니다**: `prompt_tokens`은 항상 1000이고 `output_tokens`은 항상 0입니다. 이 시리즈는 이미지당 고정 가격으로 과금됩니다. 실제 청구 금액은 APIYI 콘솔 청구서를 사용하여 확인합니다.


## OpenAPI

````yaml api-reference/hunyuan-image-generate-openapi-en.yaml POST /v1/images/generations
openapi: 3.1.0
info:
  title: Tencent Hunyuan Hy-Image 3.5 Preview Text-to-Image API
  description: >
    Tencent Cloud official-relay Hunyuan Hy-Image-3.5-preview image model —
    text-to-image endpoint.


    - Two public models: `hy-image-v3.5-preview-2k` (fixed 2048×2048,
    \$0.022/image) and `hy-image-v3.5-preview-4k` (fixed 4096×4096,
    \$0.030/image)

    - List prices match the official list; top-up bonuses bring the effective
    price to about **83–91% of list**. See [Top-up
    Bonuses](/en/faq/recharge-promotions)

    - Flat per-image pricing, regardless of `size`, `response_format`, or the
    number of reference images; exactly 1 image per request

    - Returns `data[0].b64_json` by default (plain base64, no `data:` prefix);
    pass `response_format: "url"` to receive a platform CDN URL

    - `size` is overridden by the model's fixed resolution; `n` is fixed at 1

    - Strong Chinese text rendering, suitable for posters, e-commerce hero
    images, and film assets


    **Authentication**: add `Authorization: Bearer YOUR_API_KEY` to the request
    headers.


    **Get an API key**: create a Token in the [APIYI
    console](https://api.apiyi.com/token)
  version: 1.0.0
servers:
  - url: https://api.apiyi.com
    description: Primary endpoint
security:
  - bearerAuth: []
paths:
  /v1/images/generations:
    post:
      tags:
        - Text-to-Image
      summary: 'Text-to-image: generate a 2K/4K image from a prompt'
      description: >
        Generate an image with `hy-image-v3.5-preview-2k` or
        `hy-image-v3.5-preview-4k`.


        - Required: `model`, `prompt`

        - Optional: `response_format` (`b64_json` by default, or `url`)

        - Do not pass `size`: `-2k` is fixed at 2048×2048 and `-4k` at 4096×4096

        - `n` is fixed at 1; send concurrent requests for multiple images

        - For reference-image generation, use the [reference-image
        endpoint](/en/api-capabilities/hunyuan-image/image-edit)
      operationId: generateHunyuanImageTextToImage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/HunyuanImageGenerateRequest'
            example:
              model: hy-image-v3.5-preview-2k
              prompt: >-
                A cinematic movie poster with the Chinese title "Between
                Mountains and Seas" centered, deep blue night sky and golden
                mountains, premium finish
              response_format: b64_json
      responses:
        '200':
          description: Image generated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageResponse'
        '400':
          description: >-
            Invalid parameters: missing prompt returns `invalid_image_request`;
            content moderation returns `content_safety_violation`
        '401':
          description: Unauthorized - invalid API key
        '429':
          description: Rate limit exceeded or insufficient quota
        '500':
          description: Internal server error
        '503':
          description: Wrong model name, or no available channel in the current group
      security:
        - bearerAuth: []
components:
  schemas:
    HunyuanImageGenerateRequest:
      type: object
      required:
        - model
        - prompt
      properties:
        model:
          type: string
          description: Model ID. `-2k` is fixed at 2048×2048; `-4k` is fixed at 4096×4096
          enum:
            - hy-image-v3.5-preview-2k
            - hy-image-v3.5-preview-4k
          default: hy-image-v3.5-preview-2k
        prompt:
          type: string
          description: >-
            Prompt, Chinese or English. Wrap text that must appear in the image
            in quotes
          example: >-
            A cinematic movie poster with the Chinese title "Between Mountains
            and Seas" centered, deep blue night sky and golden mountains,
            premium finish
        response_format:
          type: string
          description: >-
            Response format. Defaults to `b64_json`; `url` returns a stable
            platform CDN URL
          enum:
            - b64_json
            - url
          default: b64_json
        'n':
          type: integer
          description: Fixed at 1. This model always returns exactly one image
          enum:
            - 1
          default: 1
    ImageResponse:
      type: object
      properties:
        created:
          type: integer
          description: Unix timestamp
          example: 1795534600
        id:
          type: string
          description: Task ID for this request
          example: tsk_01m8736tvsqp2t27p0k53hjn7z
        data:
          type: array
          description: Image result array, always exactly one item
          items:
            type: object
            properties:
              b64_json:
                type: string
                description: Plain base64 PNG data, no `data:` prefix (returned by default)
                example: iVBORw0KGgoAAAANSUhEUgAA...
              url:
                type: string
                description: Image URL (returned when response_format=url)
                example: https://hdcdn.agisuitepro.com/o/2026/11/24/example.png
        usage:
          type: object
          description: >
            **Placeholder values; do not use for billing reconciliation.**
            `prompt_tokens` is always 1000 and `output_tokens` is always 0.

            Actual charges are flat per image and come from the console bill.
          properties:
            prompt_tokens:
              type: integer
              example: 1000
            total_tokens:
              type: integer
              example: 1000
            input_tokens:
              type: integer
              example: 1000
            output_tokens:
              type: integer
              example: 0
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key created in the APIYI console

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.