{"id":133,"date":"2026-03-21T22:47:19","date_gmt":"2026-03-21T14:47:19","guid":{"rendered":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/gateway-openai-http-api\/"},"modified":"2026-03-21T23:28:52","modified_gmt":"2026-03-21T15:28:52","slug":"gateway-openai-http-api","status":"publish","type":"post","link":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/gateway-openai-http-api\/","title":{"rendered":"OpenAI Chat Completions"},"content":{"rendered":"<h1>OpenAI Chat Completions<\/h1>\n<h1>OpenAI Chat Completions\uff08HTTP\uff09<\/h1>\n<p>OpenClaw \u7684 Gateway \u7f51\u5173 \u7f51\u5173\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2a\u5c0f\u578b\u7684 OpenAI \u517c\u5bb9 Chat Completions \u7aef\u70b9\u3002<\/p>\n<p>\u6b64\u7aef\u70b9<strong>\u9ed8\u8ba4\u7981\u7528<\/strong>\u3002\u8bf7\u5148\u5728\u914d\u7f6e\u4e2d\u542f\u7528\u5b83\u3002<\/p>\n<ul>\n<li><code>POST \/v1\/chat\/completions<\/code><\/li>\n<li>\u4e0e Gateway \u7f51\u5173 \u7f51\u5173\u76f8\u540c\u7684\u7aef\u53e3\uff08WS + HTTP \u591a\u8def\u590d\u7528\uff09\uff1a<code>http:\/\/&lt;gateway-host&gt;:&lt;port&gt;\/v1\/chat\/completions<\/code><\/li>\n<\/ul>\n<p>\u5e95\u5c42\u5b9e\u73b0\u4e2d\uff0c\u8bf7\u6c42\u4f5c\u4e3a\u666e\u901a\u7684 Gateway \u7f51\u5173 \u7f51\u5173\u667a\u80fd\u4f53\u8fd0\u884c\u6267\u884c\uff08\u4e0e <code>openclaw agent<\/code> \u76f8\u540c\u7684\u4ee3\u7801\u8def\u5f84\uff09\uff0c\u56e0\u6b64\u8def\u7531\/\u6743\u9650\/\u914d\u7f6e\u4e0e\u4f60\u7684 Gateway \u7f51\u5173 \u7f51\u5173\u4e00\u81f4\u3002<\/p>\n<h2>\u8ba4\u8bc1<\/h2>\n<p>\u4f7f\u7528 Gateway \u7f51\u5173 \u7f51\u5173\u8ba4\u8bc1\u914d\u7f6e\u3002\u53d1\u9001 bearer \u4ee4\u724c\uff1a<\/p>\n<ul>\n<li><code>Authorization: Bearer &lt;token&gt;<\/code><\/li>\n<\/ul>\n<p>\u6ce8\u610f\u4e8b\u9879\uff1a<\/p>\n<ul>\n<li>\u5f53 <code>gateway.auth.mode=\"token\"<\/code> \u65f6\uff0c\u4f7f\u7528 <code>gateway.auth.token<\/code>\uff08\u6216 <code>OPENCLAW_GATEWAY_TOKEN<\/code>\uff09\u3002<\/li>\n<li>\u5f53 <code>gateway.auth.mode=\"password\"<\/code> \u65f6\uff0c\u4f7f\u7528 <code>gateway.auth.password<\/code>\uff08\u6216 <code>OPENCLAW_GATEWAY_PASSWORD<\/code>\uff09\u3002<\/li>\n<\/ul>\n<h2>\u9009\u62e9\u667a\u80fd\u4f53<\/h2>\n<p>\u65e0\u9700\u81ea\u5b9a\u4e49\u5934\uff1a\u5728 OpenAI <code>model<\/code> \u5b57\u6bb5\u4e2d\u7f16\u7801\u667a\u80fd\u4f53 ID\uff1a<\/p>\n<ul>\n<li><code>model: \"openclaw:&lt;agentId&gt;\"<\/code>\uff08\u4f8b\u5982\uff1a<code>\"openclaw:main\"<\/code>\u3001<code>\"openclaw:beta\"<\/code>\uff09<\/li>\n<li><code>model: \"agent:&lt;agentId&gt;\"<\/code>\uff08\u522b\u540d\uff09<\/li>\n<\/ul>\n<p>\u6216\u901a\u8fc7\u5934\u6307\u5b9a\u7279\u5b9a\u7684 OpenClaw \u667a\u80fd\u4f53\uff1a<\/p>\n<ul>\n<li><code>x-openclaw-agent-id: &lt;agentId&gt;<\/code>\uff08\u9ed8\u8ba4\uff1a<code>main<\/code>\uff09<\/li>\n<\/ul>\n<p>\u9ad8\u7ea7\u9009\u9879\uff1a<\/p>\n<ul>\n<li><code>x-openclaw-session-key: &lt;sessionKey&gt;<\/code> \u5b8c\u5168\u63a7\u5236\u4f1a\u8bdd\u8def\u7531\u3002<\/li>\n<\/ul>\n<h2>\u542f\u7528\u7aef\u70b9<\/h2>\n<p>\u5c06 <code>gateway.http.endpoints.chatCompletions.enabled<\/code> \u8bbe\u7f6e\u4e3a <code>true<\/code>\uff1a<\/p>\n<p>&#8220;`json5  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{<br \/>\n  \u7f51\u5173: {<br \/>\n    http: {<br \/>\n      endpoints: {<br \/>\n        chatCompletions: { enabled: true },<br \/>\n      },<br \/>\n    },<br \/>\n  },<br \/>\n}<\/p>\n<pre><code>\n## \u7981\u7528\u7aef\u70b9\n\n\u5c06 `gateway.http.endpoints.chatCompletions.enabled` \u8bbe\u7f6e\u4e3a `false`\uff1a\n\n```json5  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{\n  gateway: {\n    http: {\n      endpoints: {\n        chatCompletions: { enabled: false },\n      },\n    },\n  },\n}\n<\/code><\/pre>\n<h2>\u4f1a\u8bdd\u884c\u4e3a<\/h2>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u7aef\u70b9\u662f<strong>\u6bcf\u8bf7\u6c42\u65e0\u72b6\u6001<\/strong>\u7684\uff08\u6bcf\u6b21\u8c03\u7528\u751f\u6210\u65b0\u7684\u4f1a\u8bdd\u952e\uff09\u3002<\/p>\n<p>\u5982\u679c\u8bf7\u6c42\u5305\u542b OpenAI <code>user<\/code> \u5b57\u7b26\u4e32\uff0cGateway \u7f51\u5173 \u7f51\u5173\u4f1a\u4ece\u4e2d\u6d3e\u751f\u4e00\u4e2a\u7a33\u5b9a\u7684\u4f1a\u8bdd\u952e\uff0c\u56e0\u6b64\u91cd\u590d\u8c03\u7528\u53ef\u4ee5\u5171\u4eab\u667a\u80fd\u4f53\u4f1a\u8bdd\u3002<\/p>\n<h2>\u6d41\u5f0f\u4f20\u8f93\uff08SSE\uff09<\/h2>\n<p>\u8bbe\u7f6e <code>stream: true<\/code> \u4ee5\u63a5\u6536 Server-Sent Events\uff08SSE\uff09\uff1a<\/p>\n<ul>\n<li><code>Content-Type: text\/event-stream<\/code><\/li>\n<li>\u6bcf\u4e2a\u4e8b\u4ef6\u884c\u662f <code>data: &lt;json&gt;<\/code><\/li>\n<li>\u6d41\u4ee5 <code>data: [DONE]<\/code> \u7ed3\u675f<\/li>\n<\/ul>\n<h2>\u793a\u4f8b<\/h2>\n<p>\u975e\u6d41\u5f0f\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\ncurl -sS http:\/\/127.0.0.1:18789\/v1\/chat\/completions<br \/>\n  -H &#8216;Authorization: Bearer YOUR_TOKEN&#8217;<br \/>\n  -H &#8216;Content-Type: application\/json&#8217;<br \/>\n  -H &#8216;x-openclaw-agent-id: main&#8217;<br \/>\n  -d &#8216;{<br \/>\n    &#8220;model&#8221;: &#8220;openclaw&#8221;,<br \/>\n    &#8220;messages&#8221;: [{&#8220;role&#8221;:&#8221;user&#8221;,&#8221;content&#8221;:&#8221;hi&#8221;}]<br \/>\n  }&#8217;<\/p>\n<pre><code>\n\u6d41\u5f0f\uff1a\n\n```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\ncurl -N http:\/\/127.0.0.1:18789\/v1\/chat\/completions \n  -H 'Authorization: Bearer YOUR_TOKEN' \n  -H 'Content-Type: application\/json' \n  -H 'x-openclaw-agent-id: main' \n  -d '{\n    &quot;model&quot;: &quot;openclaw&quot;,\n    &quot;stream&quot;: true,\n    &quot;messages&quot;: [{&quot;role&quot;:&quot;user&quot;,&quot;content&quot;:&quot;hi&quot;}]\n  }'\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>OpenAI Chat Completions OpenAI Chat Completions\uff08HTTP\uff09 O [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-133","post","type-post","status-publish","format-standard","hentry","category-docs"],"_links":{"self":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":2,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":816,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/133\/revisions\/816"}],"wp:attachment":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}