开发者资源

文档中心

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

文档中心文本生成
文本生成

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。

请求体

modelstring必填

模型 ID。

inputstring | object[]必填

输入内容。可以是字符串,或消息数组。

Show child attributesHide child attributes
rolestring

assistant、user、system 或 developer。

contentstring | object[]

文本,或内容块数组。内容块 type 必填,为 input_text、input_image、input_file、input_audio、output_text、refusal 或 reasoning_text。

instructionsstring

模型的系统指令。

max_output_tokensinteger

最大输出 token 数。

parallel_tool_callsboolean

是否允许并行工具调用。

previous_response_idstring

上一次响应的 ID。

reasoningobject

推理配置。

Show child attributesHide child attributes
effortstring

none、minimal、low、medium、high 或 xhigh。

generate_summarystring

auto、concise 或 detailed。

summarystring

auto、concise 或 detailed。

max_tokensinteger

推理 token 上限。

streamboolean

是否以 SSE 流式返回。

temperaturenumber

采样温度,范围 [0, 2]。

textobject

文本输出配置。

Show child attributesHide child attributes
formatobject

输出格式。

Show child attributesHide child attributes
typestring

text、json_object 或 json_schema。

json_schemaobject
Show child attributesHide child attributes
namestring

Schema 名称。

schemaobject

JSON Schema。

strictboolean

是否严格符合 Schema。

tool_choicestring | object

字符串为 none、auto 或 required。对象时 type 目前只允许 function,并填写 name。

toolsobject[]

模型可调用的工具。

Show child attributesHide child attributes
typestring必填

目前只允许 function。

namestring

名称。

descriptionstring

说明。

parametersobject

函数参数。type、description、required、properties、enum、additionalProperties。

strictboolean

是否要求参数严格符合 parameters。

top_pnumber

核采样。

请求示例

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。

idstring

本次响应的唯一标识。

created_atinteger

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

modelstring

实际响应的模型 ID。

statusstring

completed、failed、in_progress、canceled、queued 或 incomplete。

outputobject[]

输出条目。

Show child attributesHide child attributes
idstring

条目 ID。

typestring

reasoning、message 或 function_call。

statusstring

in_progress、completed、incomplete、interpreting 或 failed。

rolestring

assistant、user、system 或 developer。

contentstring | object[]

文本,或内容块数组。内容块 type 为 input_text、input_image、input_file、input_audio、output_text、refusal 或 reasoning_text。

namestring

函数名。

argumentsstring

函数参数,JSON 字符串。

call_idstring

本次调用的唯一 ID。

summaryobject[]

推理摘要。

Show child attributesHide child attributes
typestring必填

固定为 summary_text。

textstring必填

摘要文本。

usageobject

Token 消耗。

Show child attributesHide child attributes
input_tokensinteger

输入 token 数。

input_tokens_detailsobject
Show child attributesHide child attributes
text_tokensinteger

文本 token 数。

audio_tokensinteger

音频 token 数。

image_tokensinteger

图片 token 数。

cached_read_tokensinteger

从提示缓存读取的 token,已计入 input_tokens。

cached_write_tokensinteger

本次写入提示缓存的 token,已计入 input_tokens。

output_tokensinteger

输出 token 数。

output_tokens_detailsobject
Show child attributesHide child attributes
text_tokensinteger

文本 token 数。

accepted_prediction_tokensinteger

被接受的预测 token 数。

audio_tokensinteger

音频 token 数。

reasoning_tokensinteger

推理 token 数。

rejected_prediction_tokensinteger

被拒绝的预测 token 数。

citation_tokensinteger

引用 token 数。

total_tokensinteger

输入与输出之和。

计费按输入和输出 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 对象。

字段类型说明
messagestring可读的错误描述。
typestring错误类别,例如 invalid_request_error。
codestring内部错误代号。
paramstring触发错误的参数名。

相关指南