兼容 OpenAI 图像生成接口,使用 gpt-image-2 模型按文本提示词生成图片。
| Base URL | https://niuflu.com/v1 |
|---|---|
| Endpoint | POST /images/generations |
| 推荐模型 | gpt-image-2 |
| 鉴权 | HTTP 头 Authorization: Bearer sk-你的APIKey |
| 参数 | 说明 |
|---|---|
size | 1024x1024(方形)、1024x1536(竖图)、1536x1024(横图) |
quality | 设为 high 可提升清晰度,但会增加处理时间 |
n | 生成数量;保持为 1 更快且更稳定 |
timeout | 客户端超时建议至少 300 秒 |
curl https://niuflu.com/v1/images/generations `
-H "Authorization: Bearer sk-你的APIKey" `
-H "Content-Type: application/json" `
-d '{
"model": "gpt-image-2",
"prompt": "A small green square centered on a white background.",
"size": "1024x1024",
"quality": "high",
"n": 1
}'
import requests
resp = requests.post(
"https://niuflu.com/v1/images/generations",
headers={
"Authorization": "Bearer sk-你的APIKey",
"Content-Type": "application/json",
},
json={
"model": "gpt-image-2",
"prompt": "A small green square centered on a white background.",
"size": "1024x1024",
"quality": "high",
"n": 1,
},
timeout=300,
)
print(resp.json())
const resp = await fetch("https://niuflu.com/v1/images/generations", {
method: "POST",
headers: {
"Authorization": "Bearer sk-你的APIKey",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-image-2",
prompt: "A small green square centered on a white background.",
size: "1024x1024",
quality: "high",
n: 1,
}),
});
const data = await resp.json();
console.log(data);
Authorization 头格式。A small green square centered on a white background.,分辨率 1024x1024,确认通路正常后再调整其他参数。