Chat 接口
SenseTime TokenPlan 当前模型与接入说明
Chat 接口
标准化多轮对话接口,兼容 OpenAI Chat Completions。支持多轮上下文、工具调用(Function Calling)和多模态输入。实际可用模型和字段以当前 API Key 的权限为准。
请求地址
POST https://token.sensetime.com/api/v1/chat/completions
- Content-Type:
application/json - OpenAI 兼容客户端的
base_url/baseURL填写https://token.sensetime.com/api/v1,不要再额外拼接/v1。 stream: true时按 SSE 逐块返回,流结束标识为data: [DONE]。
授权
请求必须携带 API Key:
Authorization: Bearer <API_KEY>
将 <API_KEY> 替换为工作台创建的密钥。下面的示例使用环境变量 TOKENPLAN_API_KEY。
模型选择
| 模型 | 模态 |
|---|---|
sensenova-6.8-flash | 文本、图片 |
sensenova-6.8-flash-lite | 文本、图片 |
deepseek-v4.1-flash | 文本、图片 |
glm-5.3 | 文本 |
qwen3.8-27b | 文本、图片 |
调用前查询模型列表,确认被选模型实际返回的 protocols 是否包含 chat_completions。
请求体
模型 ID。使用上方当前清单中的 ID。
历史对话和当前输入。
Show child attributesHide child attributes
system、user、assistant 或 tool。
文本直接传字符串。多模态传对象数组,例如图片 URL。
参与者名称,用来区分同一角色下的不同身份。
仅 role 为 assistant 时可能出现,表示模型发起的工具调用。
仅 role 为 tool 时必填,对应某次工具调用的 ID。
模型可调用的工具,用于 Function Calling。
Show child attributesHide child attributes
当前为 function。
函数定义,包含 name、description 和 parameters(JSON Schema)。
工具调用策略,默认 auto。可为 none、auto、required,或 { "type": "function", "function": { "name": "my_func" } }。
是否流式返回,默认 false。
仅 stream 为 true 时有效。
Show child attributesHide child attributes
为 true 时,在 data: [DONE] 之前追加一个带 usage 的 chunk。默认 false。
{ "type": "text" } 为默认;{ "type": "json_object" } 强制 JSON。
兼容参数。生成 token 上限,不设置则直到自然结束或达到模型上限。
生成 token 上限,作用与 max_tokens 相同。
推理力度。可选 none、minimal、low、medium、high、xhigh、max、ultra。
Show child attributesHide child attributes
思考开关,例如 enabled、disabled。
采样温度,范围 [0.0, 2.0],默认 1.0。越高越随机,建议与 top_p 只调其中一个。
核采样阈值,范围 [0.0, 1.0],默认 1.0。
每条输入生成的回复数量,默认 1。
停止词。
频率惩罚,范围 [-2.0, 2.0],默认 0.0。
存在惩罚,范围 [-2.0, 2.0],默认 0.0。
是否返回输出 token 的对数概率,默认 false。
每个位置返回最可能的 N 个 token,需开启 logprobs,范围 [0, 20]。
随机种子,用于尽量可复现的采样。
请求示例
curl "https://token.sensetime.com/api/v1/chat/completions" \
-H "Authorization: Bearer $TOKENPLAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "sensenova-6.8-flash",
"messages": [
{"role": "system", "content": "你是一个严谨的人工智能助手。"},
{"role": "user", "content": "你好,请解释一下什么是黑洞?"}
],
"temperature": 0.7,
"stream": false
}'响应字段
成功时 HTTP 状态码为 200,Content-Type 为 application/json。
本次请求的唯一标识。
非流式为 chat.completion,流式 chunk 为 chat.completion.chunk。
生成时间,Unix 时间戳(秒)。
实际响应的模型 ID。
回复列表。
Show child attributesHide child attributes
在 choices 中的下标。
stop、length、tool_calls 或 content_filter。流式中间块为 null。
非流式时的完整消息。role 为 assistant。content 是文本回复;仅发起工具调用时可能为空。tool_calls 包含 id、type 和 function。
流式时替代 message,只包含本块新增的 role、content 或 tool_calls。
Token 消耗。流式响应默认不返回,除非 stream_options.include_usage 为 true。
Show child attributesHide child attributes
输入 token 数。
输出 token 数。
输入与输出之和。
finish_reason 枚举:
| value | 含义 |
|---|---|
stop | 正常结束 |
length | 达到 max_tokens 或上下文上限,消息内容可能会被部分截断。 |
tool_calls | 模型选择调用工具 |
content_filter | 内容被合规审核拦截 |
计费按输入和输出 token 计算,价格以计费与用量和工作台为准。
响应示例
{
"id": "chatcmpl-1234567890",
"object": "chat.completion",
"created": 1700000000,
"model": "sensenova-6.8-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "黑洞是宇宙中存在的一种天体,其引力极强..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 105,
"total_tokens": 133
}
}
流式响应
stream 为 true 时,响应是 text/event-stream。每个事件以 data: 开头,块之间空一行,最后一条是 data: [DONE]。
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1700000000,"model":"sensenova-6.8-flash","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1700000000,"model":"sensenova-6.8-flash","choices":[{"index":0,"delta":{"content":"黑洞"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1700000000,"model":"sensenova-6.8-flash","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
错误处理
非 200 时,响应体包含 error 对象。
| 字段 | 类型 | 说明 |
|---|---|---|
message | string | 可读的错误描述。 |
type | string | 错误类别,例如 invalid_request_error。 |
code | string | 内部错误代号。 |
param | string | 触发错误的参数名。 |