TokenToSea开发者文档
控制台

ResponsesPOST

与 OpenAI Responses 兼容的无状态对话接口,支持流式事件、图片输入与函数工具;不保存会话状态。

本页内容

POST https://api.tokentosea.com/v1/responses

按 OpenAI Responses 协议发送请求,原样返回厂商的 Response 对象。TokenToSea 只开放无状态用法:每次请求都携带完整上下文,不在平台或厂商侧保存会话。

前提:全能密钥或模型密钥,账户可用余额足以覆盖本次预留。Python 示例需要 pip install openai,Node.js 示例需要 Node.js 18+ 与 npm install openai。

支持的型号#

截至 2026-10-21,62 个型号开放本接口:千问 39、豆包 11、MiniMax 6、DeepSeek 2、阶跃星辰 2、Kimi 1(kimi-k3)、智谱 1(glm-5.3)。以 GET /v1/models 中 verified_endpoints 包含 /v1/responses 的型号为准。所有开放的型号都支持 JSON 与 SSE 两种响应方式。

请求头#

请求头必填说明
Authorization必填Bearer sk-relay_…,也可用 x-api-key
Content-Type必填application/json
Idempotency-Key建议见幂等

请求体#

参数类型必填说明
modelstring必填型号 ID
inputstring | array必填文本,或消息 / 内容项数组。图片使用 { "type": "input_image", "image_url": "https://…" },仅对已验收图片输入的型号开放
instructionsstring可选系统指令,原样转发
max_output_tokensinteger可选输出上限。不传时按型号默认值补上(多数为 4096),不能超过 max_output_tokens
streamboolean可选true 时以 SSE 事件返回
storeboolean可选只能为 false 或不传。网关总是以 store: false 发给厂商(doubao-seed-translation-250915 不发送该字段)
toolsarray可选只接受 type 为 function 或 custom 的工具;托管工具(联网搜索、文件检索、代码执行等)返回 422 hosted_tools_not_priced
tool_choicestring | object可选原样转发
reasoningobject可选思考配置,原样转发。DeepSeek 示例使用 { "effort": "none" }
其他字段—可选temperature、top_p、text 等原样转发,是否支持以厂商为准

不支持的用法#

请求中出现返回
store: true、previous_response_id、conversation、background: true422 stateful_responses_not_supported
cache_control(本接口只有 kimi-k3 开放显式缓存)422 explicit_cache_not_priced
prompt_cache_options(kimi-k3 以外)422 cache_options_not_priced
托管工具、mcp_servers、web_search_options 等附加产品422 hosted_tools_not_priced / auxiliary_product_not_priced

需要多轮对话时,把之前的输出作为 input 的一部分重新发送。

响应#

响应示例
{
  "id": "resp_…",
  "object": "response",
  "created_at": 1792483200,
  "status": "completed",
  "model": "glm-5.3",
  "output": [
    {
      "type": "message",
      "id": "msg_…",
      "status": "completed",
      "role": "assistant",
      "content": [{ "type": "output_text", "text": "向量检索把内容转成向量,再按相似度查找。", "annotations": [] }]
    }
  ],
  "usage": {
    "input_tokens": 16,
    "output_tokens": 19,
    "total_tokens": 35,
    "input_tokens_details": { "cached_tokens": 0 }
  }
}

字段以厂商返回为准。结算未完成时返回 202 和结果信封。

流式事件#

"stream": true 时返回 text/event-stream,事件形如 event: response.output_text.delta + data: {…}。

  • 中间事件实时转发。response.completed 在主站完成结算后才发出,usage 位于该事件的 response.usage。
  • 结算失败时以 event: error、data: {"error":{"code":"execution_result_pending"}} 结束,用同一个键查询 /v1/results/{key}。
  • 客户端断开不影响结算,完整 SSE 文本保存在结果的 output.stream。

示例#

文本请求#

curl https://api.tokentosea.com/v1/responses \
  -H "Authorization: Bearer $TOKENTOSEA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "model": "glm-5.3",
    "instructions": "用中文简洁回答。",
    "input": "什么是向量检索?",
    "max_output_tokens": 1024,
    "store": false
  }'

流式事件#

curl -N https://api.tokentosea.com/v1/responses \
  -H "Authorization: Bearer $TOKENTOSEA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "model": "glm-5.3",
    "input": "列出三个使用向量检索的场景。",
    "max_output_tokens": 1024,
    "store": false,
    "stream": true
  }'

图片输入#

curl https://api.tokentosea.com/v1/responses \
  -H "Authorization: Bearer $TOKENTOSEA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "model": "qwen3.8-max",
    "input": [{
      "role": "user",
      "content": [
        {"type": "input_text", "text": "描述这张图片。"},
        {"type": "input_image", "image_url": "https://example.com/photo.jpg"}
      ]
    }],
    "max_output_tokens": 1024,
    "store": false
  }'

错误#

状态码code原因与处理
422stateful_responses_not_supported使用了 store: true、previous_response_id、conversation 或 background
422endpoint_not_verified该型号未开放 Responses,改用 Chat Completions
422input_modality_not_verified型号未开放图片输入
422hosted_tools_not_priced、explicit_cache_not_priced、cache_options_not_priced见不支持的用法
400 / 409main_wallet_authorization_failed见 API 概览

下一步#

    输入关键词搜索全部文档与模型。