跳转到主要内容
POST
/
v1
/
images
/
generations
文生图:根据文本描述 + size 生成指定尺寸图片
curl --request POST \
  --url https://api.apiyi.com/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "gpt-image-2-vip",
  "prompt": "黄昏时的海边老灯塔,电影画幅,写实风格"
}
'
{
  "data": [
    {
      "url": "https://r2cdn.copilotbase.com/r2cdn2/00aaa9fb-756c-4119-a4a0-4a44fc75152b.png",
      "b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
    }
  ]
}

Documentation Index

Fetch the complete documentation index at: https://docs.apiyi.com/llms.txt

Use this file to discover all available pages before exploring further.

右侧的交互式 Playground 支持直接在线调试。请在 Authorization 中填入你的 API Key(格式:Bearer sk-xxx),输入 promptsize 后一键发送即可。
场景说明:本页用于「文本生成图片」。只需输入提示词与 size 即可,无需上传任何图片。如需根据现有图片做编辑或融合,请使用 图片编辑接口gpt-image-2-all 的区别:调用结构完全一致,只多一个 size 字段;不需要锁尺寸、追求出图速度时改用 gpt-image-2-all 即可。
🖥️ 浏览器 Playground 限制(仅 b64_json 模式)默认 response_format: "url" 模式下 Playground 工作正常(响应只是一个 R2 链接)。如果你切换成 response_format: "b64_json",响应会包含数 MB 的 base64 字符串,浏览器 Playground 可能弹出 请求时发生错误: unable to complete request ——实际请求已经成功,只是浏览器无法显示这么长的 base64。推荐做法
  • 只想看图:保持默认 url 模式,Playground 会直接返回链接。
  • 真的需要 b64_json:复制下方”代码示例”到本地运行,代码会自动解码并把图片保存为本地文件。
⚠️ 关键参数说明
  • size:必须从 30 档常见尺寸里选(10 比例 × 1K Fast / 2K Recommended / 4K Detail,详见 概览页 size 完整表)。写法用半角小写 x,例如 2048x13603840x2160,不要用 × 或大写 X
  • quality:❌ 不接受,不要传
  • n:❌ 不接受,单次仅返回 1 张图。传 n=3 会按 0.09 $ 扣费但只返回 1 张,请把 n 字段从请求里去掉。
  • aspect_ratio:❌ 不接受。比例直接由 size 决定。

代码示例

Python

import requests

API_KEY = "sk-your-api-key"

response = requests.post(
    "https://api.apiyi.com/v1/images/generations",
    headers={"Authorization": f"Bearer {API_KEY}"},
    json={
        "model": "gpt-image-2-vip",
        "prompt": "黄昏时的海边老灯塔,电影画幅,写实风格",
        "size": "2048x1152",          # 16:9 2K Recommended
        "response_format": "url"
    },
    timeout=300  # 保守值,吸收长尾 + 图片下载耗时
).json()

image_url = response["data"][0]["url"]
print(image_url)
4K Detail 档示例(壁纸 / 印刷)
import requests

response = requests.post(
    "https://api.apiyi.com/v1/images/generations",
    headers={"Authorization": "Bearer sk-your-api-key"},
    json={
        "model": "gpt-image-2-vip",
        "prompt": "桌面壁纸,赛博朋克城市夜景,霓虹招牌,雨后倒影",
        "size": "3840x2160",          # 16:9 4K Detail
        "response_format": "b64_json"
    },
    timeout=300
).json()

# b64_json 已含 "data:image/png;base64," 前缀,可直接用于 <img src> 或写文件
data_url = response["data"][0]["b64_json"]

cURL

curl -X POST "https://api.apiyi.com/v1/images/generations" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2-vip",
    "prompt": "白色陶瓷马克杯放在灰色桌面上的产品图,柔和自然光",
    "size": "2048x1360",
    "response_format": "url"
  }'

Node.js

const API_KEY = "sk-your-api-key";

const response = await fetch(
  "https://api.apiyi.com/v1/images/generations",
  {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${API_KEY}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "gpt-image-2-vip",
      prompt: "1:1 方形 LOGO,极简猫咪线条",
      size: "2048x2048",        // 1:1 2K Recommended
      response_format: "b64_json"
    })
  }
);

const data = await response.json();
// b64_json 已含前缀,可直接用作 <img src>
document.getElementById("result").src = data.data[0].b64_json;

OpenAI SDK(Python,推荐)

from openai import OpenAI

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://api.apiyi.com/v1"
)

resp = client.images.generate(
    model="gpt-image-2-vip",
    prompt="水墨山水,国画风格,纵向构图",
    size="1536x2048",        # 3:4 2K Portrait
)
print(resp.data[0].url)

参数说明速查

参数类型必填说明
modelstring固定填 gpt-image-2-vip
promptstring提示词,描述画面内容、风格、光线等
sizestring强烈建议输出尺寸,从 30 档里选;写法 宽x高(半角小写 x);省略时由模型回退到默认档
response_formatstringurl(默认,返回 R2 CDN 链接)或 b64_json
size 速查:常用挑这几个就够:
  • 电商主图:2048x1360 (3:2 2K) / 2048x2048 (1:1 2K)
  • 海报竖图:1536x2048 (3:4 2K) / 2480x3312 (3:4 4K)
  • 视频封面:2048x1152 (16:9 2K) / 3840x2160 (16:9 4K)
  • 故事/手机壁纸:1152x2048 (9:16 2K) / 2160x3840 (9:16 4K)
完整 30 档表见 概览页

响应格式

url 模式(默认,R2 CDN 全球加速):
{
    "data": [
        {
            "url": "https://r2cdn.copilotbase.com/r2cdn2/00aaa9fb-756c-4119-a4a0-4a44fc75152b.png"
        }
    ]
}
b64_json 模式(需显式 "response_format": "b64_json"):
{
    "data": [
        {
            "b64_json": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
        }
    ]
}
兼容性提示b64_json 字段本身已经包含 data:image/png;base64, 前缀,可直接赋给 HTML <img src> 或写入文件;无需再手动拼接 data:image/...;base64,。与部分旧版 OpenAI 兼容模型不同,请留意。

相关资源

模型概览(含完整 size 表)

30 档 size 完整对照表、定价、技术规格

对话式 API

Chat Completions 格式,方便传入在线 URL

图片编辑 API

/v1/images/edits 多图融合与改图

姐妹模型 gpt-image-2-all

不需要锁尺寸时调用方式一致,出图更快(约 30s)

授权

Authorization
string
header
必填

在 API易控制台获取的 API Key

请求体

application/json
model
enum<string>
默认值:gpt-image-2-vip
必填

模型名称,固定为 gpt-image-2-vip

可用选项:
gpt-image-2-vip
prompt
string
必填

提示词,描述画面内容、风格、光线等

示例:

"黄昏时的海边老灯塔,电影画幅,写实风格"

size
enum<string>

输出尺寸,从 30 档常见尺寸里选(10 比例 × 1K Fast / 2K Recommended / 4K Detail)。 写法:宽x高(半角小写 x),如 2048x13603840x2160。所有档位统一价 $0.03/张。

可用选项:
1280x1280,
848x1280,
1280x848,
960x1280,
1280x960,
1024x1280,
1280x1024,
720x1280,
1280x720,
1280x544,
2048x2048,
1360x2048,
2048x1360,
1536x2048,
2048x1536,
1632x2048,
2048x1632,
1152x2048,
2048x1152,
2048x864,
2880x2880,
2336x3520,
3520x2336,
2480x3312,
3312x2480,
2560x3216,
3216x2560,
2160x3840,
3840x2160,
3840x1632
示例:

"2048x1152"

response_format
enum<string>
默认值:url

响应格式。url 返回 R2 CDN 链接(默认);b64_json 返回已含 data URL 前缀的 base64 字符串

可用选项:
url,
b64_json

响应

成功生成图片

data
object[]

生成结果数组(本模型单次返回 1 张)