<?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: Ronald Oloo</title>
    <description>The latest articles on DEV Community by Ronald Oloo (@ronald_oloo_d67211d1e6e60).</description>
    <link>https://dev.to/ronald_oloo_d67211d1e6e60</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%2F3671331%2F7a7d60c3-da91-45b3-9d18-41d96d1760b5.png</url>
      <title>DEV Community: Ronald Oloo</title>
      <link>https://dev.to/ronald_oloo_d67211d1e6e60</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ronald_oloo_d67211d1e6e60"/>
    <language>en</language>
    <item>
      <title>How to stop OpenAI API credit draining using Client-Side Proof of Work (Node + React)</title>
      <dc:creator>Ronald Oloo</dc:creator>
      <pubDate>Fri, 19 Dec 2025 23:18:45 +0000</pubDate>
      <link>https://dev.to/ronald_oloo_d67211d1e6e60/how-to-stop-openai-api-credit-draining-using-client-side-proof-of-work-node-react-5e6g</link>
      <guid>https://dev.to/ronald_oloo_d67211d1e6e60/how-to-stop-openai-api-credit-draining-using-client-side-proof-of-work-node-react-5e6g</guid>
      <description>&lt;p&gt;I woke up last week to a $500 OpenAI bill.&lt;/p&gt;

&lt;p&gt;My new SaaS wrapper had 0 active users, but 100,000 requests.&lt;br&gt;&lt;br&gt;
I checked the logs. It was a botnet spamming my signup form to test stolen credit cards and generate free text.&lt;/p&gt;

&lt;p&gt;I tried adding &lt;strong&gt;Google reCAPTCHA v3&lt;/strong&gt;, but my signup conversion rate dropped by 20%. Users hated clicking traffic lights, and the "Invisible" score was blocking legitimate users on VPNs.&lt;/p&gt;

&lt;p&gt;I needed a way to verify requests were human &lt;em&gt;without&lt;/em&gt; annoying them.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Solution: Economic Deterrence
&lt;/h2&gt;

&lt;p&gt;I realized I didn't need to check if the user was human. I just needed to make it &lt;strong&gt;expensive&lt;/strong&gt; for them to spam me.&lt;/p&gt;

&lt;p&gt;I built a system based on &lt;strong&gt;Proof of Work (PoW)&lt;/strong&gt;, similar to Hashcash (Bitcoin).&lt;/p&gt;
&lt;h3&gt;
  
  
  How it works
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Handshake:&lt;/strong&gt; Before submitting a form, the client asks the server for a challenge.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Work:&lt;/strong&gt; The browser must solve a cryptographic puzzle (Argon2 hash) that takes about &lt;strong&gt;1–2 seconds&lt;/strong&gt; of CPU time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verification:&lt;/strong&gt; The client sends the solution. The server verifies it instantly (~0ms).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For a human, 2 seconds is invisible background work.&lt;br&gt;&lt;br&gt;
For a bot trying to send 1 million requests? That costs &lt;strong&gt;thousands of dollars&lt;/strong&gt; in electricity and CPU time. The attack becomes economically unviable.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Implementation
&lt;/h2&gt;

&lt;p&gt;I open-sourced the SDK I built for this. It's called &lt;strong&gt;IronWall&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is how you can add it to your React / Next.js app in 3 minutes.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Install the SDK
&lt;/h3&gt;

&lt;p&gt;It's only &lt;strong&gt;3KB gzipped&lt;/strong&gt; (vs 200KB+ for reCAPTCHA).&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;ironwall-sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Configure it
&lt;/h3&gt;

&lt;p&gt;Add this to your &lt;code&gt;_app.tsx&lt;/code&gt; or main entry file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;IronWall&lt;/span&gt; &lt;span class="p"&gt;}&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;ironwall-sdk&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;IronWall&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;configure&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;YOUR_PUBLIC_KEY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Get this for free from ironwall-protocol.xyz&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Protect your API Call
&lt;/h3&gt;

&lt;p&gt;Wrap your sensitive API call (Login, Register, Generate) with the guard.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleSubmit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// This pauses execution until the puzzle is solved&lt;/span&gt;
    &lt;span class="c1"&gt;// The browser calculates the hash in a Web Worker (doesn't freeze the UI)&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;IronWall&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;guard&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// If we get here, the user paid the CPU tax.&lt;/span&gt;
    &lt;span class="c1"&gt;// Proceed to your backend.&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/generate&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bot detected or user cancelled&lt;/span&gt;&lt;span class="dl"&gt;"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why this is better for AI apps
&lt;/h2&gt;

&lt;p&gt;If you are paying per token (OpenAI / Anthropic), &lt;strong&gt;volume is your enemy&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Traditional IP-based rate limiting fails because bots rotate IPs using proxies.&lt;/li&gt;
&lt;li&gt;Proof of Work makes the &lt;strong&gt;device&lt;/strong&gt; pay. Proxies don't help because the CPU cost is local.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I've packaged the backend logic into a hosted service to handle verification and replay-attack protection (using Redis atomic locks).&lt;/p&gt;

&lt;p&gt;You can grab a free key here:&lt;br&gt;&lt;br&gt;
&lt;a href="https://ironwall-protocol.xyz" rel="noopener noreferrer"&gt;https://ironwall-protocol.xyz&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It stops the bill shock — and your users never see a puzzle.&lt;/p&gt;

&lt;p&gt;Let me know if you have questions about the Argon2 parameters.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>security</category>
      <category>webdev</category>
      <category>node</category>
    </item>
  </channel>
</rss>
