{"id":1749,"date":"2026-07-26T17:06:39","date_gmt":"2026-07-26T09:06:39","guid":{"rendered":"https:\/\/www.imaseo.com\/blog\/?p=1749"},"modified":"2026-06-02T16:25:07","modified_gmt":"2026-06-02T08:25:07","slug":"codex-cli-custom-model-gateway-pitfalls","status":"publish","type":"post","link":"https:\/\/www.imaseo.com\/blog\/ai-tools\/codex-cli-custom-model-gateway-pitfalls","title":{"rendered":"Codex CLI \u63a5\u5230\u81ea\u5b9a\u4e49\u6a21\u578b\u7f51\u5173\u8e29\u4e86\u54ea\u4e9b\u5751\uff1f"},"content":{"rendered":"<p>Codex CLI \u63a5\u5230\u81ea\u5b9a\u4e49\u6a21\u578b\u7f51\u5173\u8e29\u4e86\u54ea\u4e9b\u5751\uff1f<\/p>\n<p>\u6700\u8fd1\u5728\u628a Codex CLI \u63a5\u5165\u81ea\u5efa\u7684\u6a21\u578b\u7f51\u5173\u65f6\uff0c\u53d1\u73b0\u770b\u4f3c\u201c\u6539\u4e2a Base URL + Key\u201d\u5c31\u80fd\u641e\u5b9a\u7684\u4e8b\uff0c\u5b9e\u9645\u64cd\u4f5c\u8d77\u6765\u5374\u5904\u5904\u662f\u5751\u3002\u7edf\u4e00\u7ba1\u7406 API Key\u3001\u5408\u5e76\u8c03\u7528\u65e5\u5fd7\u3001\u5b9e\u73b0\u591a\u6a21\u578b\u5207\u6362\u2026\u2026\u8fd9\u4e9b\u9700\u6c42\u90fd\u6307\u5411\u540c\u4e00\u4e2a\u89e3\u51b3\u65b9\u6848\uff1a\u81ea\u5efa OpenAI-compatible \u7f51\u5173\u3002\u4f46\u771f\u6b63\u843d\u5730\u4e4b\u540e\uff0c\u534f\u8bae\u5dee\u5f02\u3001\u9274\u6743\u903b\u8f91\u3001\u6d41\u5f0f\u54cd\u5e94\u7b49\u7ec6\u8282\u95ee\u9898\u63a5\u8e35\u800c\u81f3\u3002<\/p>\n<p>\u672c\u6587\u7ed3\u5408\u771f\u5b9e\u8e29\u5751\u7ecf\u5386\uff0c\u68b3\u7406 Codex CLI \u5bf9\u63a5\u81ea\u5efa\u7f51\u5173\u65f6\u6700\u5bb9\u6613\u7ffb\u8f66\u7684 5 \u4e2a\u73af\u8282\uff0c\u5e76\u7ed9\u51fa\u53ef\u843d\u5730\u7684\u907f\u5751\u65b9\u6848\u3002<\/p>\n<h2>1. \u534f\u8bae\u683c\u5f0f\u4e0d\u517c\u5bb9\uff1aResponses API \u4e0e Chat Completions \u7684\u9e3f\u6c9f<\/h2>\n<p>Codex CLI \u9ed8\u8ba4\u8d70 OpenAI \u7684 Responses API\uff0c\u800c\u5927\u591a\u6570\u56fd\u4ea7\u6a21\u578b\u6216\u81ea\u5efa\u7f51\u5173\u53ea\u5b9e\u73b0\u4e86 Chat Completions\u3002\u4e24\u8005\u5728\u6d88\u606f\u7ed3\u6784\u3001\u5de5\u5177\u8c03\u7528\u683c\u5f0f\u3001\u6d41\u5f0f\u4e8b\u4ef6\u5b57\u6bb5\u4e0a\u90fd\u6709\u5dee\u5f02\uff0c\u76f4\u63a5\u8f6c\u53d1\u8bf7\u6c42\u5927\u6982\u7387\u5931\u8d25\u3002<\/p>\n<p><strong>\u907f\u5751\u8981\u70b9<\/strong>\uff1a<br \/>\n&#8211; \u7f51\u5173\u5fc5\u987b\u505a\u534f\u8bae\u8f6c\u6362\uff0c\u628a Codex \u7684 <code>\/v1\/responses<\/code> \u8bf7\u6c42\u91cd\u5199\u4e3a\u4e0a\u6e38\u7684 <code>\/v1\/chat\/completions<\/code>\u3002<br \/>\n&#8211; \u6d41\u5f0f\u54cd\u5e94\u8981\u91cd\u5efa SSE \u4e8b\u4ef6\uff0c\u628a <code>delta.content<\/code> \u6620\u5c04\u56de Codex \u671f\u671b\u7684 <code>response.output_text.delta<\/code> \u683c\u5f0f\u3002<br \/>\n&#8211; \u5de5\u5177\u8c03\u7528\uff08function call\uff09\u9700\u8981\u53cc\u5411\u8f6c\u6362 JSON Schema\uff0c\u5426\u5219 Codex \u4f1a\u8ba4\u4e3a\u6a21\u578b\u4e0d\u652f\u6301\u5de5\u5177\u3002<\/p>\n<h2>2. \u9274\u6743\u4e0e Key \u7ba1\u7406\u6df7\u4e71<\/h2>\n<p>Codex CLI \u53ea\u8ba4 <code>OPENAI_API_KEY<\/code> \u73af\u5883\u53d8\u91cf\uff0c\u800c\u81ea\u5efa\u7f51\u5173\u901a\u5e38\u9700\u8981\u72ec\u7acb\u7684 Gateway Key + \u540e\u7aef Provider Key \u4e24\u5c42\u9274\u6743\u3002\u76f4\u63a5\u628a Provider Key \u5199\u8fdb Codex \u914d\u7f6e\uff0c\u65e2\u4e0d\u5b89\u5168\uff0c\u4e5f\u65e0\u6cd5\u5b9e\u73b0\u56e2\u961f\u7ea7\u7edf\u4e00\u7ba1\u7406\u3002<\/p>\n<p><strong>\u907f\u5751\u8981\u70b9<\/strong>\uff1a<br \/>\n&#8211; \u5728\u7f51\u5173\u5c42\u505a Key \u6620\u5c04\uff1aCodex \u7528 Gateway Key\uff0c\u7f51\u5173\u5185\u90e8\u518d\u8def\u7531\u5230\u4e0d\u540c Provider \u7684\u771f\u5b9e Key\u3002<br \/>\n&#8211; \u5f00\u542f Key \u8f6e\u6362\u4e0e\u7528\u91cf\u914d\u989d\uff0c\u907f\u514d\u5355 Key \u8d85\u989d\u5bfc\u81f4\u6574\u4e2a\u56e2\u961f\u670d\u52a1\u4e2d\u65ad\u3002<\/p>\n<h2>3. \u4f1a\u8bdd\u72b6\u6001\u4e0e\u4e0a\u4e0b\u6587\u4e22\u5931<\/h2>\n<p>Responses API \u652f\u6301 <code>previous_response_id<\/code> \u5b9e\u73b0\u591a\u8f6e\u5bf9\u8bdd\uff0c\u800c Chat Completions \u4f9d\u8d56\u5b8c\u6574 messages \u6570\u7ec4\u3002\u7f51\u5173\u5982\u679c\u4e0d\u6301\u4e45\u5316\u5386\u53f2\u6d88\u606f\uff0cCodex \u7684\u8fde\u7eed\u8ffd\u95ee\u5c31\u4f1a\u65ad\u5c42\u3002<\/p>\n<p><strong>\u907f\u5751\u8981\u70b9<\/strong>\uff1a<br \/>\n&#8211; \u7f51\u5173\u7528 SQLite \u6216 Redis \u7f13\u5b58\u4f1a\u8bdd ID \u4e0e\u5386\u53f2\u6d88\u606f\uff0c\u9ed8\u8ba4\u4fdd\u7559 7 \u5929\u3002<br \/>\n&#8211; \u91cd\u542f\u670d\u52a1\u540e\u4f1a\u8bdd\u4e0d\u4e22\u5931\uff0c\u786e\u4fdd Codex \u7684\u957f\u65f6\u6bb5\u4efb\u52a1\uff08\u5982\u5927\u578b\u91cd\u6784\uff09\u4e0d\u4e2d\u65ad\u3002<\/p>\n<h2>4. \u6a21\u578b\u540d\u6620\u5c04\u4e0e\u80fd\u529b\u58f0\u660e\u4e0d\u4e00\u81f4<\/h2>\n<p>Codex CLI \u5728\u542f\u52a8\u65f6\u4f1a\u6821\u9a8c\u6a21\u578b\u662f\u5426\u5b58\u5728\u5e76\u62c9\u53d6\u80fd\u529b\u5217\u8868\u3002\u81ea\u5efa\u7f51\u5173\u82e5\u76f4\u63a5\u900f\u4f20\u6a21\u578b\u540d\uff0cCodex \u53ef\u80fd\u62a5\u201cmodel not found\u201d\u6216\u65e0\u6cd5\u8bc6\u522b\u5de5\u5177\/\u7ed3\u6784\u5316\u8f93\u51fa\u80fd\u529b\u3002<\/p>\n<p><strong>\u907f\u5751\u8981\u70b9<\/strong>\uff1a<br \/>\n&#8211; \u7f51\u5173\u63d0\u4f9b\u6a21\u578b\u522b\u540d\u6620\u5c04\u8868\uff0c\u4f8b\u5982\u628a <code>deepseek-chat<\/code> \u6620\u5c04\u4e3a Codex \u53ef\u89c1\u7684 <code>gpt-4o-mini<\/code>\u3002<br \/>\n&#8211; \u80fd\u529b\u58f0\u660e\u63a5\u53e3\uff08<code>\/v1\/models<\/code>\uff09\u9700\u8fd4\u56de Codex \u5173\u5fc3\u7684\u53c2\u6570\uff0c\u5982 <code>supports_tools<\/code>\u3001<code>supports_vision<\/code> \u7b49\u5b57\u6bb5\u3002<\/p>\n<h2>5. \u6d41\u5f0f\u8f93\u51fa\u4e0e\u9519\u8bef\u6062\u590d\u673a\u5236\u7f3a\u5931<\/h2>\n<p>Codex CLI \u4f9d\u8d56\u7a33\u5b9a\u7684 SSE \u6d41\u6765\u5b9e\u65f6\u5c55\u793a\u63a8\u7406\u8fc7\u7a0b\u3002\u81ea\u5efa\u7f51\u5173\u82e5\u7b80\u5355\u8f6c\u53d1\uff0c\u4e00\u65e6\u4e0a\u6e38\u4e2d\u65ad\u6216\u7f51\u7edc\u6296\u52a8\uff0cCodex \u4f1a\u76f4\u63a5\u629b\u51fa\u201cstream interrupted\u201d\u9519\u8bef\uff0c\u4e14\u65e0\u6cd5\u81ea\u52a8\u91cd\u8bd5\u3002<\/p>\n<p><strong>\u907f\u5751\u8981\u70b9<\/strong>\uff1a<br \/>\n&#8211; \u7f51\u5173\u5b9e\u73b0\u65ad\u70b9\u7eed\u4f20\uff1a\u8bb0\u5f55\u6700\u540e\u6536\u5230\u7684 <code>sequence_id<\/code>\uff0c\u4e2d\u65ad\u540e\u81ea\u52a8\u91cd\u8fde\u5e76\u8865\u53d1\u7f3a\u5931\u4e8b\u4ef6\u3002<br \/>\n&#8211; \u5bf9\u4e0a\u6e38\u9519\u8bef\u505a\u53cb\u597d\u5305\u88c5\uff0c\u628a 429\/500 \u9519\u8bef\u8f6c\u5316\u4e3a Codex \u53ef\u7406\u89e3\u7684\u201c\u8bf7\u7a0d\u540e\u91cd\u8bd5\u201d\u63d0\u793a\uff0c\u907f\u514d CLI \u76f4\u63a5\u9000\u51fa\u3002<\/p>\n<h2>5 \u6b65\u5feb\u901f\u9a8c\u8bc1\u914d\u7f6e\u662f\u5426\u53ef\u7528<\/h2>\n<ol>\n<li>\u5b89\u88c5 Node.js\uff08macOS \u7528 Homebrew\uff0cWindows \u63a8\u8350 WSL2\uff09\u3002<\/li>\n<li>\u5168\u5c40\u5b89\u88c5 Codex CLI\uff1a<code>npm install -g @openai\/codex<\/code>\u3002<\/li>\n<li>\u90e8\u7f72\u6216\u9009\u7528\u5df2\u652f\u6301 Responses API \u7684\u7f51\u5173\uff08\u5982 LLMEX\u3001GodeX\uff09\u3002<\/li>\n<li>\u914d\u7f6e\u73af\u5883\u53d8\u91cf\uff1a<br \/>\n   <code>bash<br \/>\n   export OPENAI_BASE_URL=http:\/\/localhost:3000<br \/>\n   export OPENAI_API_KEY=gateway-key<\/code><\/li>\n<li>\u8fdb\u5165\u9879\u76ee\u76ee\u5f55\u6267\u884c <code>codex<\/code>\uff0c\u89c2\u5bdf\u662f\u5426\u80fd\u6b63\u5e38\u53d1\u8d77\u8bf7\u6c42\u5e76\u8fd4\u56de\u6d41\u5f0f\u7ed3\u679c\u3002<\/li>\n<\/ol>\n<p>\u8e29\u8fc7\u4e0a\u8ff0\u5751\u4e4b\u540e\uff0c\u4f60\u4f1a\u53d1\u73b0\uff1aCodex CLI \u63a5\u5165\u81ea\u5efa\u7f51\u5173\u7684\u6838\u5fc3\u96be\u70b9\u4e0d\u5728\u201c\u80fd\u4e0d\u80fd\u901a\u201d\uff0c\u800c\u5728\u201c\u901a\u4e86\u4e4b\u540e\u662f\u5426\u7a33\u5b9a\u3001\u662f\u5426\u53ef\u89c2\u6d4b\u3001\u662f\u5426\u80fd\u5e73\u6ed1\u5207\u6362\u591a\u6a21\u578b\u201d\u3002\u628a\u534f\u8bae\u8f6c\u6362\u3001\u4f1a\u8bdd\u6301\u4e45\u5316\u3001\u6a21\u578b\u6620\u5c04\u3001\u6d41\u5f0f\u91cd\u5efa\u8fd9\u51e0\u5c42\u8fb9\u754c\u5904\u7406\u5e72\u51c0\uff0c\u624d\u80fd\u771f\u6b63\u5b9e\u73b0\u201c\u96f6\u4fb5\u5165\u201d\u5730\u7edf\u4e00\u7ba1\u7406\u6240\u6709 AI \u7f16\u7801\u5de5\u5177\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Codex CLI \u63a5\u5230\u81ea\u5b9a\u4e49\u6a21\u578b\u7f51\u5173\u8e29\u4e86\u54ea\u4e9b\u5751\uff1f \u6700\u8fd1\u5728\u628a Codex CLI \u63a5\u5165\u81ea\u5efa\u7684\u6a21\u578b\u7f51\u5173\u65f6\uff0c\u53d1\u73b0\u770b\u4f3c\u201c\u6539\u4e2a \u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1749","post","type-post","status-publish","format-standard","hentry","category-ai-tools"],"_links":{"self":[{"href":"https:\/\/www.imaseo.com\/blog\/wp-json\/wp\/v2\/posts\/1749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.imaseo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.imaseo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.imaseo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.imaseo.com\/blog\/wp-json\/wp\/v2\/comments?post=1749"}],"version-history":[{"count":1,"href":"https:\/\/www.imaseo.com\/blog\/wp-json\/wp\/v2\/posts\/1749\/revisions"}],"predecessor-version":[{"id":1750,"href":"https:\/\/www.imaseo.com\/blog\/wp-json\/wp\/v2\/posts\/1749\/revisions\/1750"}],"wp:attachment":[{"href":"https:\/\/www.imaseo.com\/blog\/wp-json\/wp\/v2\/media?parent=1749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.imaseo.com\/blog\/wp-json\/wp\/v2\/categories?post=1749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.imaseo.com\/blog\/wp-json\/wp\/v2\/tags?post=1749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}