生成图片
图片生成使用 OpenAI Images 接口,同步返回结果,单张一般 30–60 秒。已经用 OpenAI SDK 的代码,只需把 base_url 设为 https://pxrouter.com/v1、换成 PxRouter 的 Key 和下面的模型名。
创建图片 Key
在「API 密钥」中新建一个 Key,分组选择「GPT 图片」。图片模型只在这个分组里,视频分组(「国内官方」「海外官方」)的 Key 调用图片模型会提示没有可用渠道;同一个账号可以同时有视频 Key 和图片 Key,共用余额。
生成图片
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": "一只戴宇航员头盔的柯基,摄影棚灯光",
"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="一只戴宇航员头盔的柯基,摄影棚灯光",
size="1024x1024",
response_format="b64_json",
)
with open("corgi.png", "wb") as f:
f.write(base64.b64decode(result.data[0].b64_json))
| 字段 | 说明 |
|---|---|
model |
模型名,必填,见「可用模型」 |
prompt |
图片描述,必填 |
n |
生成张数,默认 1 |
size |
图片尺寸,例如 1024x1024 |
response_format |
建议填 b64_json,见下文 |
请求里带上 "response_format": "b64_json",返回的 data 数组中每张图片都会有 b64_json(PNG 的 base64),同时附一个临时下载地址 url。不传时可能只返回 url。url 是临时地址,请及时下载保存。
{
"created": 1794564556,
"data": [
{
"b64_json": "iVBORw0KGgo...",
"url": "https://...",
"width": "1024",
"height": "1024"
}
],
"output_format": "png"
}
图片计费
每生成一张图片 ¥0.25,与模型、尺寸、质量无关;n 为 2 时按 2 张计费,以实际返回的图片数结算。请求失败不扣费。每笔扣费可在「使用日志」中查看。
Seedream
字节跳动 Seedream 图片模型,使用 OpenAI Images 接口,同步返回结果,单张一般 10–30 秒,请把客户端超时设到 120 秒以上。
| 模型 | 说明 |
|---|---|
seedream-5.5-NSFW |
Seedream 5.5,文生图、图生图、图层拆分 |
seedream-5.0-pro-NSFW |
Seedream 5.0 Pro,文生图、图生图、图层拆分、透明背景 |
seedream-5-0-flash-NSFW |
Seedream 5.0 Flash,速度快、价格低,文生图、图生图、图层拆分 |
在「API 密钥」中新建一个 Key,分组选择「seedream-nsfw」。Seedream 只在这个分组里,其他分组的 Key 调用会提示没有可用渠道;各类 Key 共用余额。
文生图:
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": "雪后的江南古镇,清晨,薄雾",
"size": "2K"
}'
图生图:同一个模型,加上 image 即可(一张传字符串,多张传数组;图片可以是链接,也可以是 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": "把图片里的场景改成雪后的冬天,保留构图",
"image": "https://example.com/input.png",
"size": "1K"
}'
| 字段 | 说明 |
|---|---|
model |
见上表,必填 |
prompt |
图片描述,必填(图层拆分时可不填) |
image |
参考图,最多 10 张。公网 http(s) 链接,或 base64(data:image/png;base64,...,格式名小写,单张不超过 10 MB) |
size |
1K、1.5K、2K,或 宽x高(总像素 921,600–4,624,220,宽高比 1:16–16:1),默认 2K |
response_format |
url(默认)或 b64_json |
output_format |
jpeg 或 png |
background |
opaque 或 transparent;5.5 还可以传 auto。5.0 Pro / Flash 的透明背景需要正好 1 张参考图,且不能配 jpeg |
layer_decomposition |
true 开启图层拆分:需要正好 1 张参考图,size 只能 1K、1.5K、2K 或 auto;5.5 默认输出 30 张(底图 + 图层),可用 layer_decomposition_options.max_images 设 2–100 |
n |
只能为 1;不支持组图(sequential_image_generation) |
返回 {"created": ..., "data": [{"url": "https://...", "size": "..."}]};response_format 为 b64_json 时返回 b64_json。返回的链接 24 小时左右失效,请及时下载保存。
也可以用 BytePlus 官方原生接口 POST https://pxrouter.com/api/v3/images/generations,请求体与官方一致,model 换成上表的名字。
Seedream 计费:按实际输出的每张图片计费,1.5K 及以下(总像素不超过约 2.61M)和 1.5K 以上价格见上表;参考图另计(5.5 每张 $0.016,5.0 Pro 第 2 张起每张 $0.006,Flash 免费)。图层拆分每张输出(底图和每个图层)各算一张,5.0 Pro 图层按 $0.045 / $0.09 计,5.5、Flash 按普通出图价;5.5 默认 30 张,请按需设 max_images。例如 5.5 出 1 张 1K 图带 1 张参考图共 $0.056(约 ¥0.374)。请求失败不扣费,每笔扣费可在「使用日志」中查看。