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. 常用参数

参数类型必填示例说明
modelstringgpt-5.5外层 Responses 模型
input[].content[].textstringCreate a product poster...图片提示词
streamboolean建议true开启 SSE 流式事件
tool_choice.typestringimage_generation指定调用图片工具
tools[].typestringimage_generation工具类型
tools[].modelstringgpt-image-2图片模型
tools[].sizestring1024x1024图片尺寸
tools[].qualitystringlow / medium / high / auto图片质量
tools[].output_formatstringpng / jpeg / webp输出格式
tools[].partial_imagesinteger1中间预览图数量

常用尺寸:

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. 常见错误

状态码原因处理
401API Key 无效或漏传检查 Authorization: Bearer YOUR_API_KEY
403Key 没有对应模型权限或余额不足检查分组、余额和模型权限
404路径写错确认使用 /v1/responses/v1/images/generations
429请求过快降低并发或稍后重试
500/502上游或中转暂时异常记录 request id 后重试,持续出现请联系管理员