Reference-image generation: create a 2K/4K image from references and a prompt
curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"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"
]
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = {
"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"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
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']
})
};
fetch('https://api.apiyi.com/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.apiyi.com/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'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'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.apiyi.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"hy-image-v3.5-preview-2k\",\n \"prompt\": \"Turn the reference image into a watercolor painting while keeping the red circle and blue square in place\",\n \"images\": [\n \"https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.apiyi.com/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"hy-image-v3.5-preview-2k\",\n \"prompt\": \"Turn the reference image into a watercolor painting while keeping the red circle and blue square in place\",\n \"images\": [\n \"https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"hy-image-v3.5-preview-2k\",\n \"prompt\": \"Turn the reference image into a watercolor painting while keeping the red circle and blue square in place\",\n \"images\": [\n \"https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"created": 1795534600,
"id": "tsk_01m8736tvsqp2t27p0k53hjn7z",
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA...",
"url": "https://hdcdn.agisuitepro.com/o/2026/11/24/example.png"
}
],
"usage": {
"prompt_tokens": 1000,
"total_tokens": 1000,
"input_tokens": 1000,
"output_tokens": 0
}
}Tencent Hunyuan Hy-Image 3.5画像生成
参照画像 API リファレンス
Tencent Hunyuan Hy-Image 3.5 Preview の参照画像 API リファレンスおよびプレイグラウンド — images 配列は 2K/4K に固定され、レガシーな image フィールドのデフォルトは 1536、マルチパート編集の出力は 1536 のみです
POST
/
v1
/
images
/
generations
Reference-image generation: create a 2K/4K image from references and a prompt
curl --request POST \
--url https://api.apiyi.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"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"
]
}
'import requests
url = "https://api.apiyi.com/v1/images/generations"
payload = {
"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"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
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']
})
};
fetch('https://api.apiyi.com/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.apiyi.com/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'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'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.apiyi.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"hy-image-v3.5-preview-2k\",\n \"prompt\": \"Turn the reference image into a watercolor painting while keeping the red circle and blue square in place\",\n \"images\": [\n \"https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.apiyi.com/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"hy-image-v3.5-preview-2k\",\n \"prompt\": \"Turn the reference image into a watercolor painting while keeping the red circle and blue square in place\",\n \"images\": [\n \"https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.apiyi.com/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"hy-image-v3.5-preview-2k\",\n \"prompt\": \"Turn the reference image into a watercolor painting while keeping the red circle and blue square in place\",\n \"images\": [\n \"https://docs.apiyi.com/images/hunyuan-image-v35-reference-input.png\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"created": 1795534600,
"id": "tsk_01m8736tvsqp2t27p0k53hjn7z",
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA...",
"url": "https://hdcdn.agisuitepro.com/o/2026/11/24/example.png"
}
],
"usage": {
"prompt_tokens": 1000,
"total_tokens": 1000,
"input_tokens": 1000,
"output_tokens": 0
}
}右側のインタラクティブなプレイグラウンドでは、リアルタイムテストを実行できます。
images フィールドでは、公開画像 URL または data:image/...;base64,... を指定できます。ローカルファイルのアップロードには対応していません。以下の例を使用して、ローカルファイルをデータ URI に変換してください。このページを使用する場合:1枚以上の参照画像から画像を生成する場合 — スタイル転送、構図の保持、複数画像の融合、または参照画像に基づく再描画などに使用します。純粋なテキストから画像への生成には、テキストから画像への API を使用してください。
⚠️ 出力サイズが異なる3つの参照方法
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 が返されます。3つの方式の比較
| 方式 | リクエスト形式 | デフォルト出力 | 明示的な 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 | 無視されます | ❌ 非推奨 |
料金は出力サイズに依存しません。 3つすべての方式で、選択したモデルの固定価格が課金されます。レガシーの
image フィールドとマルチパートの編集では、-2k / -4k の料金が課金される一方で、1536×1536 のみが返される場合があります。新しい統合にはすべて images を使用してください。コード例
Python(OpenAI SDK + extra_body)
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(data URIを使用したraw requests)
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参照)
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(複数の参照)
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用の明示的なサイズ)
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
}
)
マルチパート編集(推奨されません)
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 "[email protected]"
マルチパート
/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に固定 |
参照画像の枚数は料金に影響しません。公式ドキュメントでは、画像1枚あたり20MB以下、入力画像は合計20枚以下とされています。複数の参照画像を使用する場合は、prompt内で「画像1 / 画像2」のように指定します。
参照画像の準備
- 形式: PNG、JPEG、またはWebP。各画像は20MB以下にしてください。
- URL: 公開アクセス可能な直接リンクである必要があります。ログイン保護やホットリンク保護があるURL、または有効期限切れの署名付きURLではダウンロードに失敗します。
- データURI: ローカルファイルを
data:image/png;base64,...に変換し、images配列に格納します。小さなファイルやプライベートネットワークに適しています。 - 圧縮: 長辺を2048pxにリサイズし、品質を0.9に設定します。転送時間と処理時間を短縮するため、合計サイズを約6MB未満に抑えてください。
- 順序: 参照画像には
images配列の順序で番号が付けられます(画像1、画像2、…)。prompt内で明示的に指定してください。
レスポンス形式
{
"created": 1795534600,
"id": "tsk_01m8736tvsqp2t27p0k53hjn7z",
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAADwf7zU..."
}
],
"usage": {
"prompt_tokens": 1000,
"total_tokens": 1000,
"input_tokens": 1000,
"output_tokens": 0
}
}
レスポンスに関する注意事項
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 に達することがあります。
usage は課金用データではありません: prompt_tokens は常に 1000、output_tokens は常に 0 です。このシリーズは画像 1 枚ごとの定額課金です。実際の請求額は APIYI コンソールの請求明細で確認してください。関連ドキュメント
ボディ
application/json
レスポンス
Image generated successfully
このページは役に立ちましたか?