WaveSpeedAI

Z-Image-Turbo Inpainting API: Mask Workflow + Artifact Fixes

Complete Z-Image-Turbo inpainting guide. Learn mask creation, natural-language prompts, seamless blending techniques, and how to fix common artifacts. $0.02/image.

By Dora9 min read
Z-Image-Turbo Inpainting API: Mask Workflow + Artifact Fixes

Hey, I’m Dora. A glare spot on a product photo can turn a five-minute fix into a project. I don’t want to rebuild the whole image when a small, careful edit would do. That makes inpainting appealing—but before I put an API into my routine, I want to know exactly what the mask changes, what the request needs, and how to spot a bad edge.

What is AI Inpainting?

Inpainting is the clean-up crew of image editing. You hide a region with a mask, describe what you want there instead (or that you want nothing), and the model fills it in to match the rest of the image.

What I like about inpainting is that it feels surgical. You’re not asking the model to invent a whole scene, just to respect the one you already have. When it goes well, the edit disappears. When it doesn’t, you see seams, weird textures, or a small “AI fog” where the patch lives.

How Z-Image-Turbo Inpaint Works

The intended workflow is straightforward: provide a source image, a mask, and a prompt. The mask marks where the edit should happen; the surrounding image supplies context. It is still worth comparing the output with the original outside the mask. A mask is an instruction to the model, not a guarantee that every protected pixel will remain identical.

Two details deserve attention:

  • The mask edge: start with a clear boundary. If the result has a visible seam, test a slightly wider mask or a narrow feathered edge—one change at a time.
  • The prompt: start short and literal. Describe the replacement and the texture or lighting it needs to match.

Availability check, November 18, 2026: The WaveSpeed inpaint model page and its dedicated API documentation linked in the earlier version of this article both returned 404 during review. I could not verify a live endpoint, its current input schema, or its price. Check the current WaveSpeed model catalog before using the request example below.

API Workflow

I keep the workflow simple: preserve the source, mask only the area I want changed, and check the input files before submitting anything.

Required Inputs: Image + Mask + Prompt

The previously indexed documentation for this endpoint named three request fields: image, mask_image, and prompt. Confirm those names on a live model page before running a request. WaveSpeed’s current general API documentation says that model inputs vary by endpoint.

  • Image: use the original image at its intended working size.
  • Mask: make it the same width and height as the image. The earlier inpaint documentation described white as the area to edit and black as the area to preserve; recheck that convention if the endpoint returns.
  • Prompt: describe the desired fill. For example: “Remove the glare and continue the matte blue surface.”

I would leave guidance, strength, steps, seed, and output-size fields out of the request until the live endpoint schema confirms them. Controls exposed by another Z-Image workflow do not automatically belong to this one.

Mask Format Requirements

Begin with a black-and-white mask. A white patch should cover the glare or object you want changed; the rest should be black. If the current endpoint accepts grayscale masks, you can test a narrow gray transition at the edge when a hard boundary leaves a seam. That is different from making the whole mask soft.

Here is a small, self-contained pair of input files. Save and run this Python script to create source.png and mask.png. The blue rectangle is the source; the white spot is the area the mask selects. These are test inputs, not a claimed ​API​​ result.

import struct
import zlib
from pathlib import Path

width = height = 256

def write_png(path, pixel):
    rows = b"".join(
        b"\0" + b"".join(bytes(pixel(x, y)) for x in range(width))
        for y in range(height)
    )

    def chunk(kind, data):
        checksum = zlib.crc32(kind + data) & 0xffffffff
        return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", checksum)

    png = (
        b"\x89PNG\r\n\x1a\n"
        + chunk(b"IHDR", struct.pack(">IIBBBBB", width, height, 8, 2, 0, 0, 0))
        + chunk(b"IDAT", zlib.compress(rows))
        + chunk(b"IEND", b"")
    )
    Path(path).write_bytes(png)

def source(x, y):
    if (x - 130) ** 2 + (y - 95) ** 2 < 17 ** 2:
        return (245, 245, 240)  # glare
    if 55 < x < 200 and 45 < y < 210:
        return (55, 90, 130)    # blue surface
    return (190, 180, 160)      # background

def mask(x, y):
    value = 255 if (x - 130) ** 2 + (y - 95) ** 2 < 23 ** 2 else 0
    return (value, value, value)

write_png("source.png", source)
write_png("mask.png", mask)

Both files are 256 × 256 PNGs. Preview them together before uploading: the white circle should cover the glare with a little room around it. For a real photo, keep the same checks—matching dimensions, correct position, and no accidental white marks elsewhere.

Python Implementation

The earlier article described a multipart request with image and mask files attached directly. WaveSpeed’s current upload flow instead returns URLs for local files, and its general task API accepts JSON. The documented CLI commands are:

wavespeed upload ./source.png
wavespeed upload ./mask.png

Keep the two returned URLs. ​Only after a live inpaint model page confirms its model ID and the ​image​​, ​mask_image​, and ​prompt​​​ fields​, this minimal Python example can submit the request and retrieve its result:

import os
import time
import requests

model_id = os.environ["WAVESPEED_INPAINT_MODEL_ID"]
headers = {"Authorization": f"Bearer {os.environ['WAVESPEED_API_KEY']}"}
payload = {
    "image": os.environ["SOURCE_URL"],
    "mask_image": os.environ["MASK_URL"],
    "prompt": "Remove the glare and continue the matte blue surface.",
}

response = requests.post(
    f"https://api.wavespeed.ai/api/v3/{model_id}",
    headers=headers,
    json=payload,
    timeout=(10, 60),
)
response.raise_for_status()
task = response.json()["data"]
task_id = task["id"]
print("Submitted task:", task_id)

while True:
    response = requests.get(
        f"https://api.wavespeed.ai/api/v3/predictions/{task_id}/result",
        headers=headers,
        timeout=30,
    )
    response.raise_for_status()
    result = response.json()["data"]

    if result["status"] == "completed":
        print("Output:", result.get("outputs", []))
        break
    if result["status"] in {"failed", "cancelled", "timeout", "deleted"}:
        raise RuntimeError(result.get("error") or result["status"])
    time.sleep(2)

Install requests if needed with python -m pip install requests. Set the four environment variables from your account and the two upload results. Do not reuse the old model ID just because it appears in an earlier article. If submission loses its connection before you receive a task ID, check task history before submitting again; the current API guidance says an uncertain submission may still have created a billable task.

Writing Effective Inpaint Prompts

I start with shorter, more literal prompts. The mask defines the area; the prompt describes what belongs there.

Removal Prompts (“clean surface”)

For a removal, describe the surface that should continue through the masked area: “Remove the reflection; continue the matte blue finish,” or “Remove the dust specks; preserve the surrounding wood grain.”

Lighting matters when a patch looks pasted on. “Match the soft light from the right” gives the model a clearer target than “make it realistic.”

Replacement Prompts (describe new content)

For swaps, be specific but compact:

  • “Replace the red mug with a plain white ceramic cup of similar size and angle.”
  • “Fill the gap with concrete matching the surrounding texture.”

I avoid adjectives that invite an unrelated style—“beautiful” and “cinematic” do little to define the replacement. “Similar size” and “same angle” are more useful instructions.

Context-Aware Prompting

When the scene has warm light, soft shadows, or shallow depth of field, name the feature the patch must match. “Match the existing warm light and soft shadow to the left” is more actionable than “realistic.”

If the surrounding texture is complicated, try a smaller mask first. Compare the output with the original at the edge and outside the mask before deciding whether a second pass is worthwhile.

Practical Applications

These are the cases where I would consider a masked edit before a larger rewrite.

Product Photo Cleanup

For a scuff, backdrop crease, or lamp hotspot, mask the flaw and describe the surface underneath it. Review the result at full size. A patch can look clean in a thumbnail while still changing a product edge or printed label.

Remove Unwanted Objects

For an object against brick or pavement, include the continuation you expect: “continue the brick pattern” or “extend the sidewalk texture.” If the object covers a complex boundary, one large mask may give the model too much to invent. Try a tighter region and inspect the join.

Background Replacement

Full background swaps are touchier. Hair, thin product edges, and natural shadows all make the boundary harder to hide. If the task is to extend the canvas rather than replace an area inside it, the Z-Image edit workflow guide explains that distinction.

Fixing Common Artifacts

When something looks “off,” I check the boundary, the light, and the texture separately. Changing all three at once makes it hard to tell what helped.

Visible Seams at Mask Edges

Symptom: a faint outline where the patch meets the original.

What to try:

  • Check that the mask lines up with the source pixel for pixel.
  • Expand the white region slightly so the model can paint across the old edge.
  • If the endpoint supports grayscale masks, compare that hard edge with a narrow feathered edge.

Keep the prompt and other inputs the same for this comparison. If the seam moves with the mask edge, you have a useful clue.

Color/Lighting Mismatch

Symptom: the patch has the right shape but the wrong light.

What to try:

  • Name the existing light direction and warmth in the prompt.
  • Compare the generated file with the ungraded source. If the source already has a strong grade, test the edit before applying that grade.
  • Check whether the mismatch is present in the returned image or appears only after your export step.

Texture Inconsistency

Symptom: a surface looks smudged or too uniform.

What to try:

  • Describe the texture you want continued: “fine canvas texture” or “subtle wood grain.”
  • Reduce the masked region if it covers more than the flaw.
  • Compare one revised mask or prompt at a time against the same source.

Why this matters to me: inpainting is most useful when a small edit stays small. Clear prompts and careful masks help, but the result still needs an edge check. Until the Z-Image-Turbo inpaint endpoint is listed and documented again, I would prepare the files and test plan, then confirm the live schema and price before making a production request.


Previous posts:

Share