Flu API Image Generation

生图 API 调用说明

基本信息

本文档用于说明如何通过当前中转域名调用 Flu API 的生图接口。

Base URLhttps://image.fluapi.com/v1
EndpointPOST /images/generations
推荐模型gpt-image-2

鉴权方式

HTTP Header
Authorization: Bearer sk-你的Flu API密钥

推荐参数

稳定测试

JSON
{
  "model": "gpt-image-2",
  "prompt": "A small green square centered on a white background.",
  "size": "1024x1024",
  "n": 1
}

高清人物竖图

JSON
{
  "model": "gpt-image-2",
  "prompt": "A tasteful lifestyle photo of an adult Asian woman wearing modest satin pajamas in a modern hotel room, sitting comfortably near a window with warm evening light, elegant and natural, non-sexual, photorealistic.",
  "size": "1024x1536",
  "quality": "high",
  "n": 1
}
参数建议值说明
size1024x1024方图,最稳
size1024x1536竖图,适合人物
size1536x1024横图,适合场景
qualityhigh清晰度更高,耗时可能更长,已测试可用
n1批量生成更慢,也更容易失败
timeout300客户端超时时间建议 300 秒或更高

如果 quality 参数报错,去掉 quality 使用默认质量。

curl 示例

Windows PowerShell

PowerShell
$body = @{
  model = "gpt-image-2"
  prompt = "A small green square centered on a white background."
  size = "1024x1024"
  n = 1
} | ConvertTo-Json -Compress

curl.exe https://image.fluapi.com/v1/images/generations `
  -H "Authorization: Bearer sk-你的Flu API密钥" `
  -H "Content-Type: application/json" `
  -d $body

高清竖图

PowerShell
$body = @{
  model = "gpt-image-2"
  prompt = "A tasteful lifestyle photo of an adult Asian woman wearing modest satin pajamas in a modern hotel room, warm evening light, elegant and natural, non-sexual, photorealistic."
  size = "1024x1536"
  quality = "high"
  n = 1
} | ConvertTo-Json -Compress

curl.exe https://image.fluapi.com/v1/images/generations `
  -H "Authorization: Bearer sk-你的Flu API密钥" `
  -H "Content-Type: application/json" `
  -d $body

Python 示例

Python
import base64
import requests

api_key = "sk-你的Flu API密钥"
url = "https://image.fluapi.com/v1/images/generations"

payload = {
    "model": "gpt-image-2",
    "prompt": "A small green square centered on a white background.",
    "size": "1024x1024",
    "n": 1,
}

response = requests.post(
    url,
    headers={
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
    },
    json=payload,
    timeout=300,
)

response.raise_for_status()
data = response.json()

item = data["data"][0]
if "b64_json" in item:
    image_bytes = base64.b64decode(item["b64_json"])
    with open("output.png", "wb") as f:
        f.write(image_bytes)
elif "url" in item:
    image_url = item["url"]
    image_data = requests.get(image_url, timeout=300).content
    with open("output.png", "wb") as f:
        f.write(image_data)
else:
    raise RuntimeError(f"Unexpected response: {data}")

print("saved: output.png")

JavaScript 示例

JavaScript
const apiKey = "sk-你的Flu API密钥";

const response = await fetch("https://image.fluapi.com/v1/images/generations", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "gpt-image-2",
    prompt: "A small green square centered on a white background.",
    size: "1024x1024",
    n: 1,
  }),
});

if (!response.ok) {
  throw new Error(await response.text());
}

const data = await response.json();
console.log(data);

本地测试脚本

当前本机已有测试脚本和配置文件:

Path
C:\Users\Administrator\Desktop\生图脚本\generate_image.py
C:\Users\Administrator\Desktop\生图脚本\.env

.env 里应包含:

.env
NEW_API_BASE_URL=https://image.fluapi.com/v1
NEW_API_KEY=sk-你的Flu API密钥
IMAGE_MODEL=gpt-image-2
IMAGE_SIZE=1024x1024
IMAGE_N=1
REQUEST_TIMEOUT=300

运行示例

PowerShell
cd C:\Users\Administrator\Desktop\生图脚本
python .\generate_image.py --prompt "A small green square centered on a white background." --timeout 300

高清竖图

PowerShell
python .\generate_image.py --prompt "A tasteful lifestyle photo of an adult Asian woman wearing modest satin pajamas in a modern hotel room, warm evening light, elegant and natural, non-sexual, photorealistic." --size 1024x1536 --quality high --timeout 300

生成文件默认保存到:

Path
C:\Users\Administrator\Desktop\生图脚本\outputs

常见问题

401 Unauthorized

原因:没有传 key,或者 key 错误。检查请求头:

HTTP Header
Authorization: Bearer sk-你的Flu API密钥

400 Invalid request

  • JSON 格式不合法。
  • 参数名称写错。
  • sizequality 当前通道不支持。

建议先用最稳参数测试:

JSON
{
  "model": "gpt-image-2",
  "prompt": "A small green square centered on a white background.",
  "size": "1024x1024",
  "n": 1
}