How to use APIYI to invoke Tencent Hunyuan Hy-Image 3.5 Preview for continuous image editing? A three-round reference image editing tutorial

Summary: This article walks through a reusable three-round example showing how to call Tencent Hunyuan Hy-Image 3.5 Preview on APIYI — feeding each round’s output back in as the next round’s reference image, and progressively editing a product shot.

Bottom line first: On APIYI, every reference-image request to Hy-Image 3.5 Preview is an independent single-round edit — the platform doesn’t keep the previous round’s frame. To chain edits together, your application has to handle three things itself:

  1. Put the previous round’s output image into this round’s images field.
  2. Write the full goal, plus every requirement that’s still in effect, into this round’s prompt.
  3. Explicitly pass the same aspect-ratio size in every round.

The first two rounds use hy-image-v3.5-preview-2k with 2048x1152; the final version uses hy-image-v3.5-preview-4k with 3840x2160. At Default list pricing, three rounds come to $0.074. The three-round flow below is an illustrative plan, not a live test — for interface details, refer to the APIYI apiyi.com documentation.

apiyi-hunyuan-hy-image-3-5-preview-multi-round-edit-en-image-0


Tencent Hunyuan Hy-Image 3.5 Preview: Iterative Image Editing Knowledge Map

apiyi-hunyuan-hy-image-3-5-preview-multi-round-edit-en-image-1

Figure caption: The trunk is “interface → canvas → three rounds of editing → acceptance”. Each round only advances the version once a new image has been received and archived. On a timeout or failure, switch to section 4, and decide whether to resend after confirming the result. The third round additionally brings in the original draft as a second reference image.

Hy-Image 3.5 Preview Tutorial Index

The reading order here matches the execution order. Sections meant for on-demand reference are marked separately.

  • 1 API and parameters: Start by confirming how to send the request and what comes back. This is the foundation for all the rounds that follow.
  • 2 Canvas and tiers: Decide on the model tier and size. Whether you can stack the three rounds side by side for comparison depends on this step.
  • 3 Three-round reference image editing: This is the core workflow. Run the three rounds in sequence; section 3.4 specifies how to archive each round.
  • 4 Timeouts, failures, and cost: Use this when any round in section 3 goes wrong. It also lays out the budget for all three rounds.
  • 5 Common questions: Consult as needed.
  • 6 Delivery acceptance: Run this last, and check the final version against the checklist.

To Know: Hunyuan Reference Image Editing Terms

Term Brief explanation
Reference-image generation Submit one or more images plus a text instruction, and let the model generate a new image based on the images
images The array of reference images in the request; each element is an image URL or a data URI string
data URI A way to encode an image into a string, in the form data:image/png;base64, followed by the Base64 content
b64_json The default return format: Base64 PNG without a prefix
Tier The model ID suffix -2k / -4k, which determines the maximum allowed pixel area and the unit price
Base image The reference image to be modified in the current round, usually the output image from the previous round

1 How to Call the Hy-Image 3.5 Preview Reference Image API

1.1 Tencent Hunyuan reference-image generation endpoint and authentication

On APIYI, text-to-image and reference-image generation share the same endpoint: POST /v1/images/generations. Requests use Bearer API key authentication, and the request body is JSON. As long as the request includes images with at least one image, it’s a reference-image generation request.

The singular image field and the legacy /v1/images/edits multipart path are also kept as compatibility options. They also validate custom width and height within the model tier. For new projects, use JSON with an images array—when you add a second reference image later, you won’t need to change the structure. Each request returns only one image.

1.2 Hy-Image 3.5 Preview request fields

Field Required Description
model Yes hy-image-v3.5-preview-2k or hy-image-v3.5-preview-4k
prompt Yes Complete instructions for this round, including the new goal and requirements that still need to be preserved
images Yes (reference-image generation) 1–20 items; each element is a URL or data URI; each image must be no larger than 20 MB; supports PNG, JPEG, and WebP
size Optional Formatted like 2048x1152; defaults to square output when omitted
response_format Optional Defaults to b64_json; passing "url" returns a direct platform CDN link

For transfer, the platform recommends compressing the long edge of reference images to 2048 pixels or less and keeping the total image payload under 6 MB per request. This is a transfer recommendation, not a hard limit, but it can significantly reduce upload time and failure rates.

1.3 How the returned result becomes the next round’s reference image

After a successful request, the generated image is in data[0]. There are two ways to pass it back in the next round:

  • URL method: Set response_format: "url" in the request, then put data[0].url directly into the next round’s images. This keeps the response body small and works well for continuous editing.
  • Base64 method: The default data[0].b64_json has no prefix. When passing it back, prepend data:image/png;base64,; otherwise it isn’t a valid data URI.

CDN direct links can be used directly for page display. If you need cross-origin pixel reads or canvas processing in the browser, the APIYI FAQ recommends fetching them through your application server. If a direct link expires or access is restricted, you can re-encode the file your app saved into a data URI, so you should save each round’s output image to disk.

Here’s a minimal runnable example for a single round of reference-image editing:

import requests

BASE_URL = "https://api.apiyi.com/v1"  # APIYI OpenAI-compatible API
headers = {"Authorization": "Bearer YOUR_API_KEY"}

payload = {
    "model": "hy-image-v3.5-preview-2k",
    "prompt": "把瓶身背后的背景换成干净的浅灰色,瓶身大小、位置和标志保持不变",
    "images": ["https://example.com/bottle-original.png"],
    "size": "2048x1152",
    "response_format": "url",
}

resp = requests.post(f"{BASE_URL}/images/generations",
                     json=payload, headers=headers, timeout=120)
resp.raise_for_status()
print(resp.json()["data"][0]["url"])

🚀 Quick start: First create an API key in the APIYI console at apiyi.com and claim the free trial credits for new users. Use the single-round example above to confirm the API works, then integrate it into the three-round workflow below.

2 Hy-Image 3.5 Preview: How to Choose the Canvas and Tier

2.1 Area Rules for the Tencent Hunyuan 2K and 4K Tiers

APIYI selects the tier based on the model ID. For both tiers, each side can range from 256 to 8192 pixels; the difference is the maximum area after multiplying width by height. To tell which tier a given size can use, check the area, not the long edge.

Tier Model ID Area limit Default output when size is omitted Example sizes
2K hy-image-v3.5-preview-2k 4,194,304 2048×2048 2048x1152 and 2560x1440 are both valid
4K hy-image-v3.5-preview-4k 16,777,216 4096×4096 3840x2160

2560x1440 has a long edge beyond 2048, but its area is within the 2K tier limit, so it’s still valid. 3840x2160 exceeds the 2K tier area, so it must use the 4K tier. If you submit 4096x4096 with -2k, you’ll get HTTP 400 invalid_size.

apiyi-hunyuan-hy-image-3-5-preview-multi-round-edit-en-image-2

2.2 Why You Need to Pass the Same Aspect Ratio Every Round in Iterative Image Editing

You can specify the canvas again in each round. The subject and layout are guided jointly by the reference image and instructions, but the output size is determined by size. If the first round is a widescreen image and you forget to pass size in the second round, the output falls back to the default square, and the image gets reframed. As a result, the two versions can’t be overlaid pixel by pixel for comparison.

So all three rounds should explicitly pass a 16:9 aspect ratio: the first two use -2k with 2048x1152, and the final version uses -4k with 3840x2160. When upscaling for delivery, keep the aspect ratio and only increase the pixel area, so you can compare text and edges at the same locations. Also save the actual output width and height with each version, and base acceptance on the actual values.


3 Tencent Hunyuan Hy-Image 3.5 Preview: Three-Round Reference Image Editing Example

Let’s use the same product bottle image as an example. Assume the original is a 16:9 landscape image, already compressed so its long edge is within 2048 pixels. None of the three rounds depend on a server-side session — continuity comes entirely from the images you pass back and the instructions you spell out in full.

apiyi-hunyuan-hy-image-3-5-preview-multi-round-edit-en-image-3

Round images (in order) Goal for this round What to preserve model / size
3.1 Original image Swap background to light gray Bottle size, position, logo -2k / 2048x1152
3.2 Round 1 output Switch to right-side lighting Light gray background, bottle size, position, logo -2k / 2048x1152
3.3 Image one: Round 2 output; Image two: original artwork Restore label colors per image two Composition and side lighting of image one -4k / 3840x2160

3.1 Round one: swap in a light gray background using the original image

In round one, do just one thing: change the background behind the bottle to light gray. In the same instruction, also state clearly that the bottle size, position, and logo stay unchanged. The more singular the change, the easier it is to judge whether this round actually got it right.

3.2 Round two: change the right-side lighting using round one’s output as the base

In round two, the images field holds round one’s output, not the original image. The model can’t see round one’s instruction, so the already-satisfied requirement of “light gray background” has to be written again in this round’s prompt. This is to keep the new round from reverting the background. The instruction can be phrased as: “Using the reference image as the base, change to lighting coming from the right side of the frame, and keep the light gray background, bottle size, position, and logo unchanged.”

3.3 Round Three: Restore the Label with Two Reference Images and Upscale to 4K

After two rounds of editing, the label colors may have drifted from the original. For round three, submit two images: Image 1 is the second-round output and serves as the current frame, while Image 2 is the original and is used only to provide the label color. Order matters—put the version you’re editing first and the original second. The APIYI launch announcement has also reported a use case for blending two reference images.

In the prompt, spell out the role of each image separately. For example: “Image 1 is the current frame; Image 2 is the original. Use Image 1 as the base, keep its composition, light gray background, and right-side lighting, and restore the bottle label’s original colors from Image 2.” For this round, switch to the -4k tier, set size to 3840x2160, and keep the same aspect ratio as the previous two rounds.

3.4 Version Archiving and Progression Rules for Each Round

Each round has to save four things: the base image, the instruction, the output image, and the actual width and height. Only advance the version number after you’ve received a new image; if a request fails, restart from the most recent completed version. Pick both the exported file and the next round’s reference image from the archive.

Here’s the complete three-round script. All three sets of parameters are reusable examples—swap them for your own product images:

View the full code for three-round reference image editing
import base64
import json
import pathlib
import requests

BASE_URL = "https://api.apiyi.com/v1"   # APIYI unified API endpoint
API_KEY = "YOUR_API_KEY"
ARCHIVE = pathlib.Path("archive")
ARCHIVE.mkdir(exist_ok=True)


def to_data_uri(path: pathlib.Path) -> str:
    """Encode an archived file as a data URI for use as the next round's reference image"""
    b64 = base64.b64encode(path.read_bytes()).decode()
    return f"data:image/png;base64,{b64}"


def edit_round(version: int, model: str, prompt: str,
               images: list, size: str, timeout: int) -> pathlib.Path:
    payload = {
        "model": model,
        "prompt": prompt,
        "images": images,
        "size": size,
        "response_format": "url",   # Return a direct CDN URL to keep the response body small
    }
    resp = requests.post(
        f"{BASE_URL}/images/generations",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json=payload,
        timeout=timeout,
    )
    resp.raise_for_status()
    url = resp.json()["data"][0]["url"]

    # Fetch the generated image and write it to disk to prevent the direct URL from expiring
    out = ARCHIVE / f"v{version}.png"
    out.write_bytes(requests.get(url, timeout=120).content)

    # Archive: base image source, instruction, output image, and requested size (actual width and height are based on the saved output image)
    meta = {"version": version, "model": model, "prompt": prompt,
            "size_requested": size, "output": out.name}
    (ARCHIVE / f"v{version}.json").write_text(
        json.dumps(meta, ensure_ascii=False, indent=2))
    return out


original = pathlib.Path("bottle-original.png")   # Already compressed so the long edge is ≤ 2048

# Round 1: Change to a light gray background
v1 = edit_round(1, "hy-image-v3.5-preview-2k",
                "把瓶身背后的背景换成干净的浅灰色,瓶身大小、位置和标志保持不变",
                [to_data_uri(original)], "2048x1152", timeout=120)

# Round 2: Use round 1's output as the base and change the lighting to come from the right
v2 = edit_round(2, "hy-image-v3.5-preview-2k",
                "以参考图为底,改为从画面右侧打光,保持浅灰背景、瓶身大小、位置和标志不变",
                [to_data_uri(v1)], "2048x1152", timeout=120)

# Round 3: Image one is the current frame, image two is the original; upscale to 4K
v3 = edit_round(3, "hy-image-v3.5-preview-4k",
                "图一是当前画面,图二是原稿。以图一为底,保留图一的构图、浅灰背景和右侧打光,"
                "按图二恢复瓶身标签的原始颜色",
                [to_data_uri(v2), to_data_uri(original)], "3840x2160", timeout=240)

print("终版:", v3)

In the script, if raise_for_status fails, no new version is written, so the archive always keeps the most recent completed result. Before uploading two images in round 3, it’s a good idea to check whether the total size is close to the recommended 6 MB transfer limit.


4 Hy-Image 3.5 Preview: Timeouts, Failures, and Costs

4.1 Timeout settings for Tencent Hunyuan 4K reference-image requests

APIYI’s FAQ reports that 4K reference-image image-to-image samples take about 21–55 seconds. If a 4K image is returned as Base64, the sample response body can be as large as about 26.4 MB. You can set client timeouts based on the table below:

Scenario Recommended client timeout Notes
2K tier At least 120 seconds Corresponds to rounds 1 and 2
4K tier, URL response At least 240 seconds Corresponds to round 3; recommended approach
4K tier, Base64 response 360 seconds Large response body, long download time

For consecutive edits, prefer CDN URLs to reduce response payload, then have the server archive the images and instructions.

4.2 How to fall back after a failure or timeout

If a synchronous call drops, a generation that the server has already completed may still be billed. So don’t resend immediately after a timeout. First check the platform logs to confirm whether this round has already completed: if it has, retrieve and archive the generated image; if it truly hasn’t, resend the same round starting from the most recently completed version. This helps you avoid paying twice for the same round.

4.3 Cost estimate for three consecutive image edits

Under APIYI’s Default group, the two tiers are priced at $0.022 and $0.030 per image, respectively, and both models are also listed in the SVIP group. Within the same tier, image size, number of reference images, and response format don’t affect the unit price. So this article’s workflow is two 2K images plus one 4K image, totaling $0.074 at Default list pricing.

usage in the response is just a placeholder field; actual billing is based on the platform billing records. Timeout-related resends and discarded intermediate versions should also be included in your budget.

💰 Cost tip: During the early prompt-testing phase, use the 2K tier for everything. Once you’ve confirmed the visual direction, switch to 4K for the final version. You can verify specific group pricing in APIYI’s model price list at apiyi.com.

5 Common Questions About Continuous Image Editing with Hy-Image 3.5 Preview

Q1: Does APIYI remember the image generated in the previous round?

No. Every request is an independent single-turn reference image edit. For continuous editing, your application needs to put the previous round’s output image into this round’s `images` and spell out all still-valid requirements in the instruction.

Q2: What should I do if I get an error when passing back b64_json?

The default `b64_json` doesn’t include a prefix, so you need to prepend `data:image/png;base64,` first. Alternatively, you can pass `response_format: “url”` to send back a direct link instead. Use the free quota on APIYI apiyi.com to get a single round working first, then chain multiple rounds.

Q3: Why did the second round’s output turn into a square image?

Because you didn’t pass `size`, the output fell back to the default 2048×2048 square image, so the framing got re-composed. Pass the same aspect-ratio size explicitly every round, for example `2048×1152`.

Q4: With multiple reference images, how does the model tell what each one is for?

Put the version to be edited in the first position and the original artwork or brand image in the second. In the instruction, use “Image 1” and “Image 2” to assign roles clearly, for example “Use Image 1 as the base and restore the logo according to Image 2.”

Q5: Can a CDN direct link be processed directly in a front-end canvas?

Direct links can be used for display. For cross-origin script reads and canvas processing, it’s better to have your application’s server fetch the image first and then serve it to the front end.

Q6: Is there any measured data for this three-round workflow?

No. The three rounds in this article are an example of the reference-image re-upload approach; the timing data comes from samples disclosed in the platform’s FAQ. Before going live, run a small-scale test with your own images on APIYI apiyi.com.


6 Tencent Hunyuan Hy-Image 3.5 Preview Final Delivery Acceptance

Once you have the third-round final version, overlay all three versions at the same scale and check the following five items in order:

  1. Background: Is it still light gray?
  2. Light source: Is the lighting still coming from the right?
  3. Label: Are the colors consistent with the original artwork?
  4. Bottle shape: Have the size and position stayed the same?
  5. Edges: Is the boundary between the bottle and the background clean?

At the same time, verify that the actual width and height recorded in the archive are 3840×2160. If all five items pass, you can export and deliver. If any item fails, take the corresponding version from the archive as the base image and redo just that item for one round. Following this workflow, you can plug Tencent Hunyuan Hy-Image 3.5 Preview’s continuous image editing into a stable production pipeline on APIYI apiyi.com.


📚 References

  1. APIYI Reference Image API and OpenAPI: Field, size, and format details for Tencent Hunyuan reference-image generation

    • Link: docs.apiyi.com/api-capabilities/hunyuan-image/image-edit
    • Description: Rules for the images field, size-tier area, the invalid_size error, and the approach behind the three-round example
  2. APIYI FAQ: Latency, timeout, and billing details for Hunyuan image

    • Link: docs.apiyi.com/api-capabilities/hunyuan-image/faq
    • Description: 4K latency samples, client timeout recommendations, direct CDN link usage, and details on the usage field
  3. APIYI Model Pricing: Unit prices for models by group

    • Link: docs.apiyi.com/models/index
    • Description: Check the listed prices for the two tiers under the Default and SVIP groups

Author: APIYI Technical Team
Technical Discussion: Feel free to contact us through the APIYI apiyi.com homepage to discuss reference image editing integration issues.

Leave a Comment