<?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: Shashikant Kashyap</title>
    <description>The latest articles on DEV Community by Shashikant Kashyap (@shashikant_kashyap_76692c).</description>
    <link>https://dev.to/shashikant_kashyap_76692c</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%2F4283901%2F1072d41a-8f26-4539-a415-3739bd468638.png</url>
      <title>DEV Community: Shashikant Kashyap</title>
      <link>https://dev.to/shashikant_kashyap_76692c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shashikant_kashyap_76692c"/>
    <language>en</language>
    <item>
      <title>A free-tier AI gateway on Cloudflare Workers</title>
      <dc:creator>Shashikant Kashyap</dc:creator>
      <pubDate>Sat, 05 Dec 2026 04:02:24 +0000</pubDate>
      <link>https://dev.to/shashikant_kashyap_76692c/a-free-tier-ai-gateway-on-cloudflare-workers-hb8</link>
      <guid>https://dev.to/shashikant_kashyap_76692c/a-free-tier-ai-gateway-on-cloudflare-workers-hb8</guid>
      <description>&lt;p&gt;Every free tier has a ceiling, and you find it at the worst possible time. Groq is fast until the rate limiter says no. OpenRouter's &lt;code&gt;:free&lt;/code&gt; models queue behind everyone else's traffic. Gemini's quota resets on a schedule you don't control. Wire an app directly to one of them and it breaks the first time that provider has a bad hour.&lt;/p&gt;

&lt;p&gt;I got tired of patching around that, so I put all of them behind a single Cloudflare Worker.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it is
&lt;/h2&gt;

&lt;p&gt;One Worker that speaks the OpenAI chat-completions API and the Anthropic Messages API. Your client points at the Worker instead of a provider, and the Worker decides where the request goes.&lt;/p&gt;

&lt;p&gt;It runs on the Workers free plan, stores its state in KV, and doesn't need a paid API key to work. Requests are grouped by what you're doing rather than by model name:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;assistant&lt;/code&gt; for general chat&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;agent&lt;/code&gt; for multi-step planning and tool calls&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;coding&lt;/code&gt; for code generation and agents like Claude Code&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;text&lt;/code&gt; for fast extraction and summaries&lt;/li&gt;
&lt;li&gt;plus image and video endpoints&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each group is an ordered list of providers. &lt;code&gt;coding&lt;/code&gt;, for example, starts with a free Qwen coder, falls back to Codestral, then Gemini, then Groq. You can pin a group with &lt;code&gt;"model": "coding"&lt;/code&gt; and stop thinking about which vendor is up today.&lt;/p&gt;

&lt;h2&gt;
  
  
  Routing, and what happens when a provider fails
&lt;/h2&gt;

&lt;p&gt;The interesting part isn't the happy path. It's the failure handling:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;429s&lt;/strong&gt; put that specific key on a cooldown, not the whole provider. Cooldown state lives in KV, so a Worker restart doesn't reset it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;402s&lt;/strong&gt; are treated as a stop sign. The router never escalates to a paid tier, because a surprise bill is worse than a failed request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key rotation&lt;/strong&gt; spreads load across multiple keys per provider when you have them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Predictive exhaustion&lt;/strong&gt; estimates burn rate from recent usage and moves traffic off a key before it hits the wall, instead of after.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Timeouts&lt;/strong&gt; default to 60 seconds. Reasoning models routinely need more than the 20 seconds I started with, and short per-provider hints were quietly shrinking the budget.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There's also a &lt;code&gt;/v1/status&lt;/code&gt; endpoint that reports provider health, key counts and active cooldowns. When something looks broken, that's the first place I look.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using it with existing tools
&lt;/h2&gt;

&lt;p&gt;Because it's OpenAI-compatible, most SDKs work by changing the base URL. For Claude Code and other Anthropic clients:&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://your-worker.workers.dev"&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-gateway-token"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No shim, no proxy process on your machine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Observability that doesn't cost anything
&lt;/h2&gt;

&lt;p&gt;The Worker keeps per-key RPM limits, budget caps, and usage analytics in KV. There's a semantic cache in front of the models, A/B testing for prompt variants, and a simple anomaly detector that flags request spikes and error-rate jumps per IP.&lt;/p&gt;

&lt;p&gt;None of it is fancy. All of it has saved me from debugging blind at 2am.&lt;/p&gt;

&lt;h2&gt;
  
  
  The honest limits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Free tiers change without warning. A provider order that works today may need editing next month.&lt;/li&gt;
&lt;li&gt;Latency is higher than calling a provider directly, because every request goes through one more hop and sometimes one more retry.&lt;/li&gt;
&lt;li&gt;There's no SLA. It's a free Worker in front of free APIs.&lt;/li&gt;
&lt;li&gt;Semantic caching only helps when your prompts actually repeat.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I use it for side projects and local tooling. I wouldn't put a paid product behind it without a paid provider in the mix.&lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying it
&lt;/h2&gt;

&lt;p&gt;It's MIT licensed. There's a Deploy to Cloudflare button in the README, or you can run the deploy script with a Workers API token:&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="nv"&gt;CF_API_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"your_token"&lt;/span&gt; node scripts/deploy-cf.mjs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Repo: &lt;a href="https://github.com/kashyap-digital/sentient-gateway" rel="noopener noreferrer"&gt;https://github.com/kashyap-digital/sentient-gateway&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you try it, I'd like to know which provider order held up best for your workload. That's the part that changes most often.&lt;/p&gt;

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