<?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: Khalid A</title>
    <description>The latest articles on DEV Community by Khalid A (@khalid_a_6d715c2472d70169).</description>
    <link>https://dev.to/khalid_a_6d715c2472d70169</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%2F4029145%2F3eb8befe-cd19-4d50-a255-fbe67f444750.png</url>
      <title>DEV Community: Khalid A</title>
      <link>https://dev.to/khalid_a_6d715c2472d70169</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khalid_a_6d715c2472d70169"/>
    <language>en</language>
    <item>
      <title>I Built a Proxy That Cut My AI Agent's API Costs by 90% — Here's How</title>
      <dc:creator>Khalid A</dc:creator>
      <pubDate>Tue, 14 Jul 2026 18:34:09 +0000</pubDate>
      <link>https://dev.to/khalid_a_6d715c2472d70169/i-built-a-proxy-that-cut-my-ai-agents-api-costs-by-90-heres-how-3766</link>
      <guid>https://dev.to/khalid_a_6d715c2472d70169/i-built-a-proxy-that-cut-my-ai-agents-api-costs-by-90-heres-how-3766</guid>
      <description>&lt;p&gt;&lt;strong&gt;TL;DR:&lt;/strong&gt; LeastGen is a self-hosted caching proxy that sits between your AI agents and LLM APIs. It caches repetitive prompts (tool calls, code reviews, etc.) in a local SQLite database and serves cached responses instantly. One benchmark run went from &lt;strong&gt;1,860 seconds to 0.08 seconds&lt;/strong&gt; with &lt;strong&gt;zero tokens&lt;/strong&gt; consumed. Same 30 problems. Same outputs. Just 23,000x faster and effectively free.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Try it out:&lt;/strong&gt; &lt;a href="http://leastgen.com" rel="noopener noreferrer"&gt;leastgen.com&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem: Your AI Agent Is Bleeding Money
&lt;/h2&gt;

&lt;p&gt;If you've built an AI agent that does anything non-trivial, you know the pain.&lt;/p&gt;

&lt;p&gt;Your agent makes the same tool calls over and over. It re-analyzes the same code. It re-generates the same validation logic. Every single time, you pay for the tokens. Every single time, you wait for the round-trip.&lt;/p&gt;

&lt;p&gt;I was running a moderately complex agent workflow — nothing crazy, just some code review tasks, tool orchestration, and iterative refinement. My API bills were climbing, and my development loop was painfully slow.&lt;/p&gt;

&lt;p&gt;The worst part? &lt;strong&gt;Most of those calls were identical.&lt;/strong&gt; Same prompts. Same context. Same responses. I was paying OpenAI (or Anthropic) to do the same work repeatedly.&lt;/p&gt;

&lt;p&gt;That's when I built LeastGen.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Solution: A Transparent Caching Proxy
&lt;/h2&gt;

&lt;p&gt;LeastGen is a lightweight proxy that sits between your AI agent and your LLM provider. Here's what it does:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Intercepts every request&lt;/strong&gt; — It acts as a drop-in replacement for your API endpoint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hashes the prompt&lt;/strong&gt; — Creates a unique fingerprint of the request (including system prompt, user message, and parameters).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Checks the cache&lt;/strong&gt; — If it's seen this exact prompt before, it serves the cached response from a local SQLite database.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Misses go upstream&lt;/strong&gt; — If it's a new prompt, it forwards to the real API, caches the response, and returns it to your agent.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Zero code changes.&lt;/strong&gt; Just point your agent to the proxy instead of the API directly.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Numbers That Made Me Rethink Everything
&lt;/h2&gt;

&lt;p&gt;I ran a simple benchmark: 30 coding problems, each requiring tool calls and iterative refinement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cold run (no cache):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⏱️ &lt;strong&gt;1,860 seconds&lt;/strong&gt; (~31 minutes)&lt;/li&gt;
&lt;li&gt;📊 &lt;strong&gt;360,836 tokens&lt;/strong&gt; passed to the cloud&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Hot run (cache populated):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⏱️ &lt;strong&gt;0.08 seconds&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;📊 &lt;strong&gt;0 tokens&lt;/strong&gt; consumed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same 30 problems. Same outputs. &lt;strong&gt;23,000x faster.&lt;/strong&gt; Effectively free.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Cold Run&lt;/th&gt;
&lt;th&gt;Hot Run&lt;/th&gt;
&lt;th&gt;Improvement&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Time&lt;/td&gt;
&lt;td&gt;1,860s&lt;/td&gt;
&lt;td&gt;0.08s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;23,250x&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tokens&lt;/td&gt;
&lt;td&gt;360,836&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;100% reduction&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This isn't just about saving money. It's about &lt;strong&gt;unlocking new workflows&lt;/strong&gt;. When your agent can iterate in milliseconds instead of minutes, everything changes.&lt;/p&gt;




&lt;h2&gt;
  
  
  How It Works Under the Hood
&lt;/h2&gt;

&lt;p&gt;LeastGen is deliberately simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local SQLite database&lt;/strong&gt; — No external dependencies, no cloud services. Everything runs on your machine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompt hashing&lt;/strong&gt; — Uses a deterministic hash of the full request to identify duplicates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transparent proxy&lt;/strong&gt; — Your agent doesn't know the difference. It just sees faster responses.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The architecture is intentionally minimal. No complex routing. No semantic similarity matching. Just exact-match caching for deterministic, repeatable prompts.&lt;/p&gt;

&lt;p&gt;Why exact match? Because in agent workflows, &lt;strong&gt;tool calls and code reviews are often byte-for-byte identical&lt;/strong&gt; across runs. Caching these with semantic matching would introduce latency and complexity. Exact matching is fast, simple, and catches the 80% case that matters most.&lt;/p&gt;




&lt;h2&gt;
  
  
  Who Is This For?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AI agent developers&lt;/strong&gt; — If you're building with LangChain, CrewAI, or custom agents, this will cut your dev loop costs dramatically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Teams doing iterative testing&lt;/strong&gt; — Run the same test suite 50 times? Pay for it once.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CI/CD pipelines&lt;/strong&gt; — Cache API responses in your build process and watch your pipeline times drop.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Anyone tired of paying for the same work twice&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;leastgen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. Set your agent's API base URL to the proxy address, and you're done.&lt;/p&gt;

&lt;p&gt;The proxy handles all the caching logic automatically. You can inspect the SQLite database directly if you want to see what's being cached.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;p&gt;LeastGen is early, but the core is solid. Here's what I'm working on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Semantic caching&lt;/strong&gt; — Matching similar (not just identical) prompts&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache invalidation rules&lt;/strong&gt; — TTLs and manual purge&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Analytics dashboard&lt;/strong&gt; — See exactly how much you're saving&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Team sharing&lt;/strong&gt; — Share cache across a development team&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;&lt;strong&gt;Important note:&lt;/strong&gt; LeastGen is currently in private beta. The MIT license on the website reflects our intention to open-source the project, but we're holding the code back temporarily while we polish the experience and ensure stability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you want early access or want to contribute, reach out.&lt;/strong&gt; I'm prioritizing developers who are actively building agents and can provide real feedback.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why I Built This
&lt;/h2&gt;

&lt;p&gt;I was frustrated. I was paying too much. I was waiting too long. And I knew there had to be a better way.&lt;/p&gt;

&lt;p&gt;Caching is not a new idea. CDNs have been doing it for decades. But for some reason, the AI community has been slow to adopt it for agent workflows.&lt;/p&gt;

&lt;p&gt;LeastGen is my attempt to fix that. It's not magic. It's just a proxy with a SQLite database. But it saves me time and money every single day.&lt;/p&gt;

&lt;p&gt;I hope it saves you some too.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Try it out:&lt;/strong&gt; &lt;a href="http://leastgen.com" rel="noopener noreferrer"&gt;leastgen.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Questions? Feedback?&lt;/strong&gt; Drop a comment below or reach out directly.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;P.S. — If you're building an AI agent and want to collaborate, I'd love to hear what you're working on. The space is moving fast, and we're all figuring this out together.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>api</category>
      <category>performance</category>
      <category>showdev</category>
    </item>
  </channel>
</rss>
