- 异步处理模式,返回任务ID用于后续查询
- Pro 和 Max 均支持文本生成图片与参考图编辑
- 生成结果中的 expires_at 表示图片链接的过期时间
请求示例
bash
curl --request POST \
--url https://api.openveer.com/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"model": "flux-kontext-pro",
"prompt": "把头发变成蓝色",
"image_urls": ["https://example.com/portrait.jpg"],
"size": "16:9",
"output_format": "png"
}'
```python
import requests
url = "https://api.openveer.com/v1/images/generations"
payload = {
"model": "flux-kontext-pro",
"prompt": "把头发变成蓝色",
"image_urls": ["https://example.com/portrait.jpg"],
"size": "16:9",
"output_format": "png"
}
headers = {
"Authorization": "Bearer
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
```
```javascript
const url = "https://api.openveer.com/v1/images/generations";
const payload = {
model: "flux-kontext-pro",
prompt: "把头发变成蓝色",
image_urls: ["https://example.com/portrait.jpg"],
size: "16:9",
output_format: "png"
};
const headers = {
"Authorization": "Bearer
"Content-Type": "application/json"
};
fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(payload)
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
```
响应示例
json
{
"code": 200,
"data": [
{
"status": "submitted",
"task_id": "task_01KFG5BBFNK1YQDTJDZY0P0QT2"
}
]
}
json
{
"error": {
"code": 401,
"message": "身份验证失败,请检查您的API密钥",
"type": "authentication_error"
}
}
json
{
"error": {
"code": 402,
"message": "账户余额不足,请充值后再试",
"type": "payment_required"
}
}
支持的模型
| 模型名 | 说明 |
|---|---|
flux-kontext-pro |
Flux Kontext Pro 图像生成与编辑模型 |
flux-kontext-max |
Flux Kontext Max 高质量图像生成与编辑模型 |
Authorizations
Authorization stringBody
model stringprompt stringimage_urls arraysize stringKontext 不支持 width 或 height,传入任一字段都会导致任务失败;请使用 size 控制宽高比。resolution 对 Kontext 不生效,输出恒定在约 1MP。
output_format stringresponse_format stringn integerseed integerprompt_upsampling booleansafety_tolerance integer实际输出尺寸
| 比例 | 实际输出尺寸 |
|---|---|
1:1 |
1024×1024 |
4:3 |
1184×880 |
3:4 |
880×1184 |
16:9 |
1392×752 |
9:16 |
752×1392 |
3:2 |
1248×832 |
2:3 |
832×1248 |
21:9 |
1568×672 |
9:21 |
672×1568 |
使用场景示例
图片编辑(带输入图片)
{
"model": "flux-kontext-pro",
"prompt": "把背景换成海滩",
"image_urls": ["https://example.com/photo.jpg"],
"size": "16:9",
"output_format": "png"
}
纯文生图(无输入图片)
{
"model": "flux-kontext-max",
"prompt": "一只蓝色的猫",
"size": "1:1",
"seed": 12345
}
多参考图编辑
{
"model": "flux-kontext-max",
"prompt": "把图一的人物放进图二的场景,并统一光照",
"image_urls": [
"https://example.com/person.jpg",
"https://example.com/scene.jpg"
],
"size": "4:3"
}
Response
code integerdata arraytask_id string查询任务结果
提交成功后,通过 GET /v1/tasks/{task_id} 轮询任务状态,详见 任务查询接口。
成功响应示例
{
"code": 200,
"data": {
"id": "task_01KFG5BBFNK1YQDTJDZY0P0QT2",
"status": "completed",
"progress": 100,
"created": 1785133674,
"completed": 1785133683,
"actual_time": 9,
"estimated_time": 15,
"result": {
"images": [
{
"url": [
"https://upload.apimart.ai/f/image/xxxxxxxx-flux-kontext.png"
],
"expires_at": 1785220083
}
]
}
}
}
取图路径:data.result.images[0].url[0]。expires_at 是该链接的 Unix 过期时间戳,请在过期前保存图片。
任务状态
| 状态 | 含义 |
|---|---|
submitted / pending |
任务已受理或正在排队,继续轮询 |
processing |
生成中,继续轮询 |
completed |
生成成功,结果位于 result.images |
failed |
生成失败,查看 data.error.message;任务费用会全额退还 |
参数错误与失败响应
模型参数无效时,提交接口仍会返回 HTTP 200 和 task_id。请持续轮询,任务随后会进入 failed 状态,并在 data.error.message 中返回具体原因。失败任务会全额退款。
{
"code": 200,
"data": {
"status": "failed",
"error": {
"type": "task_failed",
"code": "task_failed",
"message": "width/height are not supported by flux-kontext-pro"
}
}
}
error.code 固定为 task_failed,具体失败原因请读取 error.message。
注意事项
- 异步处理:提交后返回
task_id,需要轮询/v1/tasks/{task_id}获取结果。 - 参考图要求:最多支持 4 张参考图,可使用公网可访问的图片 URL 或 Base64 输入;输出与全部参考图合计不得超过 9MP。
- 尺寸规则:默认比例为
1:1。width/height会导致任务失败,resolution不改变约 1MP 的输出,像素格式的size会映射到最接近的支持比例。 - 生成张数:
n默认且只能为1。 - 提示词改写:显式设置
prompt_upsampling: false可关闭提示词改写。 - 结果链接:图片 URL 的有效期以对应的
expires_atUnix 时间戳为准,请及时保存。 - 异步参数错误:非法模型参数不会在提交时同步返回 4xx;必须轮询到
failed并读取data.error.message。