Docs / Image Generation
Image Generation
Generate images from text prompts through the OpenAI-compatible POST /v1/images/generations endpoint. The image comes back in the same response, as base64 data for the GPT Image models and as a download link for Seedream 4.5; no polling required.
#Models
| Model ID | Family | Notes |
|---|---|---|
| gpt-image-2 | OpenAI | Native up to 4K, image output free |
| gpt-image-2.6 | OpenAI | Stills, animated GIF and SVG, transparent backgrounds, image editing; $0.04 per image |
| seedream-4.5 | ByteDance Seedream | 2K and 4K images, image to image with reference pictures, sets of related images; $0.05 per image |
Image output is free on RelayDance: you pay only for the input. Faces and portraits are supported, and tasks start immediately with no queue.
gpt-image-2.6 is billed per image instead: a flat $0.04 for each image returned, whatever the size or format. It adds animated GIF and SVG output, transparent backgrounds and image editing; see GPT Image 2.6 below.
seedream-4.5 is billed per image too: $0.05 for each image it produces, at 2K or 4K. Reference pictures are free, and a set of related images costs $0.05 for each image actually returned. See Seedream 4.5 below.
#API usage
cURL
curl https://relaydance.com/v1/images/generations \
-H "Authorization: Bearer $RELAYDANCE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A serene Japanese garden with cherry blossoms, watercolor style",
"n": 1
}' | jq -r '.data[0].b64_json' | base64 --decode > garden.pngPython
import base64, os, requests
response = requests.post(
"https://relaydance.com/v1/images/generations",
headers={
"Authorization": f"Bearer {os.environ['RELAYDANCE_API_KEY']}",
"Content-Type": "application/json",
},
json={
"model": "gpt-image-2",
"prompt": "A serene Japanese garden with cherry blossoms, watercolor style",
"n": 1,
},
timeout=300,
)
response.raise_for_status()
image = response.json()["data"][0]
with open("garden.png", "wb") as f:
f.write(base64.b64decode(image["b64_json"]))OpenAI SDK
import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.RELAYDANCE_API_KEY,
baseURL: "https://relaydance.com/v1",
});
const res = await client.images.generate({
model: "gpt-image-2",
prompt: "A futuristic city at dusk, cinematic lighting",
n: 1,
});
const b64 = res.data?.[0]?.b64_json;
if (b64) fs.writeFileSync("city.png", Buffer.from(b64, "base64"));#Response
{
"created": 1794605056,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA...",
"revised_prompt": "A serene Japanese garden with cherry blossoms, watercolor style"
}
]
}With the GPT Image models the image arrives inline as base64 in data[].b64_json: decode it and write the bytes to a file. They do not provide hosted image URLs, so do not rely on response_format: "url" with them. Seedream 4.5 is different: it returns a download link by default; see its response below.
#Request parameters
| Parameter | Type | Description |
|---|---|---|
model | string | Image model ID |
prompt | string | Text description of the image to generate |
n | integer | Number of images to generate. Default: 1 |
size | string | Optional output size, model-dependent (e.g. "1024x1024") |
#GPT Image 2.6: stills, GIF and SVG
gpt-image-2.6 runs on the same endpoint and adds new outputs: besides PNG, JPEG and WebP it can return an animated GIF or an SVG, render on a transparent background, and edit an existing picture. Every image returned costs a flat $0.04, whatever the size, quality or format. Asking for n images costs n times that, and failed requests are not charged.
Still image
curl https://relaydance.com/v1/images/generations \
-H "Authorization: Bearer $RELAYDANCE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.6",
"prompt": "A paper kite flying over green hills, flat illustration",
"size": "1024x1024"
}' | jq -r '.data[0].b64_json' | base64 --decode > kite.pngAnimated GIF
Set output_format to gif and describe the motion in the prompt. The price is the same $0.04.
curl https://relaydance.com/v1/images/generations \
-H "Authorization: Bearer $RELAYDANCE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.6",
"prompt": "A candle flame flickering, simple flat illustration",
"output_format": "gif"
}' | jq -r '.data[0].b64_json' | base64 --decode > candle.gifThe service picks the frame count, timing and dimensions itself. In our tests a GIF comes back as a looping animation of 8 or 9 frames at roughly 160 to 350 ms per frame. Frames are small, about 170,000 to 190,000 pixels in total (for example 414x413, 508x337 or 217x883): size only nudges the aspect ratio. frame_count and frame_duration_ms are not supported and are ignored.
Python
This sample saves whatever format comes back, taking the file extension from the response.
import base64, os, requests
resp = requests.post(
"https://relaydance.com/v1/images/generations",
headers={"Authorization": f"Bearer {os.environ['RELAYDANCE_API_KEY']}"},
json={
"model": "gpt-image-2.6",
"prompt": "A candle flame flickering, simple flat illustration",
"output_format": "gif", # png (default), jpeg, webp, gif or svg
"n": 1,
},
timeout=300,
)
resp.raise_for_status()
body = resp.json()
ext = body.get("output_format") or "png"
for i, item in enumerate(body["data"]):
with open(f"image_{i}.{ext}", "wb") as f:
f.write(base64.b64decode(item["b64_json"]))
print(f"saved image_{i}.{ext}", item.get("width"), item.get("height"))Edit an image (image to image)
POST /v1/images/edits takes a multipart form instead of JSON: the source picture in the image file field, plus model and prompt. output_format works here too (add -F output_format=gif to turn a still picture into an animation). Same price: $0.04 per image returned.
curl https://relaydance.com/v1/images/edits \
-H "Authorization: Bearer $RELAYDANCE_API_KEY" \
-F model=gpt-image-2.6 \
-F [email protected] \
-F prompt="Turn this picture into a watercolor painting" \
| jq -r '.data[0].b64_json' | base64 --decode > edited.pngResponse
{
"created": 1794604905,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUgAA...",
"revised_prompt": "A paper kite flying over green hills, flat illustration",
"width": 1024,
"height": 1024
}
],
"output_format": "png",
"size": "1024x1024",
"quality": "auto",
"background": "auto",
"usage": { "input_tokens": 10, "output_tokens": 1056, "total_tokens": 1066 }
}width and height are the real pixel dimensions of the returned file, and output_format is the format actually produced. usage is informational: billing is per image, not per token.
Parameters
| Parameter | Type | Description |
|---|---|---|
model | string | gpt-image-2.6 |
prompt | string | What to draw. For a GIF, describe the motion too |
n | integer | Number of images. Default: 1. Each image returned is billed |
size | string | 1024x1024, 1536x1024, 1024x1536, 2048x2048, or a custom WIDTHxHEIGHT such as 1280x720 or 1920x1088. Width and height must both be multiples of 16 and the total pixel count between 655,360 and 8,294,400, so 512x512 and 1920x1080 are rejected. Omit it or pass auto to let the service choose |
output_format | string | png (default), jpeg, webp, gif or svg |
background | string | Set to transparent for a transparent background; use it with png or webp |
quality | string | Accepted for compatibility (low, medium, high). It does not change the price |
image | file | Edits endpoint only: the source picture, sent as a multipart file field |
response_format | string | Not supported: the image is always returned as base64 in b64_json |
frame_count, frame_duration_ms | integer | Not supported: ignored, the service chooses GIF frames and timing |
Timing and limits
- A still takes about 20 to 45 seconds, a GIF about 30 to 55 seconds and an SVG about 90 seconds. Set your HTTP client timeout to at least 180 seconds.
- The call is synchronous: the image is in the response to the same request. There is no streaming, no partial images and no batch mode.
- Choose the file extension from the
output_formatfield of the response, or from the first bytes of the file, rather than from what you asked for. - Chat clients can use it too:
gpt-image-2.6also answers onPOST /v1/chat/completions, where the reply is a Markdown image with the picture embedded as a data URI. Each reply costs the same $0.04.
#Seedream 4.5: 2K and 4K images, reference pictures and image sets
seedream-4.5 is ByteDance's Seedream 4.5 on the same JSON endpoint. It draws at 2K or 4K, can work from one or more reference pictures, and can return a set of related images in one call. Every image it produces costs $0.05, whatever the size. Reference pictures are free. Requests that fail, including prompts or results rejected by the standard content filter, are not charged.
Text to image
The response carries a download link, so the sample pipes it to a second curl that saves the JPEG.
curl https://relaydance.com/v1/images/generations \
-H "Authorization: Bearer $RELAYDANCE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-4.5",
"prompt": "A lighthouse on a rocky coast at golden hour, oil painting",
"size": "2K"
}' | jq -r '.data[0].url' | xargs curl -s -o lighthouse.jpgReference pictures (image to image)
Put the pictures in image: one URL, an array of URLs, or data:image/png;base64,... strings. Refer to them in the prompt as image 1, image 2 and so on. URLs must be publicly downloadable: a host that refuses the download (for example with 403) makes the request fail. There is no multipart edits endpoint for this model; image to image always goes through POST /v1/images/generations.
import os, requests
resp = requests.post(
"https://relaydance.com/v1/images/generations",
headers={"Authorization": f"Bearer {os.environ['RELAYDANCE_API_KEY']}"},
json={
"model": "seedream-4.5",
"prompt": "The cat from image 2 wearing the red hat from image 1, sitting on a windowsill, photo",
# public image URLs or data:image/...;base64,... strings
"image": ["https://example.com/hat.jpg", "https://example.com/cat.jpg"],
"size": "2K",
},
timeout=300,
)
resp.raise_for_status()
item = resp.json()["data"][0]
with open("cat.jpg", "wb") as f:
f.write(requests.get(item["url"], timeout=120).content)
print("saved cat.jpg", item["size"])A set of related images
Set sequential_image_generation to auto and cap the set with sequential_image_generation_options.max_images (1 to 15). The model decides how many images the prompt calls for, up to that cap, and you pay $0.05 for each image actually returned. n is ignored by this model: without these two fields every call returns one image.
import os, requests
resp = requests.post(
"https://relaydance.com/v1/images/generations",
headers={"Authorization": f"Bearer {os.environ['RELAYDANCE_API_KEY']}"},
json={
"model": "seedream-4.5",
"prompt": "A set of three illustrations of the same red fox: in a spring meadow, in a summer forest, in autumn leaves",
"sequential_image_generation": "auto",
"sequential_image_generation_options": {"max_images": 3},
"size": "2K",
},
timeout=300,
)
resp.raise_for_status()
for i, item in enumerate(resp.json()["data"]):
if "url" in item:
with open(f"fox_{i}.jpg", "wb") as f:
f.write(requests.get(item["url"], timeout=120).content)
print(f"saved fox_{i}.jpg", item["size"])Response
{
"model": "seedream-4-5-251128",
"created": 1795612345,
"data": [
{
"url": "https://...",
"size": "2304x1728"
}
],
"usage": { "generated_images": 1, "output_tokens": 15552, "total_tokens": 15552 }
}data[].url is a direct link that stays valid for 24 hours: download the file right away. Pass response_format: "b64_json" to get base64 in data[].b64_json instead. size is the real pixel size of each image, and usage.generated_images is the number of images you are billed for.
Parameters
| Parameter | Type | Description |
|---|---|---|
model | string | seedream-4.5 |
prompt | string | What to draw. When you pass reference pictures, refer to them as image 1, image 2 and so on |
size | string | 2K or 4K lets the model pick the aspect ratio from the prompt (for example 2304x1728 or 2848x1600 at 2K, 4704x3520 at 4K). For a fixed shape pass WIDTHxHEIGHT with at least 3,686,400 pixels, such as 2048x2048 or 2560x1440. Smaller sizes such as 1024x1024 are rejected |
image | string or array | Reference pictures: public URLs or data:image/...;base64,... strings. Not billed |
sequential_image_generation | string | auto to allow a set of related images; disabled (the default) for one image |
sequential_image_generation_options | object | {"max_images": 1 to 15}: the most images the set may contain |
response_format | string | url (default, link valid for 24 hours) or b64_json |
watermark | boolean | Defaults to false: images come back without a watermark. Pass true to stamp a small "AI generated" mark in the bottom right corner |
n | integer | Ignored: use sequential_image_generation for several images |
Timing and limits
- A 2K image takes about 6 to 17 seconds; a 4K image or a set of three takes about 45 seconds. Set your HTTP client timeout to at least 180 seconds.
- The call is synchronous: the images are in the response to the same request. There is no task to poll.
- The standard content filter applies to prompts, reference pictures and results. A rejected request returns an error and is not charged.
#Tips for better results
- Be specific: describe style, composition, lighting and mood in your prompt
- Name a style: keywords like "photorealistic", "watercolor", "anime" steer the output strongly
- Iterate: small prompt changes can shift results a lot; generate, adjust, repeat
source_url in metadata.content[] of a video task. See Image-to-Video.