メインコンテンツへスキップ

Responses API

OpenAI の次世代ステートフルエンドポイントです。ツール、Web 検索、ファイル検索、マルチステップタスクを内蔵でサポートし、Chat Completions を徐々に置き換えていきます。

レスポンスの作成​

POST /v1/responses
RequestREQUEST
POSThttps://test.kailin.com.cn/v1/responses
ResponseRESPONSE
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"
}'

リクエストボディ​

パラメーター型必須説明
modelstringはいモデル名
inputstring / arrayはい入力テキスト、またはメッセージ/コンテンツパートの配列
streambooleanいいえストリーム出力(より豊富なイベントタイプ)
instructionsstringいいえシステムレベルの指示
previous_response_idstringいいえ前の Response ID を渡すと、履歴を再送せずにマルチターンを継続できます
toolsarrayいいえツール:function、web_search_preview など
temperature / top_pnumberいいえサンプリングパラメーター
max_output_tokensnumberいいえ最大出力トークン数
metadataobjectいいえカスタム key-value ペア(最大 16 個)
storebooleanいいえ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... ]
}'
パラメーター型必須説明
modelstringはい圧縮に使用するモデル
inputarrayはい圧縮するメッセージ配列
instructionsstringいいえ要約用のカスタム指示

圧縮済みの要約オブジェクトを返します。次のリクエストの input にそのまま置けます。

備考

WebSocket アクセス(wss://.../v1/responses の response.create イベント)は、ゲートウェイの WS パススルー対応に依存します — REST + SSE がクライアント統合の主要経路であり、ここでは扱いません。