同步图片生成
SenseTime TokenPlan 当前模型与接入说明
同步图片生成
根据提示词同步生成图片。请求保持连接,直到返回图片结果。要基于已有图片修改时,使用同步图片编辑。
请求地址
POST https://token.sensetime.com/api/v1/images/generations
- Content-Type:
application/json - OpenAI 兼容客户端的
base_url/baseURL填写https://token.sensetime.com/api/v1,不要再额外拼接/v1。images.generate对应此路径。
授权
请求必须携带 API Key:
Authorization: Bearer <API_KEY>
将 <API_KEY> 替换为工作台创建的密钥。下面的示例使用环境变量 TOKENPLAN_API_KEY。
模型选择
当前文生图模型:sensenova-u1.6-lite、sensenova-u1-pro。
调用前查询模型列表,确认被选模型实际返回的 mode 为 image。
请求体
未传入的可选字段使用下列默认值。
模型 ID。
图像描述文本。
图像尺寸,默认 auto。建议使用下方分辨率。
生成图片数量,当前仅支持值为 1。
是否添加水印,默认 false。
返回形式,默认 url。url 返回临时图片链接,b64_json 返回 Base64 编码。
输出图片格式,可选 png、jpeg、webp,默认 png。
提示词自动润色优化开关。默认 true。sensenova-u1-pro 只支持 prompt_extend 为 true。
建议分辨率
| 分辨率 | 比例 | 等级 |
|---|---|---|
2048x2048 | 1:1 | 2K |
2720x1536 | 16:9 | 2K |
1536x2720 | 9:16 | 2K |
1664x2496 | 2:3 | 2K |
2496x1664 | 3:2 | 2K |
4096x4096 | 1:1 | 4K |
请求示例
curl "https://token.sensetime.com/api/v1/images/generations" \
-H "Authorization: Bearer $TOKENPLAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "sensenova-u1.6-lite",
"prompt": "一只在窗边打盹的橘猫,午后阳光,写实风格",
"size": "2048x2048",
"n": 1,
"response_format": "url"
}'响应字段
成功时 HTTP 状态码为 200,Content-Type 为 application/json。
接口返回的图片 URL 为临时访问链接,固定有效期 24小时,超时后链接直接失效,无法再次访问图片。
创建时间,Unix 时间戳(秒)。
图片结果。
Show child attributesHide child attributes
response_format 为 url 时返回。
response_format 为 b64_json 时返回,内容为图片的 Base64 编码。
实际输出格式。
实际输出尺寸。
Token 与图片数量。
Show child attributesHide child attributes
输入 token 数。
Show child attributesHide child attributes
输出 token 数。
Show child attributesHide child attributes
输入与输出之和。
输入图片数量。
输出图片数量。
计费以计费与用量和工作台为准。
响应示例
{
"created": 1713167890,
"data": [
{
"url": "https://example.com/generated.png"
}
],
"output_format": "png",
"size": "2048x2048",
"usage": {
"input_tokens": 20,
"input_tokens_details": {
"text_tokens": 20
},
"output_tokens": 1024,
"output_tokens_details": {
"image_tokens": 1024
},
"total_tokens": 1044,
"input_image_count": 0,
"output_image_count": 1
}
}
错误处理
model 或 prompt 缺失、n 不是 1、response_format 不是 url 或 b64_json 时,请求失败。