Responses 接口
SenseTime TokenPlan 当前模型与接入说明
Responses 接口
通用模型生成接口,支持结构化输入和输出,适合需要更底层控制的生成与推理。实际可用模型和字段以当前 API Key 的权限为准。
请求地址
POST https://token.sensetime.com/api/v1/responses
- Content-Type:
application/json - OpenAI 兼容客户端的
base_url/baseURL填写https://token.sensetime.com/api/v1,不要再额外拼接/v1。SDK 会自行请求/responses。 stream: true时按 SSE 逐条事件返回。
授权
请求必须携带 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 是否包含 responses。
请求体
模型 ID。
输入内容。可以是字符串,或消息数组。
Show child attributesHide child attributes
assistant、user、system 或 developer。
文本,或内容块数组。内容块 type 必填,为 input_text、input_image、input_file、input_audio、output_text、refusal 或 reasoning_text。
模型的系统指令。
最大输出 token 数。
是否允许并行工具调用。
上一次响应的 ID。
推理配置。
Show child attributesHide child attributes
none、minimal、low、medium、high 或 xhigh。
auto、concise 或 detailed。
auto、concise 或 detailed。
推理 token 上限。
是否以 SSE 流式返回。
采样温度,范围 [0, 2]。
文本输出配置。
Show child attributesHide child attributes
输出格式。
Show child attributesHide child attributes
text、json_object 或 json_schema。
Show child attributesHide child attributes
Schema 名称。
JSON Schema。
是否严格符合 Schema。
字符串为 none、auto 或 required。对象时 type 目前只允许 function,并填写 name。
模型可调用的工具。
Show child attributesHide child attributes
目前只允许 function。
名称。
说明。
函数参数。type、description、required、properties、enum、additionalProperties。
是否要求参数严格符合 parameters。
核采样。
请求示例
curl "https://token.sensetime.com/api/v1/responses" \
-H "Authorization: Bearer $TOKENPLAN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "sensenova-6.8-flash",
"instructions": "你是一个严谨的人工智能助手。",
"input": [
{"type": "message", "role": "user", "content": "请解释一下什么是闭包。"}
],
"stream": false
}'响应字段
成功且 stream 为 false 时,HTTP 状态码为 200,Content-Type 为 application/json。
本次响应的唯一标识。
创建时间,Unix 时间戳(秒)。
实际响应的模型 ID。
completed、failed、in_progress、canceled、queued 或 incomplete。
输出条目。
Show child attributesHide child attributes
条目 ID。
reasoning、message 或 function_call。
in_progress、completed、incomplete、interpreting 或 failed。
assistant、user、system 或 developer。
文本,或内容块数组。内容块 type 为 input_text、input_image、input_file、input_audio、output_text、refusal 或 reasoning_text。
函数名。
函数参数,JSON 字符串。
本次调用的唯一 ID。
推理摘要。
Show child attributesHide child attributes
固定为 summary_text。
摘要文本。
Token 消耗。
Show child attributesHide child attributes
输入 token 数。
Show child attributesHide child attributes
文本 token 数。
音频 token 数。
图片 token 数。
从提示缓存读取的 token,已计入 input_tokens。
本次写入提示缓存的 token,已计入 input_tokens。
输出 token 数。
Show child attributesHide child attributes
文本 token 数。
被接受的预测 token 数。
音频 token 数。
推理 token 数。
被拒绝的预测 token 数。
引用 token 数。
输入与输出之和。
计费按输入和输出 token 计算,价格以计费与用量和工作台为准。
响应示例
{
"id": "resp_abc123",
"created_at": 1700000000,
"model": "sensenova-6.8-flash",
"status": "completed",
"output": [
{
"type": "message",
"role": "assistant",
"content": "闭包是指那些能够访问自由变量的函数..."
}
],
"usage": {
"input_tokens": 51,
"output_tokens": 149,
"total_tokens": 200
}
}
流式响应
stream 为 true 时,响应是 text/event-stream。每条事件包含 type 和 sequence_number。文本增量的 type 为 response.output_text.delta,delta 是文本片段。工具参数增量的 type 为 response.function_call_arguments.delta,arguments 是参数片段。结束事件为 response.completed、response.incomplete 或 response.failed。
data: {"type":"response.output_text.delta","sequence_number":1,"output_index":0,"delta":"闭包"}
data: {"type":"response.completed","sequence_number":2}
错误处理
非 200 时,响应体包含 error 对象。
| 字段 | 类型 | 说明 |
|---|---|---|
message | string | 可读的错误描述。 |
type | string | 错误类别,例如 invalid_request_error。 |
code | string | 内部错误代号。 |
param | string | 触发错误的参数名。 |