<?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: ModAPI</title>
    <description>The latest articles on DEV Community by ModAPI (@dedemap123sys).</description>
    <link>https://dev.to/dedemap123sys</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%2F4255255%2F246659ad-3d0f-4e83-b140-161ea821c7c3.png</url>
      <title>DEV Community: ModAPI</title>
      <link>https://dev.to/dedemap123sys</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dedemap123sys"/>
    <language>en</language>
    <item>
      <title>How to Use Claude Code with a Third-Party API Provider (ModAPI Example)</title>
      <dc:creator>ModAPI</dc:creator>
      <pubDate>Sun, 22 Nov 2026 06:48:56 +0000</pubDate>
      <link>https://dev.to/dedemap123sys/how-to-use-claude-code-with-a-third-party-api-provider-modapi-example-pag</link>
      <guid>https://dev.to/dedemap123sys/how-to-use-claude-code-with-a-third-party-api-provider-modapi-example-pag</guid>
      <description>&lt;p&gt;&lt;em&gt;Disclosure: I work on ModAPI. The general steps apply to any provider that implements the Anthropic Messages API.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Claude Code talks to Anthropic's API by default, but it doesn't have to. You can point it at a &lt;strong&gt;third-party API provider&lt;/strong&gt; or gateway that speaks the same protocol, which is handy when you want one bill for several model vendors, per-key spending limits for a team, or a different data-retention setup.&lt;/p&gt;

&lt;p&gt;This guide explains what a third-party endpoint has to support, which settings Claude Code reads, and how to set it up with ModAPI as a worked example.&lt;/p&gt;

&lt;h2&gt;
  
  
  What "third-party API" means for Claude Code
&lt;/h2&gt;

&lt;p&gt;Claude Code is not an OpenAI-compatible client. It sends requests in &lt;strong&gt;Anthropic's Messages API format&lt;/strong&gt; (&lt;code&gt;POST /v1/messages&lt;/code&gt;), including streaming events, tool use and prompt-caching fields.&lt;/p&gt;

&lt;p&gt;So the one hard requirement is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;Claude Code custom API endpoint&lt;/strong&gt; must implement the Anthropic Messages API. An endpoint that only offers OpenAI-style &lt;code&gt;/v1/chat/completions&lt;/code&gt; will not work, however many models it lists.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before you pick a provider, check its docs for an Anthropic-format endpoint, not just "OpenAI compatible". If you are comparing gateways for Claude in general, our overview of &lt;a href="https://modapi.ai/blog/claude-api-gateway/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=offsite_seo" rel="noopener noreferrer"&gt;what a Claude API gateway does&lt;/a&gt; covers the trade-offs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The settings Claude Code reads
&lt;/h2&gt;

&lt;p&gt;Claude Code picks up its endpoint and credentials from environment variables:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Variable&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ANTHROPIC_BASE_URL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Where requests go instead of Anthropic's API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ANTHROPIC_AUTH_TOKEN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sent as &lt;code&gt;Authorization: Bearer &amp;lt;token&amp;gt;&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ANTHROPIC_API_KEY&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Sent as the &lt;code&gt;x-api-key&lt;/code&gt; header (use one of the two, as your provider documents)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ANTHROPIC_MODEL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The main model Claude Code uses&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;ANTHROPIC_DEFAULT_HAIKU_MODEL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The model used when Claude Code selects the Haiku alias, including for a subagent configured to use Haiku&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;We checked this behaviour with Claude Code 2.1.329: with &lt;code&gt;ANTHROPIC_BASE_URL&lt;/code&gt; set, it sends &lt;code&gt;POST /v1/messages&lt;/code&gt; to that root with streaming on; &lt;code&gt;ANTHROPIC_AUTH_TOKEN&lt;/code&gt; is sent as a Bearer header and &lt;code&gt;ANTHROPIC_API_KEY&lt;/code&gt; as &lt;code&gt;x-api-key&lt;/code&gt;; and a subagent set to Haiku requests the model in &lt;code&gt;ANTHROPIC_DEFAULT_HAIKU_MODEL&lt;/code&gt;. Check Claude Code's &lt;a href="https://code.claude.com/docs/en/env-vars" rel="noopener noreferrer"&gt;environment variable docs&lt;/a&gt; for the current list, since names occasionally change between versions.&lt;/p&gt;

&lt;p&gt;A full Claude Code session needs more than single replies: the endpoint must stream Messages events and handle tool-use round trips (&lt;code&gt;tool_use&lt;/code&gt; then &lt;code&gt;tool_result&lt;/code&gt;), and pass &lt;code&gt;cache_control&lt;/code&gt; through for prompt caching.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example: Claude Code with ModAPI
&lt;/h2&gt;

&lt;p&gt;ModAPI is an AI gateway with an Anthropic-format endpoint for Claude models, alongside its OpenAI-compatible API for other vendors.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Get an API key
&lt;/h3&gt;

&lt;p&gt;Create an account at &lt;a href="https://modapi.ai/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=offsite_seo" rel="noopener noreferrer"&gt;modapi.ai&lt;/a&gt; and create a key in the dashboard. You can restrict the key to the Claude models you plan to use and give it a spending quota and expiry date, which is useful when the key lives on a shared machine or in CI.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Set the environment variables
&lt;/h3&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://modapi.ai"&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;"your-modapi-api-key"&lt;/span&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;"claude-sonnet-5-5"&lt;/span&gt;
&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;ANTHROPIC_DEFAULT_HAIKU_MODEL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"claude-haiku-5-5"&lt;/span&gt;   &lt;span class="c"&gt;# used when Claude Code picks the Haiku alias&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the base URL has &lt;strong&gt;no&lt;/strong&gt; &lt;code&gt;/v1&lt;/code&gt; suffix: Claude Code appends &lt;code&gt;/v1/messages&lt;/code&gt; itself.&lt;/p&gt;

&lt;p&gt;To make this permanent, add the lines to your shell profile, or put them in the &lt;code&gt;env&lt;/code&gt; block of Claude Code's &lt;code&gt;settings.json&lt;/code&gt; so they only apply to Claude Code.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Start Claude Code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check it in two stages so you know where a failure happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ask it to reply with just &lt;code&gt;OK&lt;/code&gt;. This confirms the endpoint, key and model.&lt;/li&gt;
&lt;li&gt;Ask it to hand a small task to a subagent, for example: &lt;code&gt;Use a subagent to reply OK, then tell me what it said.&lt;/code&gt; This confirms streaming and a tool round trip, and, if a subagent is set to Haiku, that the Haiku model works too.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you get an authentication error, check that the key is pasted without spaces and that it is allowed to call the model you set.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Pick a model
&lt;/h3&gt;

&lt;p&gt;Any Claude model ModAPI serves on its Anthropic endpoint can go in &lt;code&gt;ANTHROPIC_MODEL&lt;/code&gt;. Current IDs and prices are on the &lt;a href="https://modapi.ai/pricing?search=claude&amp;amp;utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=offsite_seo" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt;, for example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;claude-sonnet-5-5&lt;/code&gt; for everyday coding&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;claude-opus-5-5&lt;/code&gt; for long, hard tasks&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;claude-haiku-5-5&lt;/code&gt; for the Haiku alias (for example, a subagent set to Haiku)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Things to know before you switch
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prices and billing.&lt;/strong&gt; Requests are billed by the provider, not Anthropic. Check ModAPI's &lt;a href="https://modapi.ai/pricing?search=claude&amp;amp;utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=offsite_seo" rel="noopener noreferrer"&gt;current pricing page&lt;/a&gt; for the selected model and group, including input, output, cache-read and cache-write rates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data retention.&lt;/strong&gt; Each provider has its own policy. For stateless text requests covered by its policy, ModAPI does not persist prompt or response content at the gateway layer. LLM_Prime applies upstream zero-data-retention routing restrictions by default. See the &lt;a href="https://modapi.ai/policies/zdr/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=offsite_seo" rel="noopener noreferrer"&gt;data retention statement&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Features.&lt;/strong&gt; Prompt caching, tool use and extended thinking depend on the provider passing those fields through unchanged. Test the features you rely on before moving a whole team over.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Switching back.&lt;/strong&gt; Unset the variables (or remove them from &lt;code&gt;settings.json&lt;/code&gt;) and Claude Code goes back to Anthropic's API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If your goal is mainly a cheaper or more flexible way to reach Claude, &lt;a href="https://modapi.ai/blog/claude-api-alternative/?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=offsite_seo" rel="noopener noreferrer"&gt;our comparison of Claude API alternatives&lt;/a&gt; walks through the options beyond Claude Code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Troubleshooting
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symptom&lt;/th&gt;
&lt;th&gt;Likely cause&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;401&lt;/code&gt; / authentication error&lt;/td&gt;
&lt;td&gt;Wrong key, or the key header doesn't match what the provider expects (&lt;code&gt;ANTHROPIC_AUTH_TOKEN&lt;/code&gt; vs &lt;code&gt;ANTHROPIC_API_KEY&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;404&lt;/code&gt; on every request&lt;/td&gt;
&lt;td&gt;Base URL includes &lt;code&gt;/v1&lt;/code&gt;, or the provider has no Anthropic Messages endpoint&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Model not found&lt;/td&gt;
&lt;td&gt;The model ID isn't served on the provider's Anthropic endpoint, or the key isn't allowed to call it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Works, but a Haiku subagent fails&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;ANTHROPIC_DEFAULT_HAIKU_MODEL&lt;/code&gt; points to a model the key can't use&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A tool call hangs or times out&lt;/td&gt;
&lt;td&gt;Contact &lt;a href="https://modapi.ai/contact?utm_source=devto&amp;amp;utm_medium=referral&amp;amp;utm_campaign=offsite_seo" rel="noopener noreferrer"&gt;ModAPI support&lt;/a&gt; with the time of the request and the model you used&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;To use Claude Code with a third-party API, you need a provider with an Anthropic Messages endpoint, then set &lt;code&gt;ANTHROPIC_BASE_URL&lt;/code&gt;, a credential variable and the model names. With ModAPI that is one key, one base URL and the Claude model IDs from the pricing page.&lt;/p&gt;

&lt;p&gt;Questions or a setup that doesn't work? Ask in the &lt;a href="https://discord.gg/7D7eds9Q4E" rel="noopener noreferrer"&gt;ModAPI Discord&lt;/a&gt;.&lt;/p&gt;

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