JunFeiAI 图片接口文档
适用对象:需要通过 JunFeiAI API 调用图片生成模型的下游系统。
最后更新:2026-06-21
1. 接入地址
| 场景 | Base URL | 说明 |
|---|---|---|
| 标准入口 | https://junfeiai.com/v1 | 推荐给海外或网络稳定环境使用 |
| 国内代理入口 | https://junfeiai.hk-proxy.lingzhiwuxian.com/v1 | 国内网络访问不稳定时使用 |
| 文档域名 | https://doc.junfeiai.com | 只放接口文档,不用于 API 请求 |
请求时使用你的 JunFeiAI API Key:
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
2. 推荐接口
新项目推荐使用 Responses API 的图片工具:
POST /responses
完整地址:
https://junfeiai.com/v1/responses
国内代理地址:
https://junfeiai.hk-proxy.lingzhiwuxian.com/v1/responses
3. 文生图请求
curl -N -X POST "https://junfeiai.com/v1/responses" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{
"model": "gpt-5.5",
"input": [
{
"type": "message",
"role": "user",
"content": [
{
"type": "input_text",
"text": "Create a clean premium product poster for a silver smart speaker, white studio background, realistic commercial photography, no text, no watermark."
}
]
}
],
"stream": true,
"store": false,
"tool_choice": { "type": "image_generation" },
"reasoning": { "effort": "xhigh", "summary": "auto" },
"tools": [
{
"type": "image_generation",
"model": "gpt-image-2",
"size": "1024x1024",
"quality": "medium",
"output_format": "png",
"partial_images": 1
}
]
}'
如果你的服务器在国内,把 URL 换成:
https://junfeiai.hk-proxy.lingzhiwuxian.com/v1/responses
4. 常用参数
| 参数 | 类型 | 必填 | 示例 | 说明 |
|---|---|---|---|---|
model | string | 是 | gpt-5.5 | 外层 Responses 模型 |
input[].content[].text | string | 是 | Create a product poster... | 图片提示词 |
stream | boolean | 建议 | true | 开启 SSE 流式事件 |
tool_choice.type | string | 是 | image_generation | 指定调用图片工具 |
tools[].type | string | 是 | image_generation | 工具类型 |
tools[].model | string | 是 | gpt-image-2 | 图片模型 |
tools[].size | string | 否 | 1024x1024 | 图片尺寸 |
tools[].quality | string | 否 | low / medium / high / auto | 图片质量 |
tools[].output_format | string | 否 | png / jpeg / webp | 输出格式 |
tools[].partial_images | integer | 否 | 1 | 中间预览图数量 |
常用尺寸:
1024x10241536x10241024x15362048x1152
5. SSE 返回
开启 stream: true 后,接口返回 text/event-stream。
常见事件:
event: response.image_generation_call.generating
data: {"type":"response.image_generation_call.generating","item_id":"..."}
event: response.image_generation_call.partial_image
data: {"type":"response.image_generation_call.partial_image","partial_image_index":0,"partial_image":"..."}
event: response.output_item.done
data: {"type":"response.output_item.done","item":{"type":"image_generation_call","result":"..."}}
event: response.completed
data: {"type":"response.completed","response":{...}}
客户端建议兼容这些字段读取图片 Base64:
result
b64_json
image
image_b64
partial_image
partial_image_b64
6. Node.js 示例
import fs from "node:fs";
const baseURL = "https://junfeiai.com/v1";
const response = await fetch(`${baseURL}/responses`, {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
"Accept": "text/event-stream"
},
body: JSON.stringify({
model: "gpt-5.5",
input: [{
type: "message",
role: "user",
content: [{
type: "input_text",
text: "Create a clean product poster, realistic studio lighting, no text."
}]
}],
stream: true,
store: false,
tool_choice: { type: "image_generation" },
tools: [{
type: "image_generation",
model: "gpt-image-2",
size: "1024x1024",
quality: "medium",
output_format: "png"
}]
})
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
let buffer = "";
for await (const chunk of response.body) {
buffer += Buffer.from(chunk).toString("utf8");
const blocks = buffer.split("\n\n");
buffer = blocks.pop() || "";
for (const block of blocks) {
const dataLine = block.split("\n").find((line) => line.startsWith("data: "));
if (!dataLine) continue;
const payload = JSON.parse(dataLine.slice(6));
const result = payload?.item?.result || payload?.partial_image;
if (result) {
fs.writeFileSync("image.png", Buffer.from(result, "base64"));
}
}
}
7. 兼容 Images API
旧客户端如果已经按 OpenAI Images API 对接,也可以使用兼容接口:
POST /images/generations
示例:
curl -X POST "https://junfeiai.com/v1/images/generations" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A clean product poster, white background, no text.",
"size": "1024x1024",
"quality": "medium",
"response_format": "b64_json"
}'
新接入仍建议优先使用 /v1/responses,它更适合观察生成过程和处理图片工具事件。
8. 常见错误
| 状态码 | 原因 | 处理 |
|---|---|---|
401 | API Key 无效或漏传 | 检查 Authorization: Bearer YOUR_API_KEY |
403 | Key 没有对应模型权限或余额不足 | 检查分组、余额和模型权限 |
404 | 路径写错 | 确认使用 /v1/responses 或 /v1/images/generations |
429 | 请求过快 | 降低并发或稍后重试 |
500/502 | 上游或中转暂时异常 | 记录 request id 后重试,持续出现请联系管理员 |