Image Generations API

根据文本描述调用当前已启用的图像模型生成图像

接口说明

Image Generations API 用于根据文本描述生成图像。具体模型、尺寸能力和附加参数是否生效,取决于 /v1/models 中当前启用的 type=image 模型及其上游能力。

请求方式 POST
请求地址 /v1/images/generations
认证方式 Authorization: Bearer <API_KEY>

请求参数

参数名 类型 必填 说明
model string 图像模型 ID,建议先通过 /v1/models 查询当前启用的 type=image 模型
prompt string 图像描述文本,详细描述想要生成的图像
n integer 生成图像数量,默认 1
size string 图像尺寸;是否支持由当前上游模型决定
quality string 图像质量参数;如上游不支持可能会被忽略
style string 图像风格参数;是否生效以具体模型为准

请求示例

curl
curl https://api.lingyuncx.com/v1/images/generations \
  -H "Authorization: Bearer sk-xxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<请替换为当前启用的 image 模型 ID>",
    "prompt": "一只在太空旅行的猫,科幻风格,细节丰富",
    "n": 1,
    "size": "1024x1024"
  }'
Python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.lingyuncx.com/v1",
    api_key="sk-xxxxxxxx"
)

response = client.images.generate(
    model="<请替换为当前启用的 image 模型 ID>",
    prompt="一只在太空旅行的猫,科幻风格,细节丰富",
    n=1,
    size="1024x1024"
)

print(response.data[0].url)

返回示例

JSON
{
  "created": 1677652288,
  "data": [{
    "url": "https://...",
    "revised_prompt": "一只穿着太空服的猫在太空中漂浮..."
  }]
}

支持模型

模型 提供商 支持尺寸 价格
/v1/models 中的 type=image 模型 以当前启用记录为准 以具体上游模型支持范围为准 以后台 billing_rules 配置为准
当前实例 active 数量 1 当前存在 1 条 active 图像模型记录 接入前请务必用 /v1/models 实时确认

💡 提示

如果 /v1/models 暂无 type=image 记录,说明当前实例未启用图像模型;此时即使接口路由存在,也无法完成生成。