{
  "title": "OpenAI Chat Completions (HTTP)",
  "content": "OpenClaw’s Gateway can serve a small OpenAI-compatible Chat Completions endpoint.\n\nThis endpoint is **disabled by default**. Enable it in config first.\n\n* `POST /v1/chat/completions`\n* Same port as the Gateway (WS + HTTP multiplex): `http://<gateway-host>:<port>/v1/chat/completions`\n\nUnder the hood, requests are executed as a normal Gateway agent run (same codepath as `openclaw agent`), so routing/permissions/config match your Gateway.\n\nUses the Gateway auth configuration. Send a bearer token:\n\n* `Authorization: Bearer <token>`\n\n* When `gateway.auth.mode=\"token\"`, use `gateway.auth.token` (or `OPENCLAW_GATEWAY_TOKEN`).\n* When `gateway.auth.mode=\"password\"`, use `gateway.auth.password` (or `OPENCLAW_GATEWAY_PASSWORD`).\n\nNo custom headers required: encode the agent id in the OpenAI `model` field:\n\n* `model: \"openclaw:<agentId>\"` (example: `\"openclaw:main\"`, `\"openclaw:beta\"`)\n* `model: \"agent:<agentId>\"` (alias)\n\nOr target a specific OpenClaw agent by header:\n\n* `x-openclaw-agent-id: <agentId>` (default: `main`)\n\n* `x-openclaw-session-key: <sessionKey>` to fully control session routing.\n\n## Enabling the endpoint\n\nSet `gateway.http.endpoints.chatCompletions.enabled` to `true`:\n\n## Disabling the endpoint\n\nSet `gateway.http.endpoints.chatCompletions.enabled` to `false`:\n\nBy default the endpoint is **stateless per request** (a new session key is generated each call).\n\nIf the request includes an OpenAI `user` string, the Gateway derives a stable session key from it, so repeated calls can share an agent session.\n\nSet `stream: true` to receive Server-Sent Events (SSE):\n\n* `Content-Type: text/event-stream`\n* Each event line is `data: <json>`\n* Stream ends with `data: [DONE]`",
  "code_samples": [
    {
      "code": "## Disabling the endpoint\n\nSet `gateway.http.endpoints.chatCompletions.enabled` to `false`:",
      "language": "unknown"
    },
    {
      "code": "## Session behavior\n\nBy default the endpoint is **stateless per request** (a new session key is generated each call).\n\nIf the request includes an OpenAI `user` string, the Gateway derives a stable session key from it, so repeated calls can share an agent session.\n\n## Streaming (SSE)\n\nSet `stream: true` to receive Server-Sent Events (SSE):\n\n* `Content-Type: text/event-stream`\n* Each event line is `data: <json>`\n* Stream ends with `data: [DONE]`\n\n## Examples\n\nNon-streaming:",
      "language": "unknown"
    },
    {
      "code": "Streaming:",
      "language": "unknown"
    }
  ],
  "headings": [
    {
      "level": "h2",
      "text": "Authentication",
      "id": "authentication"
    },
    {
      "level": "h2",
      "text": "Choosing an agent",
      "id": "choosing-an-agent"
    },
    {
      "level": "h2",
      "text": "Enabling the endpoint",
      "id": "enabling-the-endpoint"
    },
    {
      "level": "h2",
      "text": "Disabling the endpoint",
      "id": "disabling-the-endpoint"
    },
    {
      "level": "h2",
      "text": "Session behavior",
      "id": "session-behavior"
    },
    {
      "level": "h2",
      "text": "Streaming (SSE)",
      "id": "streaming-(sse)"
    },
    {
      "level": "h2",
      "text": "Examples",
      "id": "examples"
    }
  ],
  "url": "llms-txt#openai-chat-completions-(http)",
  "links": []
}