Skip to content

Flux 生成图像

Flux 官方格式图像生成接口,用于提交文生图任务。

重要提示 (关于 New API / One API 兼容性)

New API / One API 平台目前不支持 /flux/v1/image 接口。 由于中转分发平台不支持非标准的 OpenAI 路由,无法通过中转平台调用此接口(会导致 404 或路由失败)。

解决方法:

  1. 直接调用: 绕过中转系统,直接向 https://api.gemai.cc/flux/v1/image 发起请求。
  2. 改用 OpenAI 兼容的图像生成接口: 使用完美兼容中转平台的 /v1/images/generations 接口(详见 OpenAI 图像生成),并在请求中指定相关的 Flux 模型名(例如在 model 字段填入支持的 Flux 模型)。

接口信息

项目
方法POST
路径/flux/v1/image
完整地址https://api.gemai.cc/flux/v1/image
鉴权Authorization: Bearer sk-你的令牌

请求体示例

json
{
  "model": "flux",
  "prompt": "一只橘猫坐在赛博朋克城市屋顶",
  "width": 1024,
  "height": 1024
}

代码示例

bash
curl --location 'https://api.gemai.cc/flux/v1/image' \
  --header "Authorization: Bearer $GEMAI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "flux",
    "prompt": "一只橘猫坐在赛博朋克城市屋顶",
    "width": 1024,
    "height": 1024
  }'
javascript
const response = await fetch('https://api.gemai.cc/flux/v1/image', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.GEMAI_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: 'flux',
    prompt: '一只橘猫坐在赛博朋克城市屋顶',
    width: 1024,
    height: 1024,
  }),
})

console.log(await response.json())
python
import os
import requests

response = requests.post(
    'https://api.gemai.cc/flux/v1/image',
    headers={
        'Authorization': f"Bearer {os.environ['GEMAI_API_KEY']}",
        'Content-Type': 'application/json',
    },
    json={
        'model': 'flux',
        'prompt': '一只橘猫坐在赛博朋克城市屋顶',
        'width': 1024,
        'height': 1024,
    },
    timeout=300,
)

response.raise_for_status()
print(response.json())

返回示例

json
{
  "id": "task_xxx",
  "status": "processing"
}

注意事项

  • 如果返回任务 ID,请使用 Flux 查询任务 获取结果。
  • Flux 具体参数以模型实际支持为准。