OpenResponses API(HTTP)

OpenClaw の Gateway は、OpenResponses 互換の POST /v1/responses エンドポイントを提供できます。

このエンドポイントはデフォルトで無効です。まず config で有効にしてください。

  • POST /v1/responses
  • Gateway と同じポート(WS + HTTP 多重化):http://<gateway-host>:<port>/v1/responses

内部的には、リクエストは通常の Gateway エージェント実行として処理されます(openclaw agent と同じコードパス)。そのため、ルーティング/権限/config は Gateway と一致します。

認証

Gateway の auth 設定を使用します。bearer トークンを送信してください:

  • Authorization: Bearer <token>

注意:

  • gateway.auth.mode="token" の場合、gateway.auth.token(または OPENCLAW_GATEWAY_TOKEN)を使用してください。
  • gateway.auth.mode="password" の場合、gateway.auth.password(または OPENCLAW_GATEWAY_PASSWORD)を使用してください。

エージェントの選択

カスタムヘッダーは不要です:エージェント ID を OpenResponses の model フィールドにエンコードしてください:

  • model: "openclaw:<agentId>"(例:"openclaw:main""openclaw:beta"
  • model: "agent:<agentId>"(エイリアス)

またはヘッダーで特定の OpenClaw エージェントをターゲットにします:

  • x-openclaw-agent-id: <agentId>(デフォルト:main

高度な設定:

  • x-openclaw-session-key: <sessionKey> でセッションルーティングを完全に制御できます。

エンドポイントの有効化

gateway.http.endpoints.responses.enabledtrue に設定してください:

{
  gateway: {
    http: {
      endpoints: {
        responses: { enabled: true }
      }
    }
  }
}

エンドポイントの無効化

gateway.http.endpoints.responses.enabledfalse に設定してください:

{
  gateway: {
    http: {
      endpoints: {
        responses: { enabled: false }
      }
    }
  }
}

セッション動作

デフォルトでは、エンドポイントはリクエストごとにステートレスです(呼び出しごとに新しいセッションキーが生成されます)。

リクエストに OpenResponses の user 文字列が含まれている場合、Gateway はそれから安定したセッションキーを導出するため、繰り返し呼び出しでエージェントセッションを共有できます。

リクエスト形式(サポート)

リクエストは、アイテムベースの入力を持つ OpenResponses API に従います。現在のサポート:

  • input:文字列またはアイテムオブジェクトの配列
  • instructions:システムプロンプトにマージされます
  • tools:クライアントツール定義(function tools)
  • tool_choice:クライアントツールのフィルターまたは要求
  • stream:SSE ストリーミングを有効化
  • max_output_tokens:ベストエフォートの出力制限(プロバイダー依存)
  • user:安定したセッションルーティング

受け入れられますが現在は無視されます:

  • max_tool_calls
  • reasoning
  • metadata
  • store
  • previous_response_id
  • truncation

アイテム(input)

message

ロール:systemdeveloperuserassistant

  • systemdeveloper はシステムプロンプトに追加されます。
  • 最新の user または function_call_output アイテムが「現在のメッセージ」になります。
  • 以前の user/assistant メッセージはコンテキストの履歴として含まれます。

function_call_output(ターンベースツール)

ツール結果をモデルに返送します:

{
  "type": "function_call_output",
  "call_id": "call_123",
  "output": "{\"temperature\": \"72F\"}"
}

reasoningitem_reference

スキーマ互換性のため受け入れられますが、プロンプト構築時には無視されます。

ツール(クライアント側 function tools)

tools: [{ type: "function", function: { name, description?, parameters? } }] でツールを提供します。

エージェントがツールを呼び出すことを決定すると、レスポンスは function_call 出力アイテムを返します。 その後、function_call_output を含むフォローアップリクエストを送信してターンを続けます。

画像(input_image

base64 または URL ソースをサポート:

{
  "type": "input_image",
  "source": { "type": "url", "url": "https://example.com/image.png" }
}

許可される MIME タイプ(現在):image/jpegimage/pngimage/gifimage/webp 最大サイズ(現在):10MB

ファイル(input_file

base64 または URL ソースをサポート:

{
  "type": "input_file",
  "source": {
    "type": "base64",
    "media_type": "text/plain",
    "data": "SGVsbG8gV29ybGQh",
    "filename": "hello.txt"
  }
}

許可される MIME タイプ(現在):text/plaintext/markdowntext/htmltext/csvapplication/jsonapplication/pdf

最大サイズ(現在):5MB

現在の動作:

  • ファイルコンテンツはデコードされ、ユーザーメッセージではなくシステムプロンプトに追加されます(エフェメラルで、セッション履歴に保存されません)。
  • PDF はテキスト用にパースされます。テキストがほとんど見つからない場合、最初のページが画像にラスタライズされてモデルに渡されます。

PDF パースは Node フレンドリーな pdfjs-dist レガシービルドを使用します(ワーカーなし)。モダンな PDF.js ビルドはブラウザワーカー/DOM グローバルを期待するため、Gateway では使用されません。

URL フェッチのデフォルト:

  • files.allowUrltrue
  • images.allowUrltrue
  • リクエストは保護されています(DNS 解決、プライベート IP ブロック、リダイレクト上限、タイムアウト)。

ファイル + 画像の制限(config)

デフォルトは gateway.http.endpoints.responses で調整できます:

{
  gateway: {
    http: {
      endpoints: {
        responses: {
          enabled: true,
          maxBodyBytes: 20000000,
          files: {
            allowUrl: true,
            allowedMimes: ["text/plain", "text/markdown", "text/html", "text/csv", "application/json", "application/pdf"],
            maxBytes: 5242880,
            maxChars: 200000,
            maxRedirects: 3,
            timeoutMs: 10000,
            pdf: {
              maxPages: 4,
              maxPixels: 4000000,
              minTextChars: 200
            }
          },
          images: {
            allowUrl: true,
            allowedMimes: ["image/jpeg", "image/png", "image/gif", "image/webp"],
            maxBytes: 10485760,
            maxRedirects: 3,
            timeoutMs: 10000
          }
        }
      }
    }
  }
}

省略時のデフォルト:

  • maxBodyBytes:20MB
  • files.maxBytes:5MB
  • files.maxChars:200k
  • files.maxRedirects:3
  • files.timeoutMs:10秒
  • files.pdf.maxPages:4
  • files.pdf.maxPixels:4,000,000
  • files.pdf.minTextChars:200
  • images.maxBytes:10MB
  • images.maxRedirects:3
  • images.timeoutMs:10秒

ストリーミング(SSE)

Server-Sent Events(SSE)を受信するには stream: true を設定してください:

  • Content-Type: text/event-stream
  • 各イベント行は event: <type>data: <json>
  • ストリームは data: [DONE] で終了

現在発行されるイベントタイプ:

  • response.created
  • response.in_progress
  • response.output_item.added
  • response.content_part.added
  • response.output_text.delta
  • response.output_text.done
  • response.content_part.done
  • response.output_item.done
  • response.completed
  • response.failed(エラー時)

使用状況

基盤となるプロバイダーがトークン数を報告する場合、usage が入力されます。

エラー

エラーは次のような JSON オブジェクトを使用します:

{ "error": { "message": "...", "type": "invalid_request_error" } }

一般的なケース:

  • 401 認証の欠落/無効
  • 400 無効なリクエストボディ
  • 405 間違ったメソッド

ノンストリーミング:

curl -sS http://127.0.0.1:18789/v1/responses \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -H 'x-openclaw-agent-id: main' \
  -d '{
    "model": "openclaw",
    "input": "hi"
  }'

ストリーミング:

curl -N http://127.0.0.1:18789/v1/responses \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -H 'x-openclaw-agent-id: main' \
  -d '{
    "model": "openclaw",
    "stream": true,
    "input": "hi"
  }'