Flu API Image Generation
生图 API 调用说明
基本信息
本文档用于说明如何通过当前中转域名调用 Flu API 的生图接口。
Base URLhttps://image.fluapi.com/v1
EndpointPOST /images/generations
推荐模型gpt-image-2
鉴权方式
Authorization: Bearer sk-你的Flu API密钥
推荐参数
稳定测试
{
"model": "gpt-image-2",
"prompt": "A small green square centered on a white background.",
"size": "1024x1024",
"n": 1
}
高清人物竖图
{
"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
}
| 参数 | 建议值 | 说明 |
|---|---|---|
size | 1024x1024 | 方图,最稳 |
size | 1024x1536 | 竖图,适合人物 |
size | 1536x1024 | 横图,适合场景 |
quality | high | 清晰度更高,耗时可能更长,已测试可用 |
n | 1 | 批量生成更慢,也更容易失败 |
timeout | 300 | 客户端超时时间建议 300 秒或更高 |
如果 quality 参数报错,去掉 quality 使用默认质量。
curl 示例
Windows 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
高清竖图
$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 示例
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 示例
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);
本地测试脚本
当前本机已有测试脚本和配置文件:
C:\Users\Administrator\Desktop\生图脚本\generate_image.py
C:\Users\Administrator\Desktop\生图脚本\.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
运行示例
cd C:\Users\Administrator\Desktop\生图脚本
python .\generate_image.py --prompt "A small green square centered on a white background." --timeout 300
高清竖图
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
生成文件默认保存到:
C:\Users\Administrator\Desktop\生图脚本\outputs
常见问题
401 Unauthorized
原因:没有传 key,或者 key 错误。检查请求头:
Authorization: Bearer sk-你的Flu API密钥
400 Invalid request
- JSON 格式不合法。
- 参数名称写错。
size或quality当前通道不支持。
建议先用最稳参数测试:
{
"model": "gpt-image-2",
"prompt": "A small green square centered on a white background.",
"size": "1024x1024",
"n": 1
}