创建图像(Images)
按 OpenAI Images API 形态创建图片:POST /images/generations,请求字段为 prompt、size、n 等,成功响应为 created + data[](不是 chat.completion)。
模型 ID 见 获取模型(modality=image)或 模型广场。统一契约(/chat/completions + image_config)见 创建图像生成(chat)。编辑已有图片见 编辑图像(Images)。
Endpoint
| Method | URL | 说明 |
|---|---|---|
POST | {TRINITY_BASE_URL}/images/generations | 文生图,同步等待 |
Base URL
| 项 | 值 |
|---|---|
| Base URL | https://api.trinitydesk.ai/v1 |
| 协议 | HTTPS |
bash
export TRINITY_BASE_URL="https://api.trinitydesk.ai/v1"
export TRINITY_API_KEY="xh-..."Headers
| Header | 必填 | 说明 |
|---|---|---|
Authorization | 是 | Bearer <TRINITY_API_KEY> |
Content-Type | 是 | application/json |
请求示例
bash
curl -sS "${TRINITY_BASE_URL}/images/generations" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${TRINITY_API_KEY}" \
-d '{
"model": "gpt-image-2",
"prompt": "A children'\''s book drawing of a veterinarian listening to a baby otter",
"size": "1024x1024",
"quality": "medium",
"n": 1,
"response_format": "url"
}'请求体字段
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 生图模型 ID |
prompt | string | 是 | 文本提示词 |
n | integer | 否 | 生成张数;默认与模型能力上限以内取值 |
size | string | 否 | 像素尺寸,如 1024x1024、1536x1024;部分模型支持 auto |
quality | string | 否 | 质量档位(如 low / medium / high / auto);以模型能力为准 |
output_format | string | 否 | 文件格式:png / jpeg / webp(模型不支持的值会被拒绝) |
background | string | 否 | 背景控制(如 auto / opaque);以模型能力为准 |
moderation | string | 否 | 审核档位(如 auto / low);以模型能力为准 |
output_compression | integer | 否 | jpeg/webp 压缩比 0–100;以模型能力为准 |
response_format | string | 否 | 交付形态:url(默认,平台对象存储 URL)或 b64_json |
stream | boolean | 否 | true 不被接受 |
未知顶层字段忽略。模型不支持的参数仍会按该模型能力拒绝。统一契约字段表见 高级参数 · 生图。
返回字段
| 字段 | 说明 |
|---|---|
created | Unix 时间戳(秒) |
data[] | 结果列表 |
data[].url | response_format=url 时的图片 URL |
data[].b64_json | response_format=b64_json 时的 Base64 内容 |
usage | 有 token 用量时返回;按张计费模型可能省略 |
响应头可能包含 X-Xh-Image-Task-Id(平台任务 ID)。同步超时后可用该 ID 查询 查询图像任务。
返回示例
json
{
"created": 1777777777,
"data": [
{
"url": "https://example.cos.ap-singapore.myqcloud.com/trinity-image/demo.png"
}
],
"usage": {
"input_tokens": 12,
"output_tokens": 1000,
"total_tokens": 1012,
"input_tokens_details": {
"text_tokens": 8,
"image_tokens": 4
},
"output_tokens_details": {
"image_tokens": 1000
}
}
}错误为 error 对象,见 错误与调试。
Python 示例
python
import os
import requests
base = os.environ["TRINITY_BASE_URL"]
key = os.environ["TRINITY_API_KEY"]
r = requests.post(
f"{base}/images/generations",
headers={
"Authorization": f"Bearer {key}",
"Content-Type": "application/json",
},
json={
"model": "gpt-image-2",
"prompt": "A children's book drawing of a veterinarian listening to a baby otter",
"size": "1024x1024",
"quality": "medium",
"n": 1,
"response_format": "url",
},
timeout=300,
)
r.raise_for_status()
print(r.json())