API リファレンス

Responses API

Chat Completions の後継である OpenAI 互換の Responses API。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
  }
}

リクエストボディ

パラメータ必須説明
modelstringはいモデル ID(例:gpt-4oclaude-opus-4-8)。全カタログは モデル をご参照ください。
inputstring / arrayはいレスポンスの入力。プレーンな文字列、またはメッセージ項目の配列(例:input_textinput_image)。
instructionsstringいいえモデルへのシステムレベルの指示 — <code>system</code> メッセージに相当する Responses API の機能。
max_output_tokensintegerいいえレスポンスで生成する最大トークン数。
temperaturenumberいいえサンプリング温度(0~2)。高いほどランダムになります。
streambooleanいいえSSE ストリーミングを有効にします。デフォルト:false
toolsarrayいいえモデルが呼び出せるツール。web_search_previewfile_search などの内蔵ツールを含みます。
tool_choicestring / objectいいえツール選択の制御:"auto""none""required"、または特定のツールオブジェクト。
previous_response_idstringいいえ前回のレスポンスの id を渡すと、状態を保持したままマルチターンの会話を継続できます。
reasoningobjectいいえ推論モデル向けの推論設定(例:<code>effort</code>:<code>"low"</code> | <code>"medium"</code> | <code>"high"</code>)。

ストリーミング(SSE)

stream: true を設定すると、Server-Sent Events を介してレスポンスを段階的に受信できます — 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 には、対応する上流モデルとチャネルが必要です。利用可否はバックエンドで設定されたチャネルによって異なります。