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 Image Gen
Reference-Image API Reference
Tencent Hunyuan Hy-Image 3.5 Preview reference-image API reference and Playground — the images array stays fixed at 2K/4K, the legacy image field defaults to 1536, and multipart edits output only 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
}
}The interactive Playground on the right supports live testing. The
images field accepts public image URLs or data:image/...;base64,...; it does not upload local files. Convert local files to data URIs with the examples below.When to use this page: generate an image from one or more reference images — style transfer, composition preservation, multi-image fusion, or reference-guided redrawing. For pure text-to-image, use the text-to-image API.
⚠️ Three reference styles with different output sizes
imagesarray (recommended): fixed 2048×2048 (-2k) or 4096×4096 (-4k); an explicitsizeis overridden.- Legacy
imagefield: outputs only 1536×1536 withoutsize; passsizeexplicitly for 2K/4K, but billing remains the model’s flat price. /v1/images/editsmultipart: works, but outputs only 1536×1536 and does not use the 2K/4K override. Not recommended.
prompt is required: an image without a prompt returns 400 prompt is required.Comparing the Three Approaches
| Approach | Request shape | Default output | Explicit size | Recommendation |
|---|---|---|---|---|
images array | JSON, POST /v1/images/generations | 2048×2048 / 4096×4096 | Overridden | ✅ Recommended |
Legacy image | JSON, POST /v1/images/generations | 1536×1536 | Honored: 2K/4K | ⚠️ Legacy |
| Multipart | POST /v1/images/edits, multipart/form-data | 1536×1536 | Ignored | ❌ Not recommended |
Price does not depend on output size. All three styles bill at the selected model’s flat price. The legacy
image field and multipart edits may return only 1536×1536 while still charging the -2k / -4k price. Use images for all new integrations.Code Examples
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 (raw requests with a data URI)
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 reference)
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 (multiple references)
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'));
Legacy image field (explicit size for 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
}
)
Multipart edits (not recommended)
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]"
Multipart
/v1/images/edits outputs only 1536×1536 and does not apply the 2K/4K size override. It exists for compatibility with older code and is not recommended for new projects.Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | hy-image-v3.5-preview-2k (2048×2048) or hy-image-v3.5-preview-4k (4096×4096) |
prompt | string | Yes | — | Generation/edit instruction; state what to keep and what to change |
images | string[] | Yes (recommended) | — | Reference images as public URLs or data URIs; output stays fixed at 2K/4K |
image | string / string[] | No (legacy) | — | Edit path; outputs only 1536×1536 without size |
size | string | No | — | Only applies to the legacy image field; overridden for images |
response_format | string | No | b64_json | b64_json or url |
n | — | — | — | Fixed at 1 |
Reference count does not affect the price. The official docs list ≤20MB per image and ≤20 input images total. With multiple references, refer to them as “image 1 / image 2” in the prompt.
Preparing References
- Formats: PNG, JPEG, or WebP; each image ≤20MB.
- URLs: must be publicly reachable direct links. Login-protected, hotlink-protected, or expired signed URLs fail to download.
- Data URIs: convert local files to
data:image/png;base64,...and put them in theimagesarray. Good for small files and private networks. - Compression: resize the long edge to 2048px and use quality 0.9; keep the combined size under about 6MB to reduce transfer and processing time.
- Order: references are numbered in
imagesarray order (image 1, image 2, …). Refer to them explicitly in the prompt.
Response Format
{
"created": 1795534600,
"id": "tsk_01m8736tvsqp2t27p0k53hjn7z",
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIAAADwf7zU..."
}
],
"usage": {
"prompt_tokens": 1000,
"total_tokens": 1000,
"input_tokens": 1000,
"output_tokens": 0
}
}
Response notes
b64_jsonis plain base64 without adata:prefix. Decode it directly to a PNG.- With
response_format: "url", the image is indata[0].urlonhdcdn.agisuitepro.com. usageis a placeholder and cannot be used for billing reconciliation.- A 2K reference output is about 3–7 MB and a 4K output about 18–19 MB; a 4K base64 response can reach 26 MB.
usage is not billable data: prompt_tokens is always 1000 and output_tokens is always 0. This series bills a flat price per image; use the APIYI console bill for actual charges.Related Docs
Body
application/json
Response
Image generated successfully
Was this page helpful?