Image
MAI-Image-2.7
使用 Microsoft MAI-Image-2.7 生成和编辑图像,支持最多 5 个参考图 URL、1K/2K 档位或精确像素尺寸,按 token 计费。
快速示例
提交一次图像生成请求,保存返回的 id,然后轮询任务状态直至变为 completed 或 failed。该 API 采用异步任务模式并返回 PNG URL。
curl https://api.seedrouter.ai/v1/images/generations \
-H "Authorization: Bearer $SEEDROUTER_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"model":"mai-image-2.7","prompt":"A university campus poster at dusk, photorealistic style, cinematic lighting","size":"16:9","resolution":"2K"}'接口地址与请求头
POST https://api.seedrouter.ai/v1/images/generations
| 请求头 | 取值 |
|---|---|
| Authorization | Bearer YOUR_API_KEY |
| Content-Type | application/json |
请将密钥妥善保存在服务端。HTTP 200 仅表示任务已受理,不代表图像已生成完毕。图像编辑同样使用 /v1/images/generations 接口,并传入 image_urls。
请求参数
共支持 9 个字段。仅 model 和 prompt 为必填项。省略可选字段即可使用默认值;所有字段均不接受 null。Playground 提供固定的模型选择以及全部 8 个可编辑输入项。
| 字段 | 类型 | 默认值 | 约束 |
|---|---|---|---|
model | string | 必填 | mai-image-2.7 |
prompt | string | 必填 | 去除首尾空白后为 1–20000 个 Unicode 字符 |
n | integer | 1 | 必须为 1;如需生成多张图,请分别提交多个任务 |
size | string | 1:1 | 仅限文生图;整数宽高比 1:4–4:1 或 WIDTHxHEIGHT(也接受 * / ×);不支持 auto |
resolution | string | 1K | 1K 或 2K(不区分大小写);仅在 size 为宽高比时生效;不支持 4K |
width | integer | 省略 | 精确像素宽度,>= 768;必须与 height 成对传入;覆盖 size 和 resolution;仅限文生图 |
height | integer | 省略 | 精确像素高度,>= 768;必须与 width 成对传入;width × height <= 4,194,304(2048×2048) |
image_urls | string array | 省略 | 1–5 个不含内嵌凭证的公开 HTTP(S) 图片 URL,用于单图编辑或多图合成 |
background | string | auto | auto 或 opaque;不支持 transparent |
尺寸与宽高比
文生图时,可以传入 size(1:4 至 4:1 的整数比例)搭配 resolution(1K 或 2K),也可以直接在 size 中传入像素尺寸(例如 2048x1152),或成对传入 width 和 height。
- 像素限制:每边至少为
768,且width × height不超过4,194,304(2048×2048)。每条边会向下取整为 32 的倍数。 width和height的优先级高于size和resolution。- 传入未知字段(包括
quality、style、output_format、response_format、mask_url、auto_aspect_ratio、web_grounding)将返回 HTTP 400。输出格式固定为 PNG。
size | 1K | 2K |
|---|---|---|
1:1 | 1024×1024 | 2048×2048 |
4:3 | 1152×864 | 2336×1760 |
3:4 | 864×1152 | 1760×2336 |
3:2 | 1248×832 | 2496×1664 |
2:3 | 832×1248 | 1664×2496 |
16:9 | 1344×768 | 2720×1536 |
9:16 | 768×1344 | 1536×2720 |
2:1 | 1536×768 | 2880×1440 |
1:2 | 768×1536 | 1440×2880 |
21:9 | 1792×768 | 3104×1312 |
9:21 | 768×1792 | 1312×3104 |
4:1 | 3072×768 | 4096×1024 |
1:4 | 768×3072 | 1024×4096 |
参考图
在 image_urls 中传入 1–5 个可公开访问且不含内嵌凭证的 HTTP(S) URL,即可进行单图编辑或多图合成。支持的输入格式为 JPEG、PNG、WebP 和 GIF。SeedRouter 不接受 Base64 data URI,请先将图片托管到公开 URL。
传入 image_urls 时,模型会根据参考图自动决定输出尺寸;size、resolution、width 和 height 不会影响图生图的输出尺寸。
{
"model": "mai-image-2.7",
"prompt": "Make the bicycle blue and add a small dog sitting beside the front wheel",
"image_urls": [
"https://example.com/bicycle.png"
]
}计费
计费按三类 token 计算:文本输入、图像输入和图像输出。将各类别的实测用量乘以对应实时费率即可得出费用。失败的请求不收费。查看实时价格。
任务响应与轮询
请求受理后会返回一个异步任务对象:
{"id":"task_example","model":"mai-image-2.7","status":"processing"}curl https://api.seedrouter.ai/v1/tasks/task_example \
-H "Authorization: Bearer $SEEDROUTER_API_KEY"任务完成后的响应包含交付的 PNG URL(output.data[0].url)、实测 size、output.output_format 以及 output.usage。建议每隔 5–10 秒轮询一次。客户端超时后切勿重复提交相同请求。
错误处理
HTTP 错误响应格式为 {"error":{"code":integer,"message":string}}。详见通用错误目录与任务生命周期。
