<?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: SarangAI</title>
    <description>The latest articles on DEV Community by SarangAI (@sarangai_id).</description>
    <link>https://dev.to/sarangai_id</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%2F4149328%2F9db76e52-b97a-47c6-9139-d4a454e7b214.png</url>
      <title>DEV Community: SarangAI</title>
      <link>https://dev.to/sarangai_id</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sarangai_id"/>
    <language>en</language>
    <item>
      <title>How I Built a Unified API Gateway for 200+ AI Models (Architecture Deep Dive)</title>
      <dc:creator>SarangAI</dc:creator>
      <pubDate>Tue, 06 Oct 2026 20:37:16 +0000</pubDate>
      <link>https://dev.to/sarangai_id/how-i-built-a-unified-api-gateway-for-200-ai-models-architecture-deep-dive-3559</link>
      <guid>https://dev.to/sarangai_id/how-i-built-a-unified-api-gateway-for-200-ai-models-architecture-deep-dive-3559</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxj3vfq5iciulsst3ryg0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxj3vfq5iciulsst3ryg0.png" alt=" " width="800" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every developer who has worked with more than one AI provider knows the pain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OpenAI has its own API key&lt;/li&gt;
&lt;li&gt;Anthropic has its own billing dashboard&lt;/li&gt;
&lt;li&gt;Google has its own SDK&lt;/li&gt;
&lt;li&gt;DeepSeek has its own rate limits&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to use 4 different models, you have to manage 4 accounts, 4 invoices, and 4 sets of documentation. This isn't just annoying — it's a &lt;strong&gt;bottleneck&lt;/strong&gt; that stops developers from experimenting with new models.&lt;/p&gt;

&lt;p&gt;I built &lt;strong&gt;SarangAI&lt;/strong&gt; to solve this. It's a unified AI gateway that routes all requests to 200+ models through a &lt;strong&gt;single OpenAI-compatible endpoint&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this article, I'll walk through the architecture behind it, the design decisions I made, and the technical challenges that came up.&lt;/p&gt;

&lt;h2&gt;
  
  
  High-Level Architecture
&lt;/h2&gt;

&lt;p&gt;At a high level, SarangAI consists of 4 main components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;API Gateway&lt;/strong&gt; — receives requests from clients (CLI, IDE, or any app)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Router&lt;/strong&gt; — decides which model handles the request&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provider Adapters&lt;/strong&gt; — translate OpenAI-compatible format to each provider's format&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Billing &amp;amp; Rate Limiter&lt;/strong&gt; — manages prepaid balance and per-user rate limits&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The flow is simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client → API Gateway → Router → Provider Adapter → AI Provider
                ↓
          Billing &amp;amp; Rate Limiter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why OpenAI-Compatible?
&lt;/h2&gt;

&lt;p&gt;This is the most important design decision I made.&lt;/p&gt;

&lt;p&gt;When I started building SarangAI, I had two options:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 1:&lt;/strong&gt; Build my own API format, my own docs, my own SDK.&lt;br&gt;
&lt;strong&gt;Option 2:&lt;/strong&gt; Use the OpenAI format, which has become the de-facto standard.&lt;/p&gt;

&lt;p&gt;I chose &lt;strong&gt;option 2&lt;/strong&gt;. Here's why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Zero migration&lt;/strong&gt; — if your code already uses the OpenAI SDK, just change the base URL and API key. Done.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Massive ecosystem&lt;/strong&gt; — thousands of libraries and tools already support the OpenAI format.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Familiar&lt;/strong&gt; — developers don't need to learn a new API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is what makes SarangAI usable in minutes, not hours.&lt;/p&gt;
&lt;h2&gt;
  
  
  Technical Challenge #1: Normalizing Responses
&lt;/h2&gt;

&lt;p&gt;Every provider has a different response format. OpenAI has &lt;code&gt;choices[0].message.content&lt;/code&gt;, Anthropic has &lt;code&gt;content[0].text&lt;/code&gt;, Google has yet another structure.&lt;/p&gt;

&lt;p&gt;The solution: &lt;strong&gt;adapter pattern&lt;/strong&gt;. Each provider has an adapter that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Translates the request from OpenAI format to the provider's format&lt;/li&gt;
&lt;li&gt;Translates the response from the provider's format back to OpenAI format&lt;/li&gt;
&lt;li&gt;Handles errors and retry logic&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This keeps client-side code clean — they don't need to know which provider is being used.&lt;/p&gt;
&lt;h2&gt;
  
  
  Technical Challenge #2: Streaming
&lt;/h2&gt;

&lt;p&gt;Streaming responses are tricky. Every provider sends chunks differently:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;OpenAI uses Server-Sent Events (SSE) with &lt;code&gt;data: {...}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Anthropic has its own event types (&lt;code&gt;content_block_delta&lt;/code&gt;, etc.)&lt;/li&gt;
&lt;li&gt;Google has yet another streaming format&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In SarangAI, I normalize all streaming to the &lt;strong&gt;same SSE format&lt;/strong&gt; as OpenAI. So clients only need to handle one streaming format.&lt;/p&gt;
&lt;h2&gt;
  
  
  Technical Challenge #3: Rate Limiting &amp;amp; Billing
&lt;/h2&gt;

&lt;p&gt;Since SarangAI uses a &lt;strong&gt;prepaid IDR top-up&lt;/strong&gt; model, I need to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Track every request and calculate cost based on token usage&lt;/li&gt;
&lt;li&gt;Deduct from the user's balance in real-time&lt;/li&gt;
&lt;li&gt;Handle race conditions with concurrent requests&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For this, I use a combination of &lt;strong&gt;Redis&lt;/strong&gt; (for fast balance checks) and a &lt;strong&gt;database&lt;/strong&gt; (for audit trails).&lt;/p&gt;
&lt;h2&gt;
  
  
  Technical Challenge #4: Model Routing
&lt;/h2&gt;

&lt;p&gt;One of SarangAI's main features is &lt;strong&gt;instant model switching&lt;/strong&gt;. Users can change models without restarting their app.&lt;/p&gt;

&lt;p&gt;This means the router has to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read the model config from the request&lt;/li&gt;
&lt;li&gt;Validate that the model is available&lt;/li&gt;
&lt;li&gt;Route to the correct adapter&lt;/li&gt;
&lt;li&gt;Handle fallback if a provider is down&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I made this router &lt;strong&gt;stateless&lt;/strong&gt;, so it can scale horizontally without issues.&lt;/p&gt;
&lt;h2&gt;
  
  
  The CLI: &lt;code&gt;sarangai-cli&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Besides the API gateway, I also built a CLI tool that works directly from the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; sarangai-cli
sarang
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CLI connects to the SarangAI endpoint and gives you an interactive workspace. You can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Switch models with a single command&lt;/li&gt;
&lt;li&gt;See token usage&lt;/li&gt;
&lt;li&gt;Check your balance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is especially useful for developers who live in the terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons Learned
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Standards matter.&lt;/strong&gt;&lt;br&gt;
Choosing the OpenAI-compatible format was the best decision I made. It's what makes adoption fast.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Adapter patterns save lives.&lt;/strong&gt;&lt;br&gt;
Without clean adapters, adding a new provider would be a nightmare.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Prepaid &amp;gt; Subscription for developer tools.&lt;/strong&gt;&lt;br&gt;
Developers hate monthly subscriptions. Prepaid gives them a sense of full control.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Documentation is a feature.&lt;/strong&gt;&lt;br&gt;
No matter how good your architecture is, if the docs are bad, nobody will use it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Try It Yourself
&lt;/h2&gt;

&lt;p&gt;If you work with multiple AI models regularly, give SarangAI a try:&lt;/p&gt;

&lt;p&gt;🔗 &lt;strong&gt;&lt;a href="https://sarangai.id" rel="noopener noreferrer"&gt;https://sarangai.id&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Install the CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; sarangai-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm curious: &lt;strong&gt;what's your current setup for handling multiple AI providers?&lt;/strong&gt; Do you use a library? Or manage them one by one?&lt;/p&gt;

&lt;p&gt;Share in the comments - I'd love to hear how other developers handle this.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>opensource</category>
      <category>node</category>
    </item>
    <item>
      <title>Introducing SarangAI: One Smart Router and CLI to Connect 200+ AI Models</title>
      <dc:creator>SarangAI</dc:creator>
      <pubDate>Tue, 29 Sep 2026 10:17:04 +0000</pubDate>
      <link>https://dev.to/sarangai_id/introducing-sarangai-one-smart-router-and-cli-to-connect-200-ai-models-54bc</link>
      <guid>https://dev.to/sarangai_id/introducing-sarangai-one-smart-router-and-cli-to-connect-200-ai-models-54bc</guid>
      <description>&lt;p&gt;Managing multiple AI provider keys, varying rate limits, and fragmented SDKs often creates unnecessary complexity for developers. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://sarangai.id/" rel="noopener noreferrer"&gt;SarangAI&lt;/a&gt; simplifies this workflow by offering a unified, OpenAI-compatible smart router and a dedicated developer CLI designed to route requests across 200+ AI models with zero downtime.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Capabilities
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;200+ AI Models in One Gateway:&lt;/strong&gt; Seamlessly access top models such as Claude Sonnet, GPT, DeepSeek, GLM, MiMo, and many more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One Unified API Key:&lt;/strong&gt; Eliminate the overhead of managing dozens of individual provider subscriptions and keys.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OpenAI-Compatible Endpoint:&lt;/strong&gt; Works as a drop-in replacement with standard OpenAI SDKs and tooling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Terminal CLI:&lt;/strong&gt; An interactive developer workspace directly accessible from your terminal.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Getting Started via CLI
&lt;/h2&gt;

&lt;p&gt;Install and run the CLI globally via npm:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
npm install -g sarangai-cli&lt;br&gt;
sarang&lt;/p&gt;

</description>
      <category>ai</category>
      <category>opensource</category>
      <category>webdev</category>
      <category>node</category>
    </item>
  </channel>
</rss>
