N·00Image API

Generating images over the API

There are two ways to make images. The Images API renders straight from a description (/v1/images/generations) or edits a picture you already have (/v1/images/edits); the Responses endpoint lets a chat model call image generation as a tool, which suits revising over several turns. Same address as a text call, https://api.xylemnode.com/v1, so there's no separate image service to wire up; for the Images API, use a key whose group includes the image models.

Images API: generate and edit

If all you want is the picture, calling the image endpoints directly is the simplest route: one request returns the finished image, with no chat model in between. Generation takes a JSON body; edits upload the source image as a form. Both use Bearer auth, and each entry in the returned data array is one image in Base64.

  1. 01

    Generate from a description: /v1/images/generations

    Set model to an image model, describe the picture in prompt, and fill in size and quality as needed. The GPT Image models only return b64_json (the image in Base64), never a link, so decode it into a file. The curl below is for macOS / Linux and ends with jq and base64 to unpack the image into a file; on Windows, skip to the Python version further down.

    terminal
    curl https://api.xylemnode.com/v1/images/generations \
      -H "Authorization: Bearer sk-your-key" \
      -H "Content-Type: application/json" \
      -d '{
        "model": "gpt-image-2.5-flare",
        "prompt": "A ginger cat in a spacesuit standing on the moon, blue Earth in the distance, cinematic lighting, photorealistic.",
        "size": "1024x1536",
        "quality": "high"
      }' | jq -r '.data[0].b64_json' | base64 --decode > moon-cat.png
  2. 02

    Edit an existing image: /v1/images/edits

    Edits are uploaded as a form (multipart/form-data). Put the source image in image[] — up to 16 of them, png, webp or jpg, each under 50MB; given several, the model treats them as references and composes one image — and say what to change in prompt. To change only part of it, add a mask: a PNG with an alpha channel, the same size as the source and under 4MB, whose fully transparent areas are the ones to repaint (the model treats the mask as a guide, so the edit may not follow its outline exactly); with several sources it applies to the first. File names need the right extension (.png / .jpg / .webp). curl sets up the form encoding itself, so don't add a Content-Type header by hand.

    terminal
    curl https://api.xylemnode.com/v1/images/edits \
      -H "Authorization: Bearer sk-your-key" \
      -F "model=gpt-image-2.5-sunburst" \
      -F "image[][email protected]" \
      -F "[email protected]" \
      -F "prompt=Replace the sofa with a dark green velvet one and keep everything else the same." \
      | jq -r '.data[0].b64_json' | base64 --decode > living-room-edited.png
  3. 03

    In Python (works on Windows too)

    The same two calls in Python, with requests as the only dependency: generation sends JSON, edits upload through files, and both read the image from data[0].b64_json.

    python
    import base64
    import requests
    
    API = "https://api.xylemnode.com/v1"
    HEADERS = {"Authorization": "Bearer sk-your-key"}
    
    # Generate from a description
    result = requests.post(
        f"{API}/images/generations",
        headers=HEADERS,
        json={
            "model": "gpt-image-2.5-flare",
            "prompt": "A ginger cat in a spacesuit standing on the moon, blue Earth in the distance, cinematic lighting, photorealistic.",
            "size": "1024x1536",
            "quality": "high",
        },
        timeout=600,
    )
    result.raise_for_status()
    with open("moon-cat.png", "wb") as file:
        file.write(base64.b64decode(result.json()["data"][0]["b64_json"]))
    
    # Edit an existing image (the mask is optional)
    with open("living-room.png", "rb") as image, open("mask.png", "rb") as mask:
        result = requests.post(
            f"{API}/images/edits",
            headers=HEADERS,
            data={
                "model": "gpt-image-2.5-sunburst",
                "prompt": "Replace the sofa with a dark green velvet one and keep everything else the same.",
            },
            files=[
                ("image[]", ("living-room.png", image, "image/png")),
                ("mask", ("mask.png", mask, "image/png")),
            ],
            timeout=600,
        )
    result.raise_for_status()
    with open("living-room-edited.png", "wb") as file:
        file.write(base64.b64decode(result.json()["data"][0]["b64_json"]))
  4. 04

    Common parameters

    These work on both endpoints. size also takes a custom width and height: both sides multiples of 16, an aspect ratio between 1:3 and 3:1, no side longer than 3840, and 655,360 to 8,294,400 pixels in total (1024x640 up to 3840x2160, for example); sizes above 2560x1440 are still experimental. Pick the image model to suit the job: gpt-image-2.5-flare is fast and fine for everyday renders, gpt-image-2.5-sunburst is more detailed and suits edits — go by the model list in your console.

    n
    Images per request, 1–10
    size
    1024x1024 · 1536x1024 · 1024x1536 · auto
    quality
    low · medium · high · auto (the 2.5 models add xhigh · max)
    background
    auto · opaque · transparent (transparent needs png or webp)
    output_format
    png · jpeg · webp
    output_compression
    0–100, jpeg / webp only

Endpoints at a glance

Generate
POST https://api.xylemnode.com/v1/images/generations (JSON)
Edit / compose
POST https://api.xylemnode.com/v1/images/edits (multipart)
Image models
gpt-image-2.5-flare · gpt-image-2.5-sunburst
Result field
data[].b64_json (Base64)
Get API Key