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.
- 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 - 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 - 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"])) - 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)
Responses endpoint: images inside a conversation
When you want a chat model to understand the request before it renders, or to keep revising the same image over several turns, use the Responses endpoint: the mainline model calls image generation as a tool, and the image comes back as a Base64 result on a stream event.
- 01
Build the request body
Four things matter: put image_generation in tools and name the image model; set tool_choice to the same type so it renders instead of replying in text; turn stream on, since image generation is far slower than text and streaming keeps events flowing and the connection alive; turn store off so the turn is not retained server-side. The image description goes into input as a user message, and instructions only states the job. The snippet below is bash and only confirms the request goes through: it prints the whole event stream, image Base64 included, to your terminal, so save images with the Python example in the next step (on Windows too).
terminal curl https://api.xylemnode.com/v1/responses \ -H "Authorization: Bearer sk-your-key" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-6.1-sol", "instructions": "Generate the requested image.", "input": [ { "role": "user", "content": "A ginger cat in a spacesuit standing on the moon, blue Earth in the distance, cinematic lighting, photorealistic." } ], "tools": [{ "type": "image_generation", "model": "gpt-image-2.5-flare" }], "tool_choice": { "type": "image_generation" }, "stream": true, "store": false }' - 02
Pull the image out of the stream
The response is SSE: read the JSON after each data: line, keep only events whose type is response.output_item.done, and find the one whose item.type is image_generation_call — its item.result is the finished image in Base64. Decode it and write it to a file. Note that result is a long string, not a URL, so don't treat it as an image address or print it to your terminal.
python import base64 import json import requests PROMPT = "A ginger cat in a spacesuit standing on the moon, blue Earth in the distance, cinematic lighting, photorealistic." payload = { "model": "gpt-6.1-sol", "instructions": "Generate the requested image.", "input": [{"role": "user", "content": PROMPT}], "tools": [{"type": "image_generation", "model": "gpt-image-2.5-flare"}], "tool_choice": {"type": "image_generation"}, "stream": True, "store": False, } with requests.post( "https://api.xylemnode.com/v1/responses", headers={"Authorization": "Bearer sk-your-key"}, json=payload, stream=True, timeout=600, ) as response: response.raise_for_status() for raw in response.iter_lines(): if not raw: continue line = raw.decode("utf-8") if not line.startswith("data:"): continue chunk = line[5:].strip() if chunk == "[DONE]": break event = json.loads(chunk) if event.get("type") != "response.output_item.done": continue item = event.get("item") or {} if item.get("type") == "image_generation_call" and item.get("result"): with open("moon-cat.png", "wb") as file: file.write(base64.b64decode(item["result"])) print("saved moon-cat.png") - 03
Swap models, tune the output
Pick the image model to suit the job: gpt-image-2.5-flare is faster, gpt-image-2.5-sunburst is more precise but slower — go by the model list in your console. Output options live on the same object inside the request body's tools: size sets the frame, quality the level of detail, background can request transparency (only png / webp support it) and output_format picks the file type. Add partial_images (1–3) and you'll receive a few preview drafts while it renders, as response.image_generation_call.partial_image events.
json { "tools": [{ "type": "image_generation", "model": "gpt-image-2.5-flare", "size": "1024x1536", "quality": "high", "background": "transparent", "output_format": "png", "partial_images": 2 }] }
Parameters
- Endpoint
https://api.xylemnode.com/v1/responses- Method
POST (Bearer auth)- Mainline model
gpt-6.1-sol- Tool
image_generation- Image model
gpt-image-2.5-flare · gpt-image-2.5-sunburst- Result field
image_generation_call.result (Base64)