Generate images
Image generation uses the OpenAI Images API and returns the result synchronously; one image usually takes 30–60 seconds. Code that already uses an OpenAI SDK only needs base_url set to https://pxrouter.com/v1, a PxRouter key and one of the model names below.
Create an image key
In API Keys, create a key and pick the GPT 图片 group. Image models are only in that group: a key in a video group fails with no available channel. One account can hold video keys and image keys side by side, sharing one balance.
Generate
POST /v1/images/generations
curl https://pxrouter.com/v1/images/generations \
-H "Authorization: Bearer $PXROUTER_IMAGE_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2.5-flare",
"prompt": "a corgi wearing an astronaut helmet, studio lighting",
"n": 1,
"size": "1024x1024",
"response_format": "b64_json"
}'
from openai import OpenAI
import base64
client = OpenAI(base_url="https://pxrouter.com/v1", api_key="sk-...")
result = client.images.generate(
model="gpt-image-2.5-flare",
prompt="a corgi wearing an astronaut helmet, studio lighting",
size="1024x1024",
response_format="b64_json",
)
with open("corgi.png", "wb") as f:
f.write(base64.b64decode(result.data[0].b64_json))
| Field | Notes |
|---|---|
model |
Model name, required; see Models |
prompt |
Image description, required |
n |
Number of images, default 1 |
size |
Image size, for example 1024x1024 |
response_format |
Use b64_json; see below |
With "response_format": "b64_json", every image in the data array carries b64_json (base64 PNG) plus a temporary download url. Without it, the response may carry only the url. The url is temporary: download and save the image right away.
{
"created": 1794564556,
"data": [
{
"b64_json": "iVBORw0KGgo...",
"url": "https://...",
"width": "1024",
"height": "1024"
}
],
"output_format": "png"
}
Image billing
Each generated image costs ¥0.25 (about $0.04) whatever the model, size or quality; n: 2 bills two images, settled on the images actually returned. Failed requests are not charged. Every charge is listed in the usage log.
Seedream
ByteDance's Seedream image models on the OpenAI Images API. Results come back synchronously, usually in 10–30 seconds; set your client timeout to at least 120 seconds.
| Model | Use |
|---|---|
seedream-5.5-NSFW |
Seedream 5.5: text to image, image to image, layer decomposition |
seedream-5.0-pro-NSFW |
Seedream 5.0 Pro: text to image, image to image, layers, transparent output |
seedream-5-0-flash-NSFW |
Seedream 5.0 Flash: fast and low-cost text to image, image to image, layers |
In API Keys, create a key in the seedream-nsfw group. Seedream is only in that group: keys in other groups fail with no available channel. All keys share one balance.
Text to image:
curl https://pxrouter.com/v1/images/generations \
-H "Authorization: Bearer $PXROUTER_SEEDREAM_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5.5-NSFW",
"prompt": "an old canal town after snow, early morning, light mist",
"size": "2K"
}'
Image to image uses the same model with image added (a string for one image, an array for several; each is a URL or base64):
curl https://pxrouter.com/v1/images/generations \
-H "Authorization: Bearer $PXROUTER_SEEDREAM_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-5.5-NSFW",
"prompt": "turn the scene into a snowy winter day, keep the composition",
"image": "https://example.com/input.png",
"size": "1K"
}'
| Field | Notes |
|---|---|
model |
See the table above, required |
prompt |
Image description, required (optional for layer decomposition) |
image |
Reference images, up to 10. Public http(s) URLs or base64 (data:image/png;base64,..., lowercase format, at most 10 MB each) |
size |
1K, 1.5K, 2K or WIDTHxHEIGHT (921,600–4,624,220 pixels, aspect ratio 1:16 to 16:1), default 2K |
response_format |
url (default) or b64_json |
output_format |
jpeg or png |
background |
opaque or transparent; 5.5 also takes auto. On 5.0 Pro and Flash a transparent background needs exactly one reference image and cannot be jpeg |
layer_decomposition |
true splits one reference image into layers: exactly one reference image, size 1K, 1.5K, 2K or auto; 5.5 returns 30 images (base plus layers) by default, set 2–100 with layer_decomposition_options.max_images |
n |
Must be 1; group generation (sequential_image_generation) is not supported |
The response is {"created": ..., "data": [{"url": "https://...", "size": "..."}]}, with b64_json instead when response_format is b64_json. Links expire after about 24 hours; download and save images right away.
The BytePlus native API also works: POST https://pxrouter.com/api/v3/images/generations with the official request body and a model name from the table above.
Seedream billing: each output image is billed at its actual size — up to 1.5K (at most about 2.61 million pixels) or above, priced as in the table — plus reference images (5.5 $0.016 each, 5.0 Pro $0.006 each from the second, Flash free). With layer decomposition every output (the base image and each layer) counts as one image: 5.0 Pro layers cost $0.045 / $0.09, 5.5 and Flash charge their normal image price; 5.5 returns 30 by default, so set max_images to what you need. For example, one 1K image from 5.5 with one reference image costs $0.056. Failed requests are not charged. Every charge is listed in the usage log.