API 參考
Responses API
OpenAI 相容的Responses API — Chat Completions 的後繼者,內建 web search 與 file search 等工具。透過相同的端點與 SDK 使用。
端點
http
POST https://api.tokspan.com/v1/responses快速範例
Responses API 遵循相同的 OpenAI SDK 模式 — 只需變更方法名稱:
python
from openai import OpenAI
client = OpenAI(api_key="sk-your-key", base_url="https://api.tokspan.com/v1")
response = client.responses.create(
model="MODEL_NAME",
input="What is the capital of France?",
)
print(response.output_text)shell
curl -X POST "https://api.tokspan.com/v1/responses" \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "MODEL_NAME",
"input": "What is the capital of France?"
}'json — Response
{
"id": "resp_abc123",
"object": "response",
"created_at": 1700000000,
"status": "completed",
"model": "MODEL_NAME",
"output": [{
"type": "message",
"role": "assistant",
"content": [{
"type": "output_text",
"text": "The capital of France is Paris.",
"annotations": []
}]
}],
"usage": {
"input_tokens": 12,
"output_tokens": 8,
"total_tokens": 20
}
}請求主體
| 參數 | 類型 | 必要 | 說明 |
|---|---|---|---|
| model | string | 是 | 模型 ID(例如 gpt-4o、claude-opus-4-8)。請參閱模型了解完整目錄。 |
| input | string / array | 是 | 回應的輸入。可以是純字串或訊息項目的陣列(例如 input_text、input_image)。 |
| instructions | string | 否 | 模型的系統層級指令 — 相當於 Responses API 中的 <code>system</code> 訊息。 |
| max_output_tokens | integer | 否 | 回應中要生成的最大 Token 數。 |
| temperature | number | 否 | 取樣溫度(0–2)。數值越高越隨機。 |
| stream | boolean | 否 | 啟用 SSE 串流。預設值:false。 |
| tools | array | 否 | 模型可呼叫的工具,包含 web_search_preview 與 file_search 等內建工具。 |
| tool_choice | string / object | 否 | 控制工具選擇:"auto"、"none"、"required",或指定工具物件。 |
| previous_response_id | string | 否 | 傳入先前回應的 id,以帶有狀態的方式繼續多輪對話。 |
| reasoning | object | 否 | 推理模型的推理設定(例如 <code>effort</code>:<code>"low"</code> | <code>"medium"</code> | <code>"high"</code>)。 |
串流(SSE)
設定 stream: true 即可透過伺服器傳送事件(SSE)逐步接收回應 — 與 Chat Completions 串流相同。
shell
curl -X POST "https://api.tokspan.com/v1/responses" \
-H "Authorization: Bearer sk-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "MODEL_NAME",
"input": "Tell me a story.",
"stream": true
}'內建工具
Responses API 支援不需要自訂函式定義的內建工具:
Web Search
json
{
"model": "MODEL_NAME",
"input": "What is the latest news about AI?",
"tools": [{
"type": "web_search_preview"
}]
}File Search
json
{
"model": "MODEL_NAME",
"input": "Summarize the Q3 report",
"tools": [{
"type": "file_search",
"vector_store_ids": ["vs_abc123"]
}]
}內建工具可用性:Web search 與 file search 需要支援的上游模型與通道。可用性取決於您在後端設定的通道。