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 | 建议 | 见幂等 |
请求体#
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 必填 | 型号 ID |
input | string | array | 必填 | 文本,或消息 / 内容项数组。图片使用 { "type": "input_image", "image_url": "https://…" },仅对已验收图片输入的型号开放 |
instructions | string | 可选 | 系统指令,原样转发 |
max_output_tokens | integer | 可选 | 输出上限。不传时按型号默认值补上(多数为 4096),不能超过 max_output_tokens |
stream | boolean | 可选 | true 时以 SSE 事件返回 |
store | boolean | 可选 | 只能为 false 或不传。网关总是以 store: false 发给厂商(doubao-seed-translation-250915 不发送该字段) |
tools | array | 可选 | 只接受 type 为 function 或 custom 的工具;托管工具(联网搜索、文件检索、代码执行等)返回 422 hosted_tools_not_priced |
tool_choice | string | object | 可选 | 原样转发 |
reasoning | object | 可选 | 思考配置,原样转发。DeepSeek 示例使用 { "effort": "none" } |
| 其他字段 | — | 可选 | temperature、top_p、text 等原样转发,是否支持以厂商为准 |
不支持的用法#
| 请求中出现 | 返回 |
|---|---|
store: true、previous_response_id、conversation、background: true | 422 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
}'import os
import uuid
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOKENTOSEA_API_KEY"],
base_url="https://api.tokentosea.com/v1",
max_retries=0,
)
response = client.responses.create(
model="glm-5.3",
instructions="用中文简洁回答。",
input="什么是向量检索?",
max_output_tokens=1024,
store=False,
extra_headers={"Idempotency-Key": str(uuid.uuid4())},
)
print(response.output_text)
print(response.usage)import OpenAI from 'openai';
import { randomUUID } from 'node:crypto';
const client = new OpenAI({
apiKey: process.env.TOKENTOSEA_API_KEY,
baseURL: 'https://api.tokentosea.com/v1',
maxRetries: 0,
});
const response = await client.responses.create(
{
model: 'glm-5.3',
instructions: '用中文简洁回答。',
input: '什么是向量检索?',
max_output_tokens: 1024,
store: false,
},
{ headers: { 'Idempotency-Key': randomUUID() } },
);
console.log(response.output_text);
console.log(response.usage);流式事件#
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
}'import os
import uuid
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOKENTOSEA_API_KEY"],
base_url="https://api.tokentosea.com/v1",
max_retries=0,
)
stream = client.responses.create(
model="glm-5.3",
input="列出三个使用向量检索的场景。",
max_output_tokens=1024,
store=False,
stream=True,
extra_headers={"Idempotency-Key": str(uuid.uuid4())},
)
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)
elif event.type == "response.completed":
print("\n", event.response.usage)import OpenAI from 'openai';
import { randomUUID } from 'node:crypto';
const client = new OpenAI({
apiKey: process.env.TOKENTOSEA_API_KEY,
baseURL: 'https://api.tokentosea.com/v1',
maxRetries: 0,
});
const stream = await client.responses.create(
{ model: 'glm-5.3', input: '列出三个使用向量检索的场景。', max_output_tokens: 1024, store: false, stream: true },
{ headers: { 'Idempotency-Key': randomUUID() } },
);
for await (const event of stream) {
if (event.type === 'response.output_text.delta') process.stdout.write(event.delta);
if (event.type === 'response.completed') console.log('\n', event.response.usage);
}图片输入#
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
}'import os
import uuid
from openai import OpenAI
client = OpenAI(
api_key=os.environ["TOKENTOSEA_API_KEY"],
base_url="https://api.tokentosea.com/v1",
max_retries=0,
)
IMAGE_URL = "https://example.com/photo.jpg"
response = client.responses.create(
model="qwen3.8-max",
input=[{
"role": "user",
"content": [
{"type": "input_text", "text": "描述这张图片。"},
{"type": "input_image", "image_url": IMAGE_URL},
],
}],
max_output_tokens=1024,
store=False,
extra_headers={"Idempotency-Key": str(uuid.uuid4())},
)
print(response.output_text)import OpenAI from 'openai';
import { randomUUID } from 'node:crypto';
const client = new OpenAI({
apiKey: process.env.TOKENTOSEA_API_KEY,
baseURL: 'https://api.tokentosea.com/v1',
maxRetries: 0,
});
const IMAGE_URL = 'https://example.com/photo.jpg';
const response = await client.responses.create(
{
model: 'qwen3.8-max',
input: [{
role: 'user',
content: [
{ type: 'input_text', text: '描述这张图片。' },
{ type: 'input_image', image_url: IMAGE_URL },
],
}],
max_output_tokens: 1024,
store: false,
},
{ headers: { 'Idempotency-Key': randomUUID() } },
);
console.log(response.output_text);错误#
| 状态码 | code | 原因与处理 |
|---|---|---|
422 | stateful_responses_not_supported | 使用了 store: true、previous_response_id、conversation 或 background |
422 | endpoint_not_verified | 该型号未开放 Responses,改用 Chat Completions |
422 | input_modality_not_verified | 型号未开放图片输入 |
422 | hosted_tools_not_priced、explicit_cache_not_priced、cache_options_not_priced | 见不支持的用法 |
400 / 409 | main_wallet_authorization_failed | 见 API 概览 |
下一步#
- Chat Completions:覆盖型号最多的对话接口
- Messages:Anthropic 协议
- 流式输出指南