<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[HZAPI Dev Notes]]></title><description><![CDATA[HZAPI Dev Notes]]></description><link>https://hzapi.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 20:44:25 GMT</lastBuildDate><atom:link href="https://hzapi.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Why your LLM gateway returns 404: the /v1 rule for Claude Code vs OpenAI SDKs]]></title><description><![CDATA[If you've pointed a tool at a custom LLM gateway and got a 404, the cause is usually not your key or the model. It's one path segment: /v1. I maintain a…]]></description><link>https://hzapi.hashnode.dev/why-your-llm-gateway-returns-404-the-v1-rule-for-claude-code-vs-openai-sdks</link><guid isPermaLink="true">https://hzapi.hashnode.dev/why-your-llm-gateway-returns-404-the-v1-rule-for-claude-code-vs-openai-sdks</guid><category><![CDATA[llm]]></category><category><![CDATA[api]]></category><category><![CDATA[openai]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Wenhao Ma]]></dc:creator><pubDate>Thu, 03 Dec 2026 16:39:14 GMT</pubDate><content:encoded><![CDATA[<p>If you've pointed a tool at a custom LLM gateway and got a <code>404</code>, the cause is usually not your key or the model. It's one path segment: <code>/v1</code>.</p>
<p>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.</p>
<h2>The rule</h2>
<table>
<thead>
<tr>
<th>Client</th>
<th>Base URL</th>
</tr>
</thead>
<tbody><tr>
<td>Claude Code, Anthropic SDK, Cline (Anthropic mode)</td>
<td><code>https://api.hzapi.vip</code> (no <code>/v1</code>)</td>
</tr>
<tr>
<td>OpenAI SDKs, Codex, Cursor, Cherry Studio, Dify, n8n</td>
<td><code>https://api.hzapi.vip/v1</code></td>
</tr>
</tbody></table>
<p>Why: Anthropic clients treat the Base URL as a root and append <code>/v1/messages</code> themselves, so a trailing <code>/v1</code> produces <code>/v1/v1/messages</code>. OpenAI clients expect the Base URL to already end in <code>/v1</code> and append <code>/chat/completions</code> or <code>/responses</code>, so a bare root produces <code>/chat/completions</code> with no version. Both are 404s that look identical.</p>
<h2>Separate "client config" from "key/group" with curl</h2>
<pre><code class="language-bash">export HZAPI_API_KEY="sk-xxxx"   # placeholder
curl -sS https://api.hzapi.vip/v1/models -H "Authorization: Bearer $HZAPI_API_KEY"
</code></pre>
<p>A <code>200</code> 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.)</p>
<p>The three protocols side by side:</p>
<pre><code class="language-bash"># Chat Completions
curl -sS https://api.hzapi.vip/v1/chat/completions \
  -H "Content-Type: application/json" -H "Authorization: Bearer $HZAPI_API_KEY" \
  -d '{"model":"deepseek-v4-pro","messages":[{"role":"user","content":"ping"}]}'

# Responses
curl -sS https://api.hzapi.vip/v1/responses \
  -H "Content-Type: application/json" -H "Authorization: Bearer $HZAPI_API_KEY" \
  -d '{"model":"gpt-6.2-astra","input":"ping"}'

# Anthropic Messages
curl -sS https://api.hzapi.vip/v1/messages \
  -H "x-api-key: $HZAPI_API_KEY" -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model":"claude-fable-5-2","max_tokens":64,"messages":[{"role":"user","content":"ping"}]}'
</code></pre>
<p>(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.)</p>
<h2>Claude Code</h2>
<pre><code class="language-bash">export ANTHROPIC_BASE_URL="https://api.hzapi.vip"
export ANTHROPIC_AUTH_TOKEN="$HZAPI_API_KEY"
claude --model claude-fable-5-2
</code></pre>
<p>From Claude Code's own docs:</p>
<ul>
<li><code>ANTHROPIC_AUTH_TOKEN</code> is sent as <code>Authorization: Bearer ...</code>; <code>ANTHROPIC_API_KEY</code> is sent as <code>X-Api-Key</code>. Don't set both.</li>
<li>Setting only <code>ANTHROPIC_BASE_URL</code> leaves a saved claude.ai login as the active credential, so you still send the wrong credential to the gateway.</li>
<li>Run <code>/status</code> and check for the <code>Anthropic base URL</code> line and the credential source.</li>
<li>An auth-conflict warning means a login and a gateway credential are both active: <code>/logout</code> keeps the gateway credential.</li>
<li><code>400 ... Extra inputs are not permitted</code>: try <code>CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1</code>.</li>
</ul>
<h2>OpenAI-style tools</h2>
<p><strong>Python</strong></p>
<pre><code class="language-python">import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["HZAPI_API_KEY"], base_url="https://api.hzapi.vip/v1")
print(client.responses.create(model="gpt-6.2-astra", input="One-line summary of idempotent retries").output_text)
</code></pre>
<p><strong>Dify</strong>: install the official <em>OpenAI-API-compatible</em> plugin; API Base URL is the <code>/v1</code> address; Model Name must match an ID from <code>/v1/models</code> exactly; raise the default 4096 context size to the model's real limit.</p>
<p><strong>n8n</strong>: in the OpenAI credential change <em>Base URL</em> (default <code>https://api.openai.com/v1</code>) to the <code>/v1</code> address and leave Organization ID empty. The credential test calls <code>{Base URL}/models</code>.</p>
<p><strong>Cherry Studio</strong>: add a custom provider with an OpenAI endpoint (<code>/v1</code>) and/or an Anthropic endpoint (root), fetch the model list, add models, and turn the provider's enable switch on.</p>
<p><strong>Cline / Continue</strong>: Anthropic mode takes the root; OpenAI-compatible mode takes <code>/v1</code>. Continue defaults to <code>/responses</code> for o-series and gpt-5 models; add <code>useResponsesApi: false</code> if your model doesn't support it.</p>
<p><strong>Cursor</strong>: Settings → Models → API Keys → <em>Override OpenAI Base URL</em> = the <code>/v1</code> address. It's global (affects Cursor's own OpenAI-family models too) and doesn't apply to Tab.</p>
<h2>Error table</h2>
<table>
<thead>
<tr>
<th>Status</th>
<th>Usual cause</th>
<th>Fix</th>
</tr>
</thead>
<tbody><tr>
<td>404</td>
<td><code>/v1</code> doubled or missing; <code>/chat/completions</code> pasted into the Base URL</td>
<td>See the rule above</td>
</tr>
<tr>
<td>401</td>
<td>Truncated key, whitespace, key from a different site</td>
<td>Re-copy it</td>
</tr>
<tr>
<td><code>model_not_found</code></td>
<td>Model not in the key's group</td>
<td>Use IDs from <code>GET /v1/models</code></td>
</tr>
<tr>
<td>403</td>
<td>Balance or sub-token quota exhausted</td>
<td>Check the console</td>
</tr>
<tr>
<td>410</td>
<td>Retired host still configured</td>
<td>Use the current gateway host</td>
</tr>
<tr>
<td>429</td>
<td>Burst concurrency or tight retry loop</td>
<td>Exponential backoff with jitter</td>
</tr>
<tr>
<td>Timeout / 502 / 504</td>
<td>Long reasoning before first token; a proxy cutting idle connections at 60s</td>
<td>Stream, 180s+ timeout, check <code>proxy_read_timeout</code></td>
</tr>
</tbody></table>
<p>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.</p>
<h2>Samples</h2>
<p>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:</p>
<p><a href="https://github.com/Sakcyb/hzapi-examples?utm_source=hashnode">https://github.com/Sakcyb/hzapi-examples?utm_source=hashnode</a> (MIT, no real keys; <code>.env.example</code> uses <code>sk-xxxx</code>)</p>
<p>Official docs for the gateway: <a href="https://hziai.cc/guide/?utm_source=hashnode">https://hziai.cc/guide/?utm_source=hashnode</a></p>
<p><em>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.</em></p>
]]></content:encoded></item></channel></rss>