<?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: Sergio Wolf Knapik</title>
    <description>The latest articles on DEV Community by Sergio Wolf Knapik (@wolfnom).</description>
    <link>https://dev.to/wolfnom</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%2F4118293%2Ff02e61dc-1596-465c-80db-bea308018ed8.png</url>
      <title>DEV Community: Sergio Wolf Knapik</title>
      <link>https://dev.to/wolfnom</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wolfnom"/>
    <language>en</language>
    <item>
      <title>Multi-Provider LLM Router, or How I Got Tired of Forgetting Which API Format I Had To Use</title>
      <dc:creator>Sergio Wolf Knapik</dc:creator>
      <pubDate>Thu, 10 Sep 2026 03:53:49 +0000</pubDate>
      <link>https://dev.to/wolfnom/multi-provider-llm-router-or-how-i-got-tired-of-forgetting-which-api-format-i-had-to-use-lk3</link>
      <guid>https://dev.to/wolfnom/multi-provider-llm-router-or-how-i-got-tired-of-forgetting-which-api-format-i-had-to-use-lk3</guid>
      <description>&lt;p&gt;If you've ever built an application that integrates with multiple LLM providers (Anthropic, Google, OpenAI, DeepSeek), you already know the pain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each provider has its own distinct Python SDK.&lt;/li&gt;
&lt;li&gt;Streaming responses using Server-Sent Events (SSE) requires divergent parser logic.&lt;/li&gt;
&lt;li&gt;Thinking / Reasoning blocks are formatted completely differently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I recently extracted the core streaming router from my platform into an open-source FastAPI template. Here is how it works.&lt;/p&gt;




&lt;h2&gt;
  
  
  Objective
&lt;/h2&gt;

&lt;p&gt;A single asynchronous endpoint:&lt;br&gt;
&lt;code&gt;POST /v1/chat/stream&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It accepts a unified request payload and returns a standardized SSE stream emitting four clean events:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;event: thinking&lt;/code&gt; — Internal model reasoning tokens (streamed in real-time).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;event: content&lt;/code&gt; — User-facing response text.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;event: tool_call&lt;/code&gt; — Function calling requests.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;event: done&lt;/code&gt; — Stream completion (&lt;code&gt;[DONE]&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;

&lt;p&gt;Instead of pulling heavy wrapper frameworks, use direct asynchronous HTTP via &lt;code&gt;httpx.AsyncClient&lt;/code&gt; and the official Google GenAI SDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fastapi-multi-llm-starter/
├── app/
│   ├── config.py       # Pydantic Settings loading environment variables
│   ├── main.py         # FastAPI app with CORS, health check &amp;amp; test playground
│   ├── models.json     # Dynamic model catalog (Claude, Gemini, GPT)
│   ├── router.py       # Unified multi-provider async stream dispatcher
│   └── schemas.py      # Strict Pydantic v2 validation models
├── tests/              # Automated unit tests (pytest)
├── requirements.txt
└── README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Dynamic Model Catalog
&lt;/h3&gt;

&lt;p&gt;I disliked the idea of hardcoded models, so I decoupled them into a &lt;code&gt;models.json&lt;/code&gt; file:&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="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"models"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"claude-sonnet-5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Claude Sonnet 5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"provider"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Anthropic"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"thinking"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"gemini-3.8-flash"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Gemini 3.8 Flash"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"provider"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Google"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"thinking"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"gpt-5.6-terra"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"GPT 5.6 Terra"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"provider"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"OpenAI"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"thinking"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if you want to add another model, you just edit the JSON. The backend and the embedded UI dynamically populate available models via &lt;code&gt;GET /v1/models&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Testing Playground
&lt;/h2&gt;

&lt;p&gt;The repository includes a testing playground running directly at &lt;code&gt;http://localhost:8000/&lt;/code&gt;. You can immediately test prompts, check streaming latency, and verify reasoning blocks without setting up a frontend framework.&lt;/p&gt;

&lt;p&gt;Of course, you'll need your own API keys.&lt;/p&gt;




&lt;h2&gt;
  
  
  Open Source Code
&lt;/h2&gt;

&lt;p&gt;The full core code is open-source under the &lt;strong&gt;MIT License&lt;/strong&gt; on GitHub:&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;&lt;a href="https://github.com/wolfnomknight/fastapi-multi-llm-starter" rel="noopener noreferrer"&gt;github.com/wolfnomknight/fastapi-multi-llm-starter&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Includes full &lt;code&gt;pytest&lt;/code&gt; test coverage, &lt;code&gt;.env.example&lt;/code&gt;, and clean Pydantic v2 schemas.&lt;/p&gt;

&lt;p&gt;Feel free to fork it, use it in your side projects or micro-SaaS, and let me know if you run into any issues or have ideas for additional providers!&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>fastapi</category>
    </item>
  </channel>
</rss>
