<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Wenhao Ma</title>
    <description>The latest articles on DEV Community by Wenhao Ma (@hzapi).</description>
    <link>https://dev.to/hzapi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4281040%2F403ce4fe-cc56-4195-8e63-0130b587f47d.png</url>
      <title>DEV Community: Wenhao Ma</title>
      <link>https://dev.to/hzapi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hzapi"/>
    <language>en</language>
    <item>
      <title>Codex CLI custom provider: fixing "unexpected status 404 Not Found" and "wire_api = chat is no longer supported"</title>
      <dc:creator>Wenhao Ma</dc:creator>
      <pubDate>Thu, 03 Dec 2026 16:47:23 +0000</pubDate>
      <link>https://dev.to/hzapi/codex-cli-custom-provider-fixing-unexpected-status-404-not-found-and-wireapi-chat-is-no-2ja6</link>
      <guid>https://dev.to/hzapi/codex-cli-custom-provider-fixing-unexpected-status-404-not-found-and-wireapi-chat-is-no-2ja6</guid>
      <description>&lt;p&gt;Recent Codex CLI versions speak one wire protocol: the &lt;strong&gt;Responses API&lt;/strong&gt; (&lt;code&gt;wire_api = "chat"&lt;/code&gt; has been removed). If you point it at a third-party gateway and the first prompt fails, it is almost always one of three things: the &lt;code&gt;base_url&lt;/code&gt; is missing &lt;code&gt;/v1&lt;/code&gt;, an old &lt;code&gt;wire_api = "chat"&lt;/code&gt; line is still in your config, or the profile you defined is no longer being read. This post walks through all three with a working config. I use &lt;a href="https://hziai.cc/?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=codex-custom-provider-404" rel="noopener noreferrer"&gt;HZAPI (HZ AI)&lt;/a&gt; as the example gateway because I maintain it, but the config shape is the same for any gateway that serves &lt;code&gt;POST /v1/responses&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Every key below is a placeholder (&lt;code&gt;sk-xxxx&lt;/code&gt;). Put your real key in an environment variable, never in a repo.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The error messages, matched to causes
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What Codex prints&lt;/th&gt;
&lt;th&gt;Cause&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;unexpected status 404 Not Found: ... url: https://api.hzapi.vip/responses&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;base_url&lt;/code&gt; has no &lt;code&gt;/v1&lt;/code&gt;; Codex appends &lt;code&gt;/responses&lt;/code&gt; to whatever you wrote&lt;/td&gt;
&lt;td&gt;&lt;code&gt;base_url = "https://api.hzapi.vip/v1"&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;unexpected status 404 Not Found: ... url: https://.../v1/responses/responses&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;You pasted the full endpoint into &lt;code&gt;base_url&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;End &lt;code&gt;base_url&lt;/code&gt; at &lt;code&gt;/v1&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;`wire_api = "chat"` is no longer supported&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Old blog-post config; Codex stops at config load and sends no request&lt;/td&gt;
&lt;td&gt;Set &lt;code&gt;wire_api = "responses"&lt;/code&gt; or delete the line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;unexpected status 401 Unauthorized&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The key reached the gateway but was not accepted: truncated, wrong group, or a key from another site&lt;/td&gt;
&lt;td&gt;Re-copy the key; check &lt;code&gt;requires_openai_auth&lt;/code&gt; (below)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Missing environment variable: HZAPI_API_KEY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;env_key&lt;/code&gt; names a variable that is empty in the shell that started Codex&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;export HZAPI_API_KEY=...&lt;/code&gt; in that shell&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Profile settings seem ignored&lt;/td&gt;
&lt;td&gt;Newer Codex versions read profiles from a separate file (below)&lt;/td&gt;
&lt;td&gt;Move the settings to &lt;code&gt;~/.codex/&amp;lt;name&amp;gt;.config.toml&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;url:&lt;/code&gt; at the end of a 404 is the most useful part of the message. It shows exactly what Codex called. Compare it with the URL you expect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why &lt;code&gt;/v1&lt;/code&gt; matters here
&lt;/h2&gt;

&lt;p&gt;Codex builds the request URL itself: it takes &lt;code&gt;base_url&lt;/code&gt;, trims a trailing slash and appends &lt;code&gt;responses&lt;/code&gt;. So:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;
&lt;code&gt;base_url&lt;/code&gt; you wrote&lt;/th&gt;
&lt;th&gt;URL Codex calls&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip/responses&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;404&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip/v1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip/v1/responses&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;correct&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip/v1/responses&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;.../v1/responses/responses&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;404&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is the opposite of Claude Code, which wants the root address without &lt;code&gt;/v1&lt;/code&gt;. HZ AI's official guide has a table of which client takes which address: &lt;a href="https://hziai.cc/guide/?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=codex-custom-provider-404" rel="noopener noreferrer"&gt;guide, section 02&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: test the endpoint without Codex
&lt;/h2&gt;

&lt;p&gt;Separate "gateway problem" from "Codex config problem" with one &lt;code&gt;curl&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;HZAPI_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"sk-xxxx"&lt;/span&gt;

&lt;span class="c"&gt;# free: lists the models this key can use&lt;/span&gt;
curl -sS https://api.hzapi.vip/v1/models -H &lt;span class="s2"&gt;"Authorization: Bearer $HZAPI_API_KEY"&lt;/span&gt;

&lt;span class="c"&gt;# the call Codex will make (this one is a real, billed request)&lt;/span&gt;
curl -sS -w &lt;span class="s1"&gt;'\n%{http_code}\n'&lt;/span&gt; https://api.hzapi.vip/v1/responses \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $HZAPI_API_KEY"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"model":"gpt-6.2-astra","input":"Reply with: ok"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;A JSON answer means the gateway speaks Responses and the key works.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;404&lt;/code&gt; means that path does not exist on that host. Check the host and &lt;code&gt;/v1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;401&lt;/code&gt; means the key is wrong or not accepted.&lt;/li&gt;
&lt;li&gt;A model error means the model is not in your key's group. On HZAPI a key is bound to one group, so take the model ID from the &lt;code&gt;/v1/models&lt;/code&gt; call above, not from a blog post. &lt;code&gt;gpt-6.2-astra&lt;/code&gt; is the example from HZ AI's own guide.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: write the provider block
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;~/.codex/config.toml&lt;/code&gt; (on Windows &lt;code&gt;%USERPROFILE%\.codex\config.toml&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="na"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gpt-6.2-astra"&lt;/span&gt;          &lt;span class="c1"&gt;# an ID from your /v1/models call&lt;/span&gt;
&lt;span class="na"&gt;model_provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"hzapi"&lt;/span&gt;

&lt;span class="k"&gt;[model_providers.hzapi]&lt;/span&gt;
&lt;span class="na"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"HZ AI"&lt;/span&gt;
&lt;span class="na"&gt;base_url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.hzapi.vip/v1"&lt;/span&gt;
&lt;span class="na"&gt;env_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"HZAPI_API_KEY"&lt;/span&gt;
&lt;span class="na"&gt;wire_api&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"responses"&lt;/span&gt;            &lt;span class="c1"&gt;# the only supported value; you can also omit the line&lt;/span&gt;
&lt;span class="na"&gt;requires_openai_auth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details that cause silent mistakes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;TOML table scope.&lt;/strong&gt; Everything after a &lt;code&gt;[model_providers.hzapi]&lt;/code&gt; header belongs to that table. &lt;code&gt;model = ...&lt;/code&gt; and &lt;code&gt;model_provider = ...&lt;/code&gt; must sit &lt;strong&gt;above&lt;/strong&gt; the first &lt;code&gt;[...]&lt;/code&gt; header, or Codex reads them as provider fields and ignores them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Two credential paths.&lt;/strong&gt; With &lt;code&gt;requires_openai_auth = true&lt;/code&gt;, Codex uses the OpenAI-style login and ignores &lt;code&gt;env_key&lt;/code&gt;. For a gateway key you want &lt;code&gt;false&lt;/code&gt; plus &lt;code&gt;env_key&lt;/code&gt;. HZ AI's guide uses the same pair.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;HZAPI_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"sk-xxxx"&lt;/span&gt;
codex
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: use it as a profile without touching your normal login
&lt;/h2&gt;

&lt;p&gt;HZ AI's guide shows a &lt;code&gt;[profiles.hzapi]&lt;/code&gt; table inside &lt;code&gt;config.toml&lt;/code&gt;. OpenAI's Codex docs say that from &lt;strong&gt;Codex 0.134.0&lt;/strong&gt; &lt;code&gt;--profile&lt;/code&gt; no longer reads &lt;code&gt;[profiles.&amp;lt;name&amp;gt;]&lt;/code&gt; from &lt;code&gt;config.toml&lt;/code&gt;; instead it loads &lt;code&gt;~/.codex/&amp;lt;name&amp;gt;.config.toml&lt;/code&gt; as a layer on top. If your profile "does nothing" on a recent version, this is why.&lt;/p&gt;

&lt;p&gt;Keep the provider block in &lt;code&gt;config.toml&lt;/code&gt; (as above, without the &lt;code&gt;model&lt;/code&gt; / &lt;code&gt;model_provider&lt;/code&gt; lines) and put only the differences in a profile file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# ~/.codex/hzapi.config.toml
&lt;/span&gt;&lt;span class="na"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gpt-6.2-astra"&lt;/span&gt;
&lt;span class="na"&gt;model_provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"hzapi"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;codex --profile hzapi
codex &lt;span class="nb"&gt;exec&lt;/span&gt; --profile hzapi &lt;span class="s2"&gt;"explain this repo's build"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your default (official login) setup keeps working when you run plain &lt;code&gt;codex&lt;/code&gt;. Check &lt;code&gt;codex --version&lt;/code&gt; and read the docs for your version: &lt;a href="https://developers.openai.com/codex/config-advanced" rel="noopener noreferrer"&gt;Advanced configuration&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  If it fails mid-answer instead of at the start
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;stream disconnected before completion&lt;/code&gt; is a different problem: the connection closed before the final &lt;code&gt;response.completed&lt;/code&gt; event. That is almost always a proxy, VPN or client timeout in between, not your config. See my write-up on &lt;a href="https://github.com/Sakcyb/hzapi-examples/blob/main/docs/en/06-streaming-disconnects.md" rel="noopener noreferrer"&gt;streams that stop mid-response&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;curl .../v1/models&lt;/code&gt; returns your model list.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;curl .../v1/responses&lt;/code&gt; returns JSON.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;base_url&lt;/code&gt; ends at &lt;code&gt;/v1&lt;/code&gt;, &lt;code&gt;wire_api&lt;/code&gt; is &lt;code&gt;responses&lt;/code&gt; or absent.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;model&lt;/code&gt; and &lt;code&gt;model_provider&lt;/code&gt; are above every &lt;code&gt;[table]&lt;/code&gt; header.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;HZAPI_API_KEY&lt;/code&gt; is exported in the shell that starts Codex.&lt;/li&gt;
&lt;li&gt;On new Codex versions, profiles live in &lt;code&gt;~/.codex/&amp;lt;name&amp;gt;.config.toml&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When asking anyone for help, share the last 4 characters of the key, the model name and the time of the failure. Never the full key.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Disclosure: I maintain HZAPI. The example repo with Python, Node and curl samples is &lt;a href="https://github.com/Sakcyb/hzapi-examples" rel="noopener noreferrer"&gt;Sakcyb/hzapi-examples&lt;/a&gt; (MIT). Billing on HZAPI is usage-based; live rates are on its model plaza, so I don't quote any here.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>codex</category>
      <category>openai</category>
      <category>llm</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>OpenAI SDK with a custom base_url: fixing 404 "Invalid URL (POST /chat/completions)", 401 and model_not_found</title>
      <dc:creator>Wenhao Ma</dc:creator>
      <pubDate>Thu, 03 Dec 2026 16:34:42 +0000</pubDate>
      <link>https://dev.to/hzapi/openai-sdk-with-a-custom-baseurl-fixing-404-invalid-url-post-chatcompletions-401-and-58pk</link>
      <guid>https://dev.to/hzapi/openai-sdk-with-a-custom-baseurl-fixing-404-invalid-url-post-chatcompletions-401-and-58pk</guid>
      <description>&lt;p&gt;You changed &lt;code&gt;base_url&lt;/code&gt; to a third-party OpenAI-compatible gateway and got one of these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openai.NotFoundError: Error code: 404 - {'message': 'Invalid URL (POST /chat/completions)'}
openai.AuthenticationError: Error code: 401 - ...
openai.NotFoundError: Error code: 404 - ... model_not_found ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All three are "not found / not allowed" errors but they mean different things, and the SDK will tell you which one if you look at the right thing. Examples use &lt;a href="https://hziai.cc/?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=openai-sdk-custom-base-url" rel="noopener noreferrer"&gt;HZAPI (HZ AI)&lt;/a&gt;, a gateway I maintain; the flow works for any OpenAI-compatible endpoint.&lt;/p&gt;

&lt;h2&gt;
  
  
  The one rule
&lt;/h2&gt;

&lt;p&gt;The official OpenAI SDKs treat &lt;code&gt;base_url&lt;/code&gt; as the &lt;strong&gt;prefix&lt;/strong&gt; and append the resource path to it (&lt;code&gt;/chat/completions&lt;/code&gt;, &lt;code&gt;/responses&lt;/code&gt;, &lt;code&gt;/models&lt;/code&gt;). So the prefix must already contain the version segment:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;You set &lt;code&gt;base_url&lt;/code&gt; to&lt;/th&gt;
&lt;th&gt;SDK calls&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip/chat/completions&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;404 &lt;code&gt;Invalid URL (POST /chat/completions)&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip/v1&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip/v1/chat/completions&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;works&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip/v1/chat/completions&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;.../v1/chat/completions/chat/completions&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;404&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip/v1/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;.../v1/chat/completions&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;works (trailing slash is harmless)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Anthropic-style clients are the other way round (they want the root, no &lt;code&gt;/v1&lt;/code&gt;). HZ AI's guide has the full table per client: &lt;a href="https://hziai.cc/guide/?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=openai-sdk-custom-base-url" rel="noopener noreferrer"&gt;guide, section 02&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: print the URL the SDK is really using
&lt;/h2&gt;

&lt;p&gt;Don't guess. Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;log_request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&amp;gt;&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"HZAPI_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.hzapi.vip/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;http_client&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;httpx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event_hooks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"request"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;log_request&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"base_url:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    &lt;span class="c1"&gt;# free call, no tokens used&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt; line is the truth. If it shows &lt;code&gt;/chat/completions&lt;/code&gt; with no &lt;code&gt;/v1&lt;/code&gt;, you found your 404. You can also set &lt;code&gt;OPENAI_LOG=debug&lt;/code&gt; in the environment; the SDK then logs requests itself.&lt;/p&gt;

&lt;p&gt;Node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"openai"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;HZAPI_API_KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://api.hzapi.vip/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"baseURL:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;baseURL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// free call&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;client.models.list()&lt;/code&gt; doubles as the connectivity test: it hits &lt;code&gt;GET /v1/models&lt;/code&gt;, spends nothing, and shows which model IDs your key can use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: read the status code correctly
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;th&gt;What it means&lt;/th&gt;
&lt;th&gt;What to do&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;404&lt;/code&gt; with a path in the message (&lt;code&gt;Invalid URL (POST /chat/completions)&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;The &lt;strong&gt;path&lt;/strong&gt; doesn't exist on that host&lt;/td&gt;
&lt;td&gt;Fix &lt;code&gt;base_url&lt;/code&gt; as above&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;404&lt;/code&gt;/&lt;code&gt;400&lt;/code&gt; mentioning &lt;code&gt;model_not_found&lt;/code&gt; or "model does not exist"&lt;/td&gt;
&lt;td&gt;The path is fine; the &lt;strong&gt;model ID&lt;/strong&gt; isn't available to this key&lt;/td&gt;
&lt;td&gt;Take an ID from &lt;code&gt;models.list()&lt;/code&gt;. On HZAPI a key is bound to one group and the group decides the models&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;401&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Path and model are fine; the &lt;strong&gt;key&lt;/strong&gt; was rejected: truncated, stray whitespace/newline, or a key from a different site&lt;/td&gt;
&lt;td&gt;Re-copy it; &lt;code&gt;echo ${HZAPI_API_KEY:0:6}&lt;/code&gt; to check it's loaded&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;403&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Key valid, but balance or sub-token quota is used up&lt;/td&gt;
&lt;td&gt;Check the console&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;410&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;You still use a retired host&lt;/td&gt;
&lt;td&gt;HZAPI's retired host is &lt;code&gt;zlapi.hzapi.vip&lt;/code&gt;; switch to &lt;code&gt;https://api.hzapi.vip&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;429&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Burst limits&lt;/td&gt;
&lt;td&gt;Back off with jitter: 1 s, 2 s, 4 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Tip: a &lt;code&gt;401&lt;/code&gt; is &lt;em&gt;good news&lt;/em&gt; for URL debugging. It proves the URL is right and only the key is wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: use environment variables so tools inherit it
&lt;/h2&gt;

&lt;p&gt;The official SDKs read &lt;code&gt;OPENAI_API_KEY&lt;/code&gt; and &lt;code&gt;OPENAI_BASE_URL&lt;/code&gt; when you don't pass them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;OPENAI_BASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.hzapi.vip/v1"&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;OPENAI_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$HZAPI_API_KEY"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="c1"&gt;# picks both up from the environment&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"deepseek-v4-pro"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;    &lt;span class="c1"&gt;# an ID from your models.list()&lt;/span&gt;
    &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"role"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"user"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ping"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Many tools built on the SDK (LangChain-style wrappers, agents, notebooks) honour the same variables, which is why a single &lt;code&gt;export&lt;/code&gt; often fixes "my tool ignores my base URL". If a tool has its own field, it usually wants the same &lt;code&gt;/v1&lt;/code&gt; form.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: when the model is a "Responses" model
&lt;/h2&gt;

&lt;p&gt;Some models are served through the Responses API, not Chat Completions. Same base URL, different method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;responses&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gpt-6.2-astra"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"ping"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;output_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;gpt-6.2-astra&lt;/code&gt; is the Responses example in HZ AI's own guide. If a model works on &lt;code&gt;/v1/responses&lt;/code&gt; but fails on &lt;code&gt;/v1/chat/completions&lt;/code&gt; (or the reverse), that's about the model's group and protocol, not about &lt;code&gt;base_url&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;base_url&lt;/code&gt; ends exactly at &lt;code&gt;/v1&lt;/code&gt; (Anthropic clients: no &lt;code&gt;/v1&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;client.models.list()&lt;/code&gt; returns IDs.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;model&lt;/code&gt; string is copied from that list.&lt;/li&gt;
&lt;li&gt;The key has no spaces or newline (&lt;code&gt;.strip()&lt;/code&gt; it if it comes from a file).&lt;/li&gt;
&lt;li&gt;For streams that die halfway, see &lt;a href="https://github.com/Sakcyb/hzapi-examples/blob/main/docs/en/06-streaming-disconnects.md" rel="noopener noreferrer"&gt;this guide&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you ask for help, send only the last 4 characters of the key, the model name and the time. Never the full key.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Disclosure: I maintain HZAPI. Runnable Python, Node and curl samples are in &lt;a href="https://github.com/Sakcyb/hzapi-examples" rel="noopener noreferrer"&gt;Sakcyb/hzapi-examples&lt;/a&gt; (MIT). Billing is usage-based; live rates are on the HZ AI model plaza, so I quote none.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>openai</category>
      <category>python</category>
      <category>node</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Why your LLM gateway returns 404: the /v1 rule for Claude Code vs OpenAI SDKs</title>
      <dc:creator>Wenhao Ma</dc:creator>
      <pubDate>Thu, 03 Dec 2026 16:14:51 +0000</pubDate>
      <link>https://dev.to/hzapi/why-your-llm-gateway-returns-404-the-v1-rule-for-claude-code-vs-openai-sdks-4pli</link>
      <guid>https://dev.to/hzapi/why-your-llm-gateway-returns-404-the-v1-rule-for-claude-code-vs-openai-sdks-4pli</guid>
      <description>&lt;p&gt;If you've pointed a tool at a custom LLM gateway and got a &lt;code&gt;404&lt;/code&gt;, the cause is usually not your key or the model. It's one path segment: &lt;code&gt;/v1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I maintain a gateway called HZAPI (public brand HZ AI) and this is the most common support question I see. The rule below is true for any gateway that serves both the Anthropic Messages and OpenAI-compatible APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The rule
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Client&lt;/th&gt;
&lt;th&gt;Base URL&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Claude Code, Anthropic SDK, Cline (Anthropic mode)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;https://api.hzapi.vip&lt;/code&gt; (no &lt;code&gt;/v1&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OpenAI SDKs, Codex, Cursor, Cherry Studio, Dify, n8n&lt;/td&gt;
&lt;td&gt;&lt;code&gt;https://api.hzapi.vip/v1&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Why: Anthropic clients treat the Base URL as a root and append &lt;code&gt;/v1/messages&lt;/code&gt; themselves, so a trailing &lt;code&gt;/v1&lt;/code&gt; produces &lt;code&gt;/v1/v1/messages&lt;/code&gt;. OpenAI clients expect the Base URL to already end in &lt;code&gt;/v1&lt;/code&gt; and append &lt;code&gt;/chat/completions&lt;/code&gt; or &lt;code&gt;/responses&lt;/code&gt;, so a bare root produces &lt;code&gt;/chat/completions&lt;/code&gt; with no version. Both are 404s that look identical.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate "client config" from "key/group" with curl
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;HZAPI_API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"sk-xxxx"&lt;/span&gt;   &lt;span class="c"&gt;# placeholder&lt;/span&gt;
curl -sS https://api.hzapi.vip/v1/models -H &lt;span class="s2"&gt;"Authorization: Bearer $HZAPI_API_KEY"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;code&gt;200&lt;/code&gt; with a model array means network, TLS, key and group binding are fine; the problem is in the client. (On HZAPI a key is bound to one group, and the group decides which models you can call. Take model IDs from this call, not from guesswork.)&lt;/p&gt;

&lt;p&gt;The three protocols side by side:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Chat Completions&lt;/span&gt;
curl -sS https://api.hzapi.vip/v1/chat/completions \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; -H &lt;span class="s2"&gt;"Authorization: Bearer $HZAPI_API_KEY"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"model":"deepseek-v4-pro","messages":[{"role":"user","content":"ping"}]}'&lt;/span&gt;

&lt;span class="c"&gt;# Responses&lt;/span&gt;
curl -sS https://api.hzapi.vip/v1/responses \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; -H &lt;span class="s2"&gt;"Authorization: Bearer $HZAPI_API_KEY"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"model":"gpt-6.2-astra","input":"ping"}'&lt;/span&gt;

&lt;span class="c"&gt;# Anthropic Messages&lt;/span&gt;
curl -sS https://api.hzapi.vip/v1/messages \
  -H &lt;span class="s2"&gt;"x-api-key: $HZAPI_API_KEY"&lt;/span&gt; -H &lt;span class="s2"&gt;"anthropic-version: 2023-06-01"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"content-type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{"model":"claude-fable-5-2","max_tokens":64,"messages":[{"role":"user","content":"ping"}]}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(The model IDs above are the examples from the gateway's own guide; availability depends on your key's group and is listed on its model plaza.)&lt;/p&gt;

&lt;h2&gt;
  
  
  Claude Code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;ANTHROPIC_BASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.hzapi.vip"&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;ANTHROPIC_AUTH_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$HZAPI_API_KEY"&lt;/span&gt;
claude --model claude-fable-5-2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From Claude Code's own docs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ANTHROPIC_AUTH_TOKEN&lt;/code&gt; is sent as &lt;code&gt;Authorization: Bearer ...&lt;/code&gt;; &lt;code&gt;ANTHROPIC_API_KEY&lt;/code&gt; is sent as &lt;code&gt;X-Api-Key&lt;/code&gt;. Don't set both.&lt;/li&gt;
&lt;li&gt;Setting only &lt;code&gt;ANTHROPIC_BASE_URL&lt;/code&gt; leaves a saved claude.ai login as the active credential, so you still send the wrong credential to the gateway.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;/status&lt;/code&gt; and check for the &lt;code&gt;Anthropic base URL&lt;/code&gt; line and the credential source.&lt;/li&gt;
&lt;li&gt;An auth-conflict warning means a login and a gateway credential are both active: &lt;code&gt;/logout&lt;/code&gt; keeps the gateway credential.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;400 ... Extra inputs are not permitted&lt;/code&gt;: try &lt;code&gt;CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  OpenAI-style tools
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Python&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"HZAPI_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://api.hzapi.vip/v1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;responses&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"gpt-6.2-astra"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"One-line summary of idempotent retries"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;output_text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Dify&lt;/strong&gt;: install the official &lt;em&gt;OpenAI-API-compatible&lt;/em&gt; plugin; API Base URL is the &lt;code&gt;/v1&lt;/code&gt; address; Model Name must match an ID from &lt;code&gt;/v1/models&lt;/code&gt; exactly; raise the default 4096 context size to the model's real limit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;n8n&lt;/strong&gt;: in the OpenAI credential change &lt;em&gt;Base URL&lt;/em&gt; (default &lt;code&gt;https://api.openai.com/v1&lt;/code&gt;) to the &lt;code&gt;/v1&lt;/code&gt; address and leave Organization ID empty. The credential test calls &lt;code&gt;{Base URL}/models&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cherry Studio&lt;/strong&gt;: add a custom provider with an OpenAI endpoint (&lt;code&gt;/v1&lt;/code&gt;) and/or an Anthropic endpoint (root), fetch the model list, add models, and turn the provider's enable switch on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cline / Continue&lt;/strong&gt;: Anthropic mode takes the root; OpenAI-compatible mode takes &lt;code&gt;/v1&lt;/code&gt;. Continue defaults to &lt;code&gt;/responses&lt;/code&gt; for o-series and gpt-5 models; add &lt;code&gt;useResponsesApi: false&lt;/code&gt; if your model doesn't support it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cursor&lt;/strong&gt;: Settings → Models → API Keys → &lt;em&gt;Override OpenAI Base URL&lt;/em&gt; = the &lt;code&gt;/v1&lt;/code&gt; address. It's global (affects Cursor's own OpenAI-family models too) and doesn't apply to Tab.&lt;/p&gt;

&lt;h2&gt;
  
  
  Error table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;th&gt;Usual cause&lt;/th&gt;
&lt;th&gt;Fix&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;404&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;/v1&lt;/code&gt; doubled or missing; &lt;code&gt;/chat/completions&lt;/code&gt; pasted into the Base URL&lt;/td&gt;
&lt;td&gt;See the rule above&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;401&lt;/td&gt;
&lt;td&gt;Truncated key, whitespace, key from a different site&lt;/td&gt;
&lt;td&gt;Re-copy it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;model_not_found&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Model not in the key's group&lt;/td&gt;
&lt;td&gt;Use IDs from &lt;code&gt;GET /v1/models&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;403&lt;/td&gt;
&lt;td&gt;Balance or sub-token quota exhausted&lt;/td&gt;
&lt;td&gt;Check the console&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;410&lt;/td&gt;
&lt;td&gt;Retired host still configured&lt;/td&gt;
&lt;td&gt;Use the current gateway host&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;429&lt;/td&gt;
&lt;td&gt;Burst concurrency or tight retry loop&lt;/td&gt;
&lt;td&gt;Exponential backoff with jitter&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Timeout / 502 / 504&lt;/td&gt;
&lt;td&gt;Long reasoning before first token; a proxy cutting idle connections at 60s&lt;/td&gt;
&lt;td&gt;Stream, 180s+ timeout, check &lt;code&gt;proxy_read_timeout&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;When asking any provider's support for help, send only the last 4 characters of the key, the model name and the time, never the full key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Samples
&lt;/h2&gt;

&lt;p&gt;Runnable minimal samples (Python and Node OpenAI SDKs, curl for all three protocols) plus tutorials for Claude Code, Dify, n8n, Cursor, Cline, Continue and Cherry Studio, in English and Chinese:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Sakcyb/hzapi-examples" rel="noopener noreferrer"&gt;https://github.com/Sakcyb/hzapi-examples&lt;/a&gt; (MIT, no real keys; &lt;code&gt;.env.example&lt;/code&gt; uses &lt;code&gt;sk-xxxx&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;Official docs for the gateway: &lt;a href="https://hziai.cc/guide/" rel="noopener noreferrer"&gt;https://hziai.cc/guide/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: I maintain HZAPI. The rule in this post applies to any gateway serving both protocol families. I make no claims about pricing or model availability here; see the gateway's model plaza and pricing page.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>llm</category>
      <category>api</category>
      <category>openai</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
