<?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>Forem: Joao Romao</title>
    <description>The latest articles on Forem by Joao Romao (@jrmromao).</description>
    <link>https://forem.com/jrmromao</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F303292%2Fd9e47fc3-6ee8-47ca-9318-6f3a0be98a82.jpeg</url>
      <title>Forem: Joao Romao</title>
      <link>https://forem.com/jrmromao</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jrmromao"/>
    <language>en</language>
    <item>
      <title>Is Your OpenAI Bill Giving You Nightmares? I Built a Tool to Help</title>
      <dc:creator>Joao Romao</dc:creator>
      <pubDate>Wed, 22 Oct 2025 10:19:39 +0000</pubDate>
      <link>https://forem.com/jrmromao/is-your-openai-bill-giving-you-nightmares-i-built-a-tool-to-help-4pnn</link>
      <guid>https://forem.com/jrmromao/is-your-openai-bill-giving-you-nightmares-i-built-a-tool-to-help-4pnn</guid>
      <description>&lt;p&gt;Let's be honest: playing with large language models is amazing, but seeing that OpenAI API bill at the end of the month can be... painful. 😅&lt;/p&gt;

&lt;p&gt;I've been working with the GPT-4 and GPT-3.5 APIs a lot, and I noticed how quickly the costs can spiral out of control. A simple task routed to GPT-4 by mistake, an inefficient prompt, or running the same query over and over—it all adds up.&lt;/p&gt;

&lt;p&gt;I kept thinking there &lt;em&gt;had&lt;/em&gt; to be a smarter, more automated way to manage this without rewriting all my code.&lt;/p&gt;

&lt;p&gt;That's why I built &lt;strong&gt;CostLens&lt;/strong&gt;, a simple SDK I'm hoping can help other developers who are facing the same problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is CostLens?
&lt;/h2&gt;

&lt;p&gt;At its core, CostLens is a drop-in SDK that automatically helps you cut your AI costs. The goal is to make it a "set it and forget it" tool that starts saving you money in minutes.&lt;/p&gt;

&lt;p&gt;It works by wrapping your existing OpenAI client. Once it's installed, it automatically does three key things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Smart Model Routing:&lt;/strong&gt; This is the big one. It analyzes your requests and automatically routes simple tasks to cheaper models (like GPT-3.5) while saving the expensive, powerful models (like GPT-4) for the complex tasks that actually need them.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Prompt Optimization:&lt;/strong&gt; The tool's AI rewrites your prompts &lt;em&gt;before&lt;/em&gt; they hit the OpenAI API to be 40-60% shorter. You get the same (or better) quality results for a fraction of the token cost.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Response Caching:&lt;/strong&gt; If your application sends the same request multiple times, CostLens will catch it and return the cached result instantly, for free.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How It Works (It's Quick)
&lt;/h2&gt;

&lt;p&gt;I really wanted to make this as easy as possible, with no need to refactor your existing logic.&lt;/p&gt;

&lt;p&gt;You just import the client, wrap your existing OpenAI instance, and... that's it. You can keep using the OpenAI client just like you always have, and the optimizations happen in the background.&lt;/p&gt;

&lt;p&gt;It looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;CostLens&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;costlens&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;OpenAI&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;openai&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// 1. Initialize CostLens&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;costlens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CostLens&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;COSTLENS_KEY&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// 2. Wrap your existing OpenAI client one time&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;openai&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;costlens&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;wrapOpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="c1"&gt;// 3. Use it exactly as you did before!&lt;/span&gt;
&lt;span class="c1"&gt;// Savings happen automatically&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;openai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gpt-4&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;messages&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="c1"&gt;// ✅ This request is automatically optimized,&lt;/span&gt;
&lt;span class="c1"&gt;// ✅ routed to the best-priced model,&lt;/span&gt;
&lt;span class="c1"&gt;// ✅ and cached for future use.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  I'm Looking for Testers and Feedback!
&lt;/h2&gt;

&lt;p&gt;This started as a personal project, but I think it could be genuinely useful for other indie devs, startups, or anyone who wants to keep their AI experiments affordable.&lt;/p&gt;

&lt;p&gt;I just launched a &lt;strong&gt;Free plan&lt;/strong&gt; that lets you optimize up to $100/month of AI spend, so you can try it out without any risk.&lt;/p&gt;

&lt;p&gt;If you're a developer using the OpenAI API, I would be incredibly grateful if you'd give it a try and let me know what you think.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Does it actually save you money?&lt;/li&gt;
&lt;li&gt;Is the setup as easy as I think it is?&lt;/li&gt;
&lt;li&gt;What features are missing?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can check it out and get started here: &lt;strong&gt;&lt;a href="https://costlens.dev/" rel="noopener noreferrer"&gt;https://costlens.dev/&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;My goal is just to build something that helps the community, so any and all feedback (good or bad) is super welcome.&lt;/p&gt;

&lt;p&gt;Let me know what you think in the comments!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>ai</category>
      <category>npm</category>
      <category>openai</category>
    </item>
  </channel>
</rss>
