<?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: Lewis Lee</title>
    <description>The latest articles on DEV Community by Lewis Lee (@apimodels).</description>
    <link>https://dev.to/apimodels</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%2F4254203%2F12ce1185-979d-4664-9468-a95f8be8183f.png</url>
      <title>DEV Community: Lewis Lee</title>
      <link>https://dev.to/apimodels</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/apimodels"/>
    <language>en</language>
    <item>
      <title>How to Call GPT, Claude and Gemini From One API Endpoint</title>
      <dc:creator>Lewis Lee</dc:creator>
      <pubDate>Thu, 19 Nov 2026 16:35:43 +0000</pubDate>
      <link>https://dev.to/apimodels/how-to-call-gpt-claude-and-gemini-from-one-api-endpoint-421k</link>
      <guid>https://dev.to/apimodels/how-to-call-gpt-claude-and-gemini-from-one-api-endpoint-421k</guid>
      <description>&lt;p&gt;If you have ever built an app that talks to more than one AI model, you know the pain. OpenAI has its SDK and key. Anthropic has another. Google has a third. Each one has different request shapes, streaming formats, error codes, rate limits and billing dashboards. Before you have shipped a single feature, you are maintaining three integrations and rotating three sets of secrets.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem with juggling providers
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Multiple SDKs to install, upgrade and keep compatible&lt;/li&gt;
&lt;li&gt;Multiple API keys to store, rotate and monitor&lt;/li&gt;
&lt;li&gt;Different response formats that leak into your business logic&lt;/li&gt;
&lt;li&gt;Separate invoices, quotas and outages to track&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One OpenAI-compatible endpoint
&lt;/h2&gt;

&lt;p&gt;The idea is simple: put a single OpenAI-compatible endpoint in front of many models. Your code keeps using the familiar &lt;code&gt;openai&lt;/code&gt; client. You change only the &lt;code&gt;base_url&lt;/code&gt; and the &lt;code&gt;model&lt;/code&gt; string, and the same request works across providers.&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;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="s2"&gt;"YOUR_APIMODELS_KEY"&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.apimodels.app/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"gpt-4o"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"claude-3-5-sonnet"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;resp&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;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="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&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;"Explain REST in one sentence."&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="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;resp&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;Note: check the docs for exact model names, since they can change over time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tips for comparing cost and latency
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use the same prompt set.&lt;/strong&gt; Run 20-50 real prompts from your app against every model, not just a toy example.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure latency yourself.&lt;/strong&gt; Record time to first token and total time. Averages hide tail latency, so look at the p95 too.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Track tokens, not just price per call.&lt;/strong&gt; Different models use different amounts of output for the same task, so compare cost per successful result.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Score quality.&lt;/strong&gt; Cheap and fast does not help if the answer is wrong. Even a simple pass/fail check helps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add a fallback.&lt;/strong&gt; If one model is slow or down, switch the &lt;code&gt;model&lt;/code&gt; string and retry. That is a one-line change with a single endpoint.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;Once switching models is a one-line change, experimenting gets cheap, and you stop being locked into whichever provider you picked first.&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://apimodels.app" rel="noopener noreferrer"&gt;APIMODELS&lt;/a&gt; to make this one key, one endpoint.&lt;/p&gt;

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