返回生图工作台

Aiswing API Documentation

生图 API 接入文档

使用你平台生成的 Sub2API 用户 Key 调用 OpenAI 兼容图片接口。服务地址默认是 https://gpt.aiswing.fun

快速开始

用户只需要准备一个 Sub2API 用户 Key,然后调用 /v1/images/generations

curl --location 'https://gpt.aiswing.fun/v1/images/generations' \
  --header 'Authorization: Bearer sk-your-sub2api-key' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-image-2",
    "prompt": "Generate a cute orange cat astronaut sticker on a clean pastel background.",
    "size": "1024x1024",
    "response_format": "b64_json"
  }'

生成图片

POST/v1/images/generations

适合纯文本提示词生图。请求体使用 JSON。

{
  "model": "gpt-image-2",
  "prompt": "A premium poster of a dancing woman, cinematic sunset light.",
  "size": "1024x1024",
  "quality": "auto",
  "output_format": "png",
  "response_format": "b64_json"
}

参考图编辑

POST/v1/images/edits

上传参考图时使用 multipart/form-data。可以上传一张或多张图片。

curl --location 'https://gpt.aiswing.fun/v1/images/edits' \
  --header 'Authorization: Bearer sk-your-sub2api-key' \
  --form 'model="gpt-image-2"' \
  --form 'prompt="Turn this person into a fashion magazine cover."' \
  --form 'size="1024x1024"' \
  --form 'response_format="b64_json"' \
  --form 'image[]=@"./reference.png"'

参数说明

参数类型说明
modelstring图片模型,例如 gpt-image-2
promptstring必填。图片生成或编辑提示词。
sizestring可选。常用 1024x10241536x10241024x1536auto
qualitystring可选。lowmediumhighauto
output_formatstring可选。pngjpegwebp
response_formatstring建议使用 b64_json,前端可直接转成图片。
image[]file仅编辑接口使用,表示参考图。

响应格式

成功时通常返回 data[0].b64_json,把 base64 解码即可得到图片。

{
  "created": 1776990000,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAAANSUhEUg...",
      "revised_prompt": "..."
    }
  ]
}

常见错误

  • 401 Unauthorized:API Key 无效、被删除或没有传 Authorization。
  • 400 failed to parse request body:JSON 格式错误,检查引号和逗号。
  • CORS error:浏览器跨域拦截,本地测试可用同域代理或临时关闭浏览器安全限制。
  • 余额未扣费:检查渠道模型定价是否配置 imageper_request
  • 模型不可用:检查用户分组、渠道关联分组和模型定价列表。