开发者资源

文档中心

产品指南、接入说明与 API 参考

文档中心图片生成
图片生成

同步图片编辑

SenseTime TokenPlan 当前模型与接入说明

同步图片编辑

根据提示词和参考图同步编辑图片。请求保持连接,直到返回图片结果。只根据文本生成图片时,使用同步图片生成。

请求地址

POST https://token.sensetime.com/api/v1/images/edits

  • Content-Type:application/json
  • 请求体是 JSON。images 为对象数组,不是 multipart 文件上传。

授权

请求必须携带 API Key:

Authorization: Bearer <API_KEY>

将 <API_KEY> 替换为工作台创建的密钥。下面的示例使用环境变量 TOKENPLAN_API_KEY。

模型选择

当前文生图模型:sensenova-u1.6-lite、sensenova-u1-pro。

调用前查询模型列表,确认被选模型实际返回的 mode 为 image。

请求体

未传入的可选字段使用下列默认值。

modelstring必填

模型 ID。

imagesobject[]必填

待编辑的图片列表。

Show child attributesHide child attributes
image_urlstring必填

只能是图片 URL,或 Base64 Data-URL(data:image/...;base64,...)。传入的图片大小不能超过10MB。

promptstring必填

编辑指令,描述期望的最终画面。

ninteger

生成图片数量,当前仅支持值为 1。

sizestring

图像尺寸,默认 auto。建议使用下方分辨率。

response_formatstring

返回形式,默认 url。url 返回临时图片链接,b64_json 返回 Base64 编码。

output_formatstring

输出图片格式,可选 png、jpeg、webp,默认 png。

watermarkboolean

是否添加水印,默认 false。

prompt_extendboolean

提示词自动润色优化开关。默认 true。sensenova-u1-pro 只支持 prompt_extend 为 true。

建议分辨率

分辨率比例等级
2048x20481:12K
2720x153616:92K
1536x27209:162K
1664x24962:32K
2496x16643:22K
4096x40961:14K

请求示例

使用图片 URL

curl "https://token.sensetime.com/api/v1/images/edits" \
  -H "Authorization: Bearer $TOKENPLAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sensenova-u1.6-lite",
    "images": [
      {"image_url": "https://example.com/source.png"}
    ],
    "prompt": "将背景改为雪山,保持主体不变",
    "size": "2048x2048",
    "response_format": "url"
  }'

使用 Base64 Data-URL

image_url 写成 data:image/png;base64, 加图片的 Base64。下面的内容是一张最小 PNG,换成实际图片的编码即可。

curl "https://token.sensetime.com/api/v1/images/edits" \
  -H "Authorization: Bearer $TOKENPLAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sensenova-u1.6-lite",
    "images": [
      {"image_url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg=="}
    ],
    "prompt": "将背景改为雪山,保持主体不变",
    "size": "2048x2048",
    "response_format": "url"
  }'

响应字段

成功时 HTTP 状态码为 200,Content-Type 为 application/json。结构与同步图片生成相同。

接口返回的图片 URL 为临时访问链接,固定有效期 24小时,超时后链接直接失效,无法再次访问图片。

createdinteger

创建时间,Unix 时间戳(秒)。

dataobject[]

图片结果。

Show child attributesHide child attributes
urlstring

response_format 为 url 时返回。

b64_jsonstring

response_format 为 b64_json 时返回,内容为图片的 Base64 编码。

output_formatstring

实际输出格式。

sizestring

实际输出尺寸。

usageobject

Token 与图片数量。

Show child attributesHide child attributes
input_tokensinteger

输入 token 数。

input_tokens_detailsobject
Show child attributesHide child attributes
image_tokensinteger
text_tokensinteger
output_tokensinteger

输出 token 数。

output_tokens_detailsobject
Show child attributesHide child attributes
image_tokensinteger
text_tokensinteger
total_tokensinteger

输入与输出之和。

input_image_countinteger

输入图片数量。

output_image_countinteger

输出图片数量。

计费以计费与用量和工作台为准。

响应示例

{
  "created": 1713167890,
  "data": [
    {
      "url": "https://example.com/edited.png"
    }
  ],
  "output_format": "png",
  "size": "2048x2048",
  "usage": {
    "input_tokens": 1200,
    "input_tokens_details": {
      "image_tokens": 1160,
      "text_tokens": 40
    },
    "output_tokens": 1024,
    "output_tokens_details": {
      "image_tokens": 1024
    },
    "total_tokens": 2224,
    "input_image_count": 1,
    "output_image_count": 1
  }
}

错误处理

model、prompt 或 images 缺失、n 不是 1、response_format 不是 url 或 b64_json 时,请求失败。image_url 只能是可访问的 HTTP(S) URL,或 Base64 Data-URL。

相关指南