> ## 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 레퍼런스 및 플레이그라운드 — images 배열은 2K/4K로 고정되고, 레거시 image 필드의 기본값은 1536이며, 멀티파트 편집은 1536만 출력합니다

> [!NOTE]
>
> 오른쪽의 대화형 Playground에서는 실시간 테스트를 지원합니다. `images` 필드에는 **공개 이미지 URL** 또는 `data:image/...;base64,...`을 입력할 수 있으며, 로컬 파일은 업로드하지 않습니다. 아래 예제를 사용하여 로컬 파일을 데이터 URI로 변환하십시오.

> [!TIP]
>
> **이 페이지를 사용해야 하는 경우**: 하나 이상의 참조 이미지에서 이미지를 생성하는 경우에 사용합니다. 예를 들어 스타일 전이, 구도 유지, 다중 이미지 융합 또는 참조 이미지 기반 다시 그리기 등에 사용할 수 있습니다. 순수한 텍스트-이미지 생성에는 [텍스트-이미지 API](https://docs.apiyi.com/ko/api-capabilities/hunyuan-image/text-to-image.md)를 사용하십시오.

> [!WARNING]
>
> **⚠️ 출력 크기가 서로 다른 세 가지 참조 스타일**
>
> * **`images` 배열(권장)**: 2048×2048(`-2k`) 또는 4096×4096(`-4k`)으로 고정됩니다. 명시적인 `size`은 무시됩니다.
> * **기존 `image` 필드**: `size` 없이 **1536×1536**으로만 출력됩니다. 2K/4K에는 `size`을 명시적으로 전달하십시오. 단, 과금은 모델의 고정 요금으로 유지됩니다.
> * **`/v1/images/edits` 멀티파트**: 작동하지만 **1536×1536**으로만 출력되며 2K/4K 재정의를 사용하지 않습니다. 권장하지 않습니다.
>
> **`prompt`이 필요합니다**: 프롬프트가 없는 이미지를 요청하면 400 `prompt is required`이 반환됩니다.

## 세 가지 접근 방식 비교

| 접근 방식 | 요청 형식 | 기본 출력 | 명시적 `size` | 권장 사항 |
| - | - | - | - | - |
| `images` 배열 | JSON, `POST /v1/images/generations` | **2048×2048 / 4096×4096** | 재정의됨 | ✅ 권장 |
| 레거시 `image` | JSON, `POST /v1/images/generations` | **1536×1536** | 적용됨: 2K/4K | ⚠️ 레거시 |
| 멀티파트 | `POST /v1/images/edits`, `multipart/form-data` | **1536×1536** | 무시됨 | ❌ 권장하지 않음 |

> [!WARNING]
>
> **가격은 출력 크기에 따라 달라지지 않습니다.** 세 가지 방식 모두 선택한 모델의 고정 요금으로 과금됩니다. 레거시 `image` 필드와 멀티파트 수정은 `-2k` / `-4k` 요금이 부과되는 동안에도 1536×1536만 반환할 수 있습니다. 새로운 모든 통합에는 `images`을 사용하십시오.

## 코드 예시

### Python (OpenAI SDK + extra\_body)

```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="Turn the reference image into a watercolor painting while keeping the red circle and blue square in place",
    extra_body={
        # Data URIs such as "data:image/png;base64,..." also work
        "images": [
            "https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png"
        ]
    }
)

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

### Python (데이터 URI를 사용하는 원시 요청)

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

with open("reference.png", "rb") as f:
    data_uri = "data:image/png;base64," + base64.b64encode(f.read()).decode()

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": "Turn the reference image into a watercolor painting while keeping the red circle and blue square in place",
        "images": [data_uri],
        "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 (URL 참조)

```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-4k",
    "prompt": "Turn the reference image into a watercolor painting while keeping the red circle and blue square in place",
    "images": ["https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png"],
    "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 (여러 참조)

```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-2k',
        prompt: 'Place the person from image 1 into the scene from image 2, keeping the clothing color from image 1',
        images: [
            'https://your-domain.com/person.png',
            'https://your-domain.com/scene.png'
        ],
        response_format: 'b64_json'
    }),
    signal: AbortSignal.timeout(120000)
});

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

### 레거시 `image` 필드 (2K/4K의 명시적 크기)

```python theme={null}
resp = client.images.generate(
    model="hy-image-v3.5-preview-2k",
    prompt="Turn the reference image into a watercolor painting while keeping the composition",
    extra_body={
        "image": ["https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png"],
        "size": "2048x2048"  # Legacy field: without size, output is only 1536×1536
    }
)
```

### 멀티파트 편집 (권장하지 않음)

```bash theme={null}
curl -X POST "https://api.apiyi.com/v1/images/edits" \
  -H "Authorization: Bearer sk-your-api-key" \
  -F "model=hy-image-v3.5-preview-2k" \
  -F "prompt=Turn the reference image into a watercolor painting while keeping the composition" \
  -F "image=@reference.png"
```

> [!WARNING]
>
> 멀티파트 `/v1/images/edits` 출력은 **1536×1536**만 지원하며 2K/4K `size` 재정의를 적용하지 않습니다. 이전 코드와의 호환성을 위해 존재하며 새 프로젝트에는 권장하지 않습니다.

## 매개변수

| 매개변수 | 유형 | 필수 | 기본값 | 설명 |
| - | - | - | - | - |
| `model` | string | 예 | — | `hy-image-v3.5-preview-2k` (2048×2048) 또는 `hy-image-v3.5-preview-4k` (4096×4096) |
| `prompt` | string | 예 | — | 생성/편집 지침입니다. 유지할 항목과 변경할 항목을 명시합니다 |
| `images` | string\[] | 예 (권장) | — | 공개 URL 또는 데이터 URI 형식의 참조 이미지입니다. 출력은 2K/4K로 고정됩니다 |
| `image` | string / string\[] | 아니요 (레거시) | — | 편집 경로입니다. `size` 없이 1536×1536 출력만 지원합니다 |
| `size` | string | 아니요 | — | 레거시 `image` 필드에만 적용되며, `images`에서는 재정의됩니다 |
| `response_format` | string | 아니요 | `b64_json` | `b64_json` 또는 `url` |
| ~~`n`~~ | — | — | — | **1로 고정됩니다** |

> [!TIP]
>
> 참조 이미지 수는 가격에 영향을 주지 않습니다. 공식 문서에는 이미지당 20MB 이하, 입력 이미지 총 20개 이하로 명시되어 있습니다. 여러 참조 이미지를 사용하는 경우 프롬프트에서 “이미지 1 / 이미지 2”와 같이 지칭합니다.

## 참조 이미지 준비

* **형식**: PNG, JPEG 또는 WebP이며, 각 이미지는 20MB 이하여야 합니다.
* **URL**: 공개적으로 접근할 수 있는 직접 링크여야 합니다. 로그인이 필요하거나 핫링크 방지가 적용된 URL 또는 만료된 서명 URL은 다운로드할 수 없습니다.
* **데이터 URI**: 로컬 파일을 `data:image/png;base64,...`로 변환하여 `images` 배열에 넣습니다. 작은 파일과 사설 네트워크에 적합합니다.
* **압축**: 긴 변을 2048px로 조정하고 품질을 0.9로 설정합니다. 전송 및 처리 시간을 줄이려면 전체 크기를 약 6MB 미만으로 유지합니다.
* **순서**: 참조 이미지에는 `images` 배열 순서대로 번호가 지정됩니다(이미지 1, 이미지 2, ...). prompt에서 해당 이미지를 명시적으로 지칭합니다.

## 응답 형식

```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
  }
}
```

> [!WARNING]
>
> **응답 참고 사항**
>
> * `b64_json`는 **`data:` 접두사가 없는 일반 base64**입니다. 직접 디코딩하여 PNG로 변환하십시오.
> * `response_format: "url"`을 사용하면 이미지는 `hdcdn.agisuitepro.com`의 `data[0].url`에 있습니다.
> * `usage`은 플레이스홀더이며 과금 대사에 사용할 수 없습니다.
> * 2K 참조 출력은 약 3–7 MB이고 4K 출력은 약 18–19 MB입니다. 4K base64 응답은 최대 26 MB에 달할 수 있습니다.

> [!NOTE]
>
> **`usage`은 과금 데이터가 아닙니다**: `prompt_tokens`는 항상 1000이고 `output_tokens`은 항상 0입니다. 이 시리즈는 이미지당 고정 요금으로 과금됩니다. 실제 요금은 APIYI 콘솔의 청구 내역을 확인하십시오.

## 관련 문서

* [텍스트-이미지 변환 API 참조](https://docs.apiyi.com/ko/api-capabilities/hunyuan-image/text-to-image.md)
* [Hunyuan Hy-Image 3.5 자주 묻는 질문](https://docs.apiyi.com/ko/api-capabilities/hunyuan-image/faq.md)
* [이미지 API 모범 사례](https://docs.apiyi.com/ko/api-capabilities/image-api-best-practices.md)


## OpenAPI

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


    - Recommended field `images`: a JSON array whose items are public image URLs
    or `data:image/...;base64,...`

    - The `images` path always outputs 2048×2048 (`-2k`) or 4096×4096 (`-4k`);
    an explicit `size` is overridden

    - Legacy field `image`: string or array, routed through the edit path;
    without `size` it outputs only 1536×1536. Pass `size` explicitly for 2K/4K,
    but billing is still the model's flat price

    - `/v1/images/edits` multipart also works, but outputs only 1536×1536 and is
    not recommended

    - Returns `data[0].b64_json` by default; pass `response_format: "url"` for a
    platform CDN URL

    - Exactly 1 image per request; `n` is fixed at 1


    **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:
        - Reference Image
      summary: >-
        Reference-image generation: create a 2K/4K image from references and a
        prompt
      description: >
        Generate an image with `hy-image-v3.5-preview-2k` or
        `hy-image-v3.5-preview-4k` from one or more reference images.


        - Required: `model`, `prompt`, `images` (at least one)

        - Recommended: `images: ["https://...", "data:image/png;base64,..."]`

        - Legacy `image`: without `size` it outputs 1536×1536; pass `size`
        explicitly for 2K/4K

        - `/v1/images/edits` multipart outputs only 1536×1536 and is not
        recommended

        - Each reference image ≤20MB; the official docs list a total input limit
        of 20 images
      operationId: generateHunyuanImageFromReferences
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/HunyuanImageReferenceRequest'
            example:
              model: hy-image-v3.5-preview-2k
              prompt: >-
                Turn the reference image into a watercolor painting while
                keeping the red circle and blue square in place
              images:
                - >-
                  https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png
              response_format: b64_json
      responses:
        '200':
          description: Image generated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ImageResponse'
        '400':
          description: >-
            Missing prompt, empty reference images (`invalid_image_request`), or
            content moderation (`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:
    HunyuanImageReferenceRequest:
      type: object
      required:
        - model
        - prompt
        - images
      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: Edit/generation instruction. State what to keep and what to change
          example: >-
            Turn the reference image into a watercolor painting while keeping
            the red circle and blue square in place
        images:
          type: array
          description: >
            Reference images. Items can be public URLs or
            `data:image/...;base64,...`.

            This is the recommended field; output is fixed at the model's 2K/4K
            resolution.
          minItems: 1
          maxItems: 20
          items:
            type: string
          example:
            - >-
              https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png
        image:
          type: string
          description: >
            Legacy field, not recommended. Routed through the edit path: outputs
            1536×1536 without `size`;

            pass `size` explicitly for 2K/4K. Billing is still the model's flat
            price.
          example: https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png
        size:
          type: string
          description: >
            Only applies to the legacy `image` field; ignored when using
            `images`.

            Common values: `2048x2048` (2K) or `4096x4096` (4K).
          example: 2048x2048
        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.