4Z API

Python: generate & edit images with gpt-image-2.6 (incl. SVG / GIF output)

Models: gpt-image-2.6-flare (fast iteration) and gpt-image-2.6-sunburst (detailed visual work). Endpoints: POST /v1/images/generations (text-to-image) and POST /v1/images/edits (editing) — request bodies are OpenAI Images API compatible.

from openai import OpenAI
import base64

client = OpenAI(
    base_url="https://4zapi.com/v1",
    api_key="sk-xxx",
)

1. Generate an image (minimal)

result = client.images.generate(
    model="gpt-image-2.6-flare",
    prompt="Product still life: matte black mechanical keyboard, studio lighting, no text",
    n=1,
    size="1536x1024",
)

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

2. Image complexity (new in 2.6)

complexity controls how much the model plans before rendering, independently of quality. It has no separate fee. Defaults to high when omitted.

result = client.images.generate(
    model="gpt-image-2.6-sunburst",
    prompt="Children's book illustration: paper-cut football trophy scene with a CHAMPIONS banner",
    complexity="medium",   # low / medium / high
    quality="medium",
)
  • low: focused edits (background swaps, signage changes), lower latency, fewer side changes.
  • high: dense text, complex layouts, object relationships; higher latency, may introduce unwanted changes.

3. SVG output (new in 2.6)

Set output_format="svg" — generations only, n=1 — and send the svg object to pick the authoring model.

result = client.images.generate(
    model="gpt-image-2.6-sunburst",
    prompt="Bakery logo: golden wheat sprigs with a handwritten wordmark, flat vector style",
    output_format="svg",
    n=1,
    quality="medium",
    extra_body={
        "svg": {
            "model": "gpt-6-luna",
            "reasoning": {"effort": "low"},
        }
    },
)

with open("logo.svg", "wb") as f:
    f.write(base64.b64decode(result.data[0].b64_json))  # UTF-8 XML after decoding

Or as a plain JSON body:

{
  "model": "gpt-image-2.6-sunburst",
  "prompt": "Bakery logo: golden wheat sprigs with a handwritten wordmark, flat vector style",
  "output_format": "svg",
  "n": 1,
  "svg": { "model": "gpt-6-luna", "reasoning": { "effort": "low" } }
}
  • Billing = reference image at the image model rate + SVG tokens at the author model rate; the response's svg_usage reports the author model usage.
  • SVG does not support streaming, partial_images, prompt_rewriter, or output_compression; the edits endpoint does not support SVG.
  • Error SVG generation requires '***.model': the svg object was missing (or not passed through). Add svg.model and retry; if it persists, contact support to confirm passthrough.

4. Animated GIF output (new in 2.6)

Set output_format="gif" — generations only. Describe the subject, the motion, and the loop in the prompt.

result = client.images.generate(
    model="gpt-image-2.6-sunburst",
    prompt="A monkey in a green coat lifts a glowing lantern, blinks, and returns to its starting pose, seamless loop",
    output_format="gif",
    n=1,
    size="1024x1024",
    frame_count=9,          # 2-16, default 9
    frame_duration_ms=200,  # ms per frame, default 200, minimum 20
)

with open("monkey.gif", "wb") as f:
    f.write(base64.b64decode(result.data[0].b64_json))
  • size describes each frame; if frame count × frame size × n exceeds the pixel budget, reduce frame_count, the frame size, or n.
  • GIF does not support mask, streaming, partial_images, or custom output_compression.

5. Markup-guided edits (new in 2.6)

Circle the region to change in a transparent PNG and describe the change in prompt. The markup layer must match the first image's dimensions (after orientation) and contain transparent pixels.

result = client.images.edit(
    model="gpt-image-2.6-flare",
    image=open("kitchen.webp", "rb"),
    markup=open("markup-vase.png", "rb"),
    quality="medium",
    prompt=(
        "Recolor the striped vase inside the red circle to solid cobalt blue ceramic. "
        "Keep its shape, the dried stems, and the rest of the kitchen unchanged. "
        "Remove the red circle from the finished photo."
    ),
)

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

Equivalent curl (multipart):

curl https://4zapi.com/v1/images/edits \
  -H "Authorization: Bearer $API_KEY" \
  -F model=gpt-image-2.6-flare \
  -F image=@kitchen.webp \
  -F markup=@markup-vase.png \
  -F quality=medium \
  -F 'prompt=Recolor the striped vase inside the red circle to solid cobalt blue ceramic.' \
  | jq -r '.data[0].b64_json' | base64 --decode > vase.png
  • markup applies to the first input image only (additional images are references); max 16,777,216 pixels and 50 MB per file.
  • markup cannot be combined with mask or prompt_rewriter.
  • The edits endpoint does not support SVG output.

Common errors

Error Cause & fix
SVG generation requires '***.model' SVG output is missing svg.model (or it was not passed through); add the svg object and retry
GIF / SVG params have no effect frame_count / frame_duration_ms only apply with output_format=gif; the svg object only applies with output_format=svg
output_format=svg rejected on edits SVG is supported on POST /v1/images/generations only