Responses API
OpenAI の次世代ステートフルエンドポイントです。ツール、Web 検索、ファイル検索、マルチステップタスクを内蔵でサポートし、Chat Completions を徐々に置き換えていきます。
レスポンスの作成
POST /v1/responsesRequestREQUEST
POST
https://test.kailin.com.cn/v1/responsesResponseRESPONSE
Fill in the request and hit Send — the response shows up here
リクエスト
curl https://test.kailin.com.cn/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-token" \
-d '{
"model": "gpt-4o-mini",
"input": "Describe the Responses API in one sentence"
}'
リクエストボディ
| パラメーター | 型 | 必須 | 説明 |
|---|---|---|---|
model | string | はい | モデル名 |
input | string / array | はい | 入力テキスト、またはメッセージ/コンテンツパートの配列 |
stream | boolean | いいえ | ストリーム出力(より豊富なイベントタイプ) |
instructions | string | いいえ | システムレベルの指示 |
previous_response_id | string | いいえ | 前の Response ID を渡すと、履歴を再送せずにマルチターンを継続できます |
tools | array | いいえ | ツール:function、web_search_preview など |
temperature / top_p | number | いいえ | サンプリングパラメーター |
max_output_tokens | number | いいえ | 最大出力トークン数 |
metadata | object | いいえ | カスタム key-value ペア(最大 16 個) |
store | boolean | いいえ | previous_response_id で参照できるように結果を保存するかどうか |
配列形式の input(画像を含む)の例:
{
"model": "gpt-4o-mini",
"input": [
{
"role": "user",
"content": [
{ "type": "input_text", "text": "Describe this image" },
{ "type": "input_image", "image_url": "https://example.com/cat.jpg" }
]
}
]
}
レスポンス
{
"id": "resp_abc123",
"object": "response",
"created_at": 1730000000,
"status": "completed",
"model": "gpt-4o-mini",
"output": [
{
"type": "message",
"id": "msg_abc123",
"role": "assistant",
"status": "completed",
"content": [
{
"type": "output_text",
"text": "The Responses API is OpenAI's next-generation stateful endpoint…",
"annotations": []
}
]
}
],
"usage": {
"input_tokens": 12,
"output_tokens": 30,
"total_tokens": 42
}
}
テキストを取り出すには、type: "message" の output アイテムを列挙して content[].text を読み取ります。SDK には resp.output_text というショートカットも用意されています。
レスポンスの取得
GET /v1/responses/{response_id}curl https://test.kailin.com.cn/v1/responses/resp_abc123 \
-H "Authorization: Bearer sk-your-token"
Response オブジェクト全体を返します。store: false で作成された Response は取得できません。
コンテキストの圧縮
POST /v1/responses/compact長い会話を要約に圧縮します — 長時間動作するエージェントが、後続のリクエストでのトークン消費を抑えるのに便利です:
curl https://test.kailin.com.cn/v1/responses/compact \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-token" \
-d '{
"model": "gpt-4o-mini",
"input": [ ...long message array... ]
}'
| パラメーター | 型 | 必須 | 説明 |
|---|---|---|---|
model | string | はい | 圧縮に使用するモデル |
input | array | はい | 圧縮するメッセージ配列 |
instructions | string | いいえ | 要約用のカスタム指示 |
圧縮済みの要約オブジェクトを返します。次のリクエストの input にそのまま置けます。
備考
WebSocket アクセス(wss://.../v1/responses の response.create イベント)は、ゲートウェイの WS パススルー対応に依存します — REST + SSE がクライアント統合の主要経路であり、ここでは扱いません。