<?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: LLMCoder</title>
    <description>The latest articles on DEV Community by LLMCoder (@llmcoder).</description>
    <link>https://dev.to/llmcoder</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%2F4251836%2F27eeddc4-7dde-49bc-af1a-820511e40e6b.png</url>
      <title>DEV Community: LLMCoder</title>
      <link>https://dev.to/llmcoder</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/llmcoder"/>
    <language>en</language>
    <item>
      <title>Claude Code with your own gateway: five places it breaks</title>
      <dc:creator>LLMCoder</dc:creator>
      <pubDate>Wed, 18 Nov 2026 13:12:35 +0000</pubDate>
      <link>https://dev.to/llmcoder/claude-code-with-your-own-gateway-five-places-it-breaks-4eh2</link>
      <guid>https://dev.to/llmcoder/claude-code-with-your-own-gateway-five-places-it-breaks-4eh2</guid>
      <description>&lt;p&gt;The task looked like a five-minute job: point Claude Code at a compatible endpoint instead of the native Anthropic API. I set the environment variables in the morning and spent the evening figuring out why the CLI stayed silent.&lt;/p&gt;

&lt;p&gt;What follows is five places where the connection breaks. Not "how to set it up" — "why it is not working", because the second question is the one people search at 3 a.m. Every error below was reproduced on a live setup; the configs are at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a compatible endpoint actually is
&lt;/h2&gt;

&lt;p&gt;Claude Code is an ordinary HTTP client. It does not "integrate with Anthropic"; it sends a POST to &lt;code&gt;/v1/messages&lt;/code&gt; in the Anthropic Messages API shape and reads an SSE stream. All it needs is a server that answers in that shape. The native Anthropic API is just one option.&lt;/p&gt;

&lt;p&gt;That is the first fork in the road, and where people get lost: &lt;strong&gt;compatibility comes in two flavours&lt;/strong&gt;. OpenAI-compatible (&lt;code&gt;/v1/chat/completions&lt;/code&gt;) and Anthropic-compatible (&lt;code&gt;/v1/messages&lt;/code&gt;). Claude Code needs the second. Cursor, Cline and Codex mostly need the first. A gateway that only speaks OpenAI is useless for Claude Code, no matter how many models it lists.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 1: &lt;code&gt;/v1&lt;/code&gt; in the base URL
&lt;/h2&gt;

&lt;p&gt;The most common one. OpenAI-compatible SDKs expect &lt;code&gt;base_url = https://host/v1&lt;/code&gt;, and the client appends &lt;code&gt;/chat/completions&lt;/code&gt;. Claude Code does the opposite: &lt;code&gt;ANTHROPIC_BASE_URL&lt;/code&gt; takes the &lt;strong&gt;host without &lt;code&gt;/v1&lt;/code&gt;&lt;/strong&gt;, and it appends &lt;code&gt;/v1/messages&lt;/code&gt; itself.&lt;/p&gt;

&lt;p&gt;Set &lt;code&gt;https://host/v1&lt;/code&gt; and you get a request to &lt;code&gt;/v1/v1/messages&lt;/code&gt; and a 404 that shows up in the client log as "model not found" or "invalid request", because the request body itself was valid.&lt;/p&gt;

&lt;p&gt;Rule of thumb: two different base URLs for two protocols. Use the same one everywhere and one of the two will break.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 2: &lt;code&gt;ANTHROPIC_AUTH_TOKEN&lt;/code&gt; versus &lt;code&gt;ANTHROPIC_API_KEY&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Claude Code can authenticate two ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ANTHROPIC_API_KEY&lt;/code&gt; → the &lt;code&gt;x-api-key&lt;/code&gt; header;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ANTHROPIC_AUTH_TOKEN&lt;/code&gt; → the &lt;code&gt;Authorization: Bearer …&lt;/code&gt; header.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Gateways usually accept one of the two. The key itself can be perfectly valid and the answer is still 401. One command tells you which:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -s -o /dev/null -w &lt;span class="s2"&gt;"%{http_code}\n"&lt;/span&gt; https://host/v1/models \
  -H &lt;span class="s2"&gt;"x-api-key: $KEY"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you only get 200 with &lt;code&gt;Authorization: Bearer&lt;/code&gt;, you need &lt;code&gt;ANTHROPIC_AUTH_TOKEN&lt;/code&gt;, not &lt;code&gt;ANTHROPIC_API_KEY&lt;/code&gt;. And vice versa.&lt;/p&gt;

&lt;p&gt;A variant of the same problem: a native Anthropic key instead of the gateway key. Same 401, but the error text usually tells you which endpoint produced it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 3: model names
&lt;/h2&gt;

&lt;p&gt;Claude Code picks the model from environment variables:&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;ANTHROPIC_MODEL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;ANTHROPIC_DEFAULT_SONNET_MODEL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;ANTHROPIC_DEFAULT_OPUS_MODEL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The name has to exist in the gateway catalog character for character. &lt;code&gt;claude-sonnet-4-6&lt;/code&gt; from Anthropic docs and &lt;code&gt;claude-sonnet-5-5&lt;/code&gt; from a provider are two different identifiers, and the second is under no obligation to be an alias of the first.&lt;/p&gt;

&lt;p&gt;Check it with the same &lt;code&gt;GET /v1/models&lt;/code&gt;: the response must contain exactly the id you typed. If it does not, the CLI either gets a 404 on the model or silently falls back to the gateway default. The second is worse: it works, just not on the model you think.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 4: streaming that is "sort of supported"
&lt;/h2&gt;

&lt;p&gt;Claude Code streams over SSE on &lt;code&gt;/v1/messages&lt;/code&gt;. That works almost everywhere.&lt;/p&gt;

&lt;p&gt;It breaks where a tool calls &lt;code&gt;/v1/responses&lt;/code&gt; (Codex CLI, some assistants) and the gateway either does not implement that path or implements it without streaming, answering 400 to &lt;code&gt;stream: true&lt;/code&gt;. The error text is usually useless, so test it up front: &lt;code&gt;curl&lt;/code&gt; with &lt;code&gt;"stream": true&lt;/code&gt; against the path you need, before you point a production task at the tool.&lt;/p&gt;

&lt;p&gt;The practical takeaway: "OpenAI-compatible" ≠ "supports everything OpenAI does". Compatibility of request shape and compatibility of behaviour are two different things.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 5: billing and limits
&lt;/h2&gt;

&lt;p&gt;An agent is not a chat. It makes dozens of calls per task, drags context around and happily re-reads files. Without an upper bound on spend, one refactoring run eats the balance and you find out from an email.&lt;/p&gt;

&lt;p&gt;What the gateway side needs in order to fix this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a per-key limit (in money or tokens), separate from the account balance;&lt;/li&gt;
&lt;li&gt;distinguishable 402 and 429 — "out of money" and "too many requests" need different reactions, and collapsing them into one "error" is a bad idea;&lt;/li&gt;
&lt;li&gt;a log with model, tokens and price at the time of the request, not "approximately".&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Diagnostic checklist
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;curl $BASE/v1/models&lt;/code&gt; with your key → 200 and a model list. If not, the problem is auth or the address, and Claude Code is still far away.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;claude /status&lt;/code&gt; → shows the base URL and the models the CLI actually uses.&lt;/li&gt;
&lt;li&gt;One short request → a log line with tokens. No line means the request never arrived.&lt;/li&gt;
&lt;li&gt;401 → key or header form. 402 → balance or key limit. 403 → model not allowed for the key, or IP not on the list. 429 → rate. 404 on a model → the name.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The full config
&lt;/h2&gt;

&lt;p&gt;Through the shell:&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;ANTHROPIC_BASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://llmcode.io"&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;"sk-llmcode-..."&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;ANTHROPIC_DEFAULT_SONNET_MODEL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"claude-sonnet-5-5"&lt;/span&gt;

claude /status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Through &lt;code&gt;~/.claude/settings.json&lt;/code&gt; — more reliable, it survives a new terminal tab:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"ANTHROPIC_BASE_URL"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://llmcode.io"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"ANTHROPIC_AUTH_TOKEN"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"sk-llmcode-..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"ANTHROPIC_DEFAULT_SONNET_MODEL"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"claude-sonnet-5-5"&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;A step-by-step version with the response codes explained lives in the &lt;a href="https://llmcode.io/ru/clusters/claude-code-api" rel="noopener noreferrer"&gt;Claude Code guide&lt;/a&gt; (RU), and the compatible-endpoint overview with published per-token prices is &lt;a href="https://llmcode.io/clusters/openai-compatible-api" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Full disclosure: I run &lt;a href="https://llmcode.io" rel="noopener noreferrer"&gt;LLMcode&lt;/a&gt;, the gateway used in the examples above. It is a prepaid balance with a per-key spend cap, crypto top-up, and both API shapes behind one URL — no card, no subscription. The traps above are the same for any gateway, including this one, which is why they are worth checking before you commit to a provider.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this is not
&lt;/h2&gt;

&lt;p&gt;A compatible endpoint is not native access. Latency and limits depend on the upstream, not on your code, and nobody gives Anthropic-grade SLA guarantees there. If the tool is critical in production, the behavioural difference between a channel and the native API is a risk to price in before migration, not after.&lt;/p&gt;

&lt;p&gt;There is exactly one upside: one key and one bill for every tool that lets you change the base URL. For local development, agents and scripts that is usually enough.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>api</category>
      <category>devtools</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
