通用开放接口图像 API
POST /v1/images/generations
POST
/v1/images/generations文生图。
鉴权:Bearer Token
Content-Type:application/json
请求体
{ "model": "dall-e-3", "prompt": "A white siamese cat sitting on a windowsill, watercolor style", "n": 1, "size": "1024x1024", "quality": "standard", "response_format": "url"}请求字段
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 图像模型 ID |
prompt | string | 是 | 图像描述 |
n | integer | 否 | 生成数量,默认 1 |
size | string | 否 | 尺寸,如 1024x1024、1792x1024 |
quality | string | 否 | 画质,如 standard、hd |
response_format | string | 否 | url(默认)或 b64_json |
style | string | 否 | 风格,如 vivid、natural |
Agnes 图像模型示例(含参考图):
{ "model": "agnes-image-2.0-flash", "prompt": "A sunset over the ocean, cinematic lighting", "size": "1024x768", "response_format": "url", "extra_body": { "response_format": "url" }, "image": ["https://example.com/reference.jpg"]}请求示例(curl)
curl https://www.yunsell.com/v1/images/generations \ -H "Authorization: Bearer sk-xxx" \ -H "Content-Type: application/json" \ -d '{ "model": "dall-e-3", "prompt": "A white siamese cat sitting on a windowsill, watercolor style", "n": 1, "size": "1024x1024", "quality": "standard", "response_format": "url" }'响应体
HTTP 200
{ "created": 1712697600, "data": [ { "url": "https://cdn.example.com/generated/image_abc123.png", "revised_prompt": "A white Siamese cat perched on a sunlit windowsill, rendered in soft watercolor style." } ], "usage": { "quota_type": 1, "prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0, "request_count": 1, "quota": 5000 }}response_format 为 b64_json 时:
{ "created": 1712697600, "data": [ { "b64_json": "iVBORw0KGgoAAAANSUhEUgAA..." } ]}响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
created | integer | Unix 时间戳(秒) |
data | array | 生成结果,长度等于请求中的 n |
data[].url | string | 图片 URL(response_format=url 时返回) |
data[].b64_json | string | Base64 编码图片(response_format=b64_json 时返回) |
data[].revised_prompt | string | 模型改写后的 prompt(部分模型返回) |
usage | object | 计费信息,见 公共响应对象 |
url与b64_json互斥,取决于请求中的response_format。
失败响应
HTTP 400 等,格式见 标准错误。