How I set OpenAI API usage limits to stop agent overspending and other AI billing nightmares


img-9860

David Gewirtz/ZDNET

Follow ZDNET: Add us as a preferred source on Google.


ZDNET’s key takeaways

  • OpenAI API spend can rise fast if agents run wild.
  • Hard limits help stop surprise API bills.
  • Alerts and rate limits add another layer of protection.

The other night, I woke up in a damp sweat from a strange nightmare. This wasn’t my typical nightmares where I’m chased by villagers with pitchforks and torches or flaming skulls (or a combination of both).

No, this was a nightmare in which my AI app decided to spawn hundreds of agents, all of whom were making API calls, racking up an ever-climbing API-usage bill. Rogue AIs overspending on my credit card is a notch better than being eaten by flaming skulls, but it’s still not pleasant.

Also: How I stopped a massive WordPress spam attack with 4,700 lines of code in two days – thanks to Codex and Claude

While OpenAI can’t help with the flaming skulls, it can help reduce the risk of a nightmare of an inflated API bill. All you need to do is set usage limits on your account. In this article, I’m going to show you how.

Getting started

Log in to your OpenAI account and browse to the spending limits page. Lots is happening here. We’re going to look at spending limits, spending alerts, rate limits, and usage tiers, each of which contributes to how much your card gets dinged.

Understanding usage tiers

I’m going to start with usage tiers, as they are a break against overspending early in your API journey.

For example, until you’ve spent a total of $50 on API calls, you’re locked into Tier 1. That setup means that even if you don’t set any usage limits, OpenAI won’t let you spend more than $100/month. I’m in Tier 1 because even though I have the API connected to my Karakeep Docker server for keyword analysis, I still haven’t broken $50 in over a year of use.

Once you’ve spent $50, you jump to Tier 2, where you’re allowed to spend $500/month. Spending a total of $100 gets you into Tier 3, where you can spend up to $1,000/month. Spending a total of $250 on API usage jumps you into Tier 4, where you’re allowed to spend up to $5,000/month.

Also: I had Gemini and Claude write my email replies – but only one sounds like me

These are fairly large top-end limits, but once you hit $1,000 paid to OpenAI, the floodgates open. OpenAI will let you spend up to $200,000 per month.

Think about this scenario. You hook up OpenClaw to your OpenAI API account, and within a few months, you’ve spent $1,000 in API calls. Then one day, OpenClaw decides it wants to launch an army of agents to do some task, and off it goes. That unruly beast could slam your account for hundreds of thousands of dollars before you get a chance to shut it off.

And that’s why you also need to set specific spending limits.

Understanding spending limits

Let’s get back to the spending limits page. As you can see (at 1), I’m at Tier 1.

spend-limits

Screenshot by David Gewirtz/ZDNET

A lot is going on here. At (2), note that the page says, “Your actual costs may exceed this based on usage.” This note is because, unless you tell it to, OpenAI doesn’t place a hard limit on your spending. The idea is that without hard limits, your infrastructure won’t break. But, of course, you can spend more. I’ll show you how to fix this issue in a minute.

Also: I got 4 years of product development done in 4 days for $200, and I’m still stunned

At (3), you can see that the account allows automatic refill. Clicking the pencil icon lets you control how much the refill can charge.

auto-recharge

Screenshot by David Gewirtz/ZDNET

You can turn off Auto Recharge by clicking the toggle button. If you do, the limits page will update, and you will no longer be able to turn Auto Recharge back on from this page. Instead, click Billing from the left-side menu.

billing

Screenshot by David Gewirtz/ZDNET

As you can see, my credit balance is $7.77 from the last time I topped up my account. Hitting the Auto Recharge Settings button opens the Auto Recharge dialog, where you can toggle it back to on.

Finally, going back to the Limits screen shown at the beginning of this section, you can specify Spend Alerts at (4) and receive an email alert once you reach a percentage of your budget.

alert

Screenshot by David Gewirtz/ZDNET

You can set the percentage of your spend when you want the alert to trigger. You can also specify where you’d like the email alert notification to be sent.

Setting a hard limit

If you don’t like the idea of your actual costs potentially exceeding the spend limit you set, you can set a hard limit. On the Limits screen, click the Edit Spend Limit button.

hard-limit

Screenshot by David Gewirtz/ZDNET

Notice the Enforce Hard Limit toggle. I recommend turning this on, especially if you’re in one of the higher usage tiers. This step will cause your API calls to be rejected with a 429 error, but you won’t spend more than you should.

Just make sure your code checks for the error condition when it makes a call to the AI.

Understanding rate limits

OpenAI also has rate limits, which limit how many requests per minute, requests per day, tokens per minute, tokens per day, and images per minute you’re allowed to use, based on the model you’re using.

OpenAI says it has rate limits to “help protect against abuse or misuse of the API”, “help ensure that everyone has fair access to the API,” and “help OpenAI manage the aggregate load on its infrastructure.”

Also: Treat your AI agents like eager but misguided human interns – before you lose control

OpenAI has a guide for how to code to rate limits. One recommendation they have is to use exponential backoff, where you automatically retry after a short sleep, and do this a few times until either the request goes through or you exceed a retry threshold of your choice.

The bottom line

The bottom line here is simple. Set up spend limits so rogue AIs don’t exceed your budget. Rate limits are very easy to configure, making them a no-brainer for protecting your account.

They won’t keep the angry villagers at bay, but they will help you manage your AI API spend. And that’s something, at least.


You can follow my day-to-day project updates on social media. Be sure to subscribe to my weekly update newsletter, and follow me on Twitter/X at @DavidGewirtz, on Facebook at Facebook.com/DavidGewirtz, on Instagram at Instagram.com/DavidGewirtz, on Bluesky at @DavidGewirtz.com, and on YouTube at YouTube.com/DavidGewirtzTV.





Source link

Leave a Reply

Subscribe to Our Newsletter

Get our latest articles delivered straight to your inbox. No spam, we promise.

Recent Reviews







Today, when one pictures a “classic Dodge Charger”, the first image that pops up is almost certainly one of the highly desirable Charger models from the late 1960s or early ’70s. Indeed, those early muscle car Chargers are iconic, playing a starring role in the “Dukes of Hazzard” television show and, somewhat more recently, “The Fast and the Furious” films. But as time ticks on, is it time to start appreciating the modern version of the Charger as a potential modern classic?

It’s now been over 20 years since Dodge brought back the Charger nameplate for a spacious four-door sedan with an optional HEMI V8 engine. While the basic Charger R/T was a potent machine for its time, Dodge really took the Charger’s game to the next level for the 2006 model year with the debut of the Charger SRT8. 

The SRT8 model used a larger version of the third-gen HEMI V8 that, combined with other performance upgrades, transformed the sedan into a serious performance car capable of running with its 1960s HEMI ancestors at the drag strip — to say nothing of its vastly superior handling and refinement. In the years that followed, Dodge would continue to improve the Charger’s performance with larger and more powerful HEMI engines, but the significance of the original Charger SRT8 is not to be overlooked.

A muscle car legend reborn for the 2000s

Today, with the modern Charger being such an established part of the car enthusiast world, it’s easy to forget some of the controversy that surrounded its mid-2000s return. Most of it focused on the fact that the beloved muscle car nameplate had been brought back for a four-door sedan rather than a retro-styled coupe. Fortunately, those people looking for that retro coupe would be satisfied by the reborn Dodge Challenger when it arrived a few years later, while the Charger went on to become a highly popular muscle sedan in its own right.

The addition of the SRT8 model to the lineup certainly helped, of course. Under the hood was the larger 6.1-liter HEMI V8, which differed from the standard 5.7-liter HEMI in several ways, not least the displacement. With the 6.1 under the hood, the SRT8 made 425 hp and 420 lb-ft of torque, easily laying down a mid-13-second quarter-mile time in Motor Trend’s hands. This was very quick by mid-2000s standards, especially considering the now-outdated five-speed automatic transmission.

But the SRT8’s performance went beyond just the drag strip. As part of the SRT transformation, Dodge also gave the car larger wheels and tires, a retuned suspension setup, and large Brembo brakes. While this didn’t necessarily make the car an agile road course weapon, it did give the SRT8 an athleticism that belied the Charger’s weight and size. 

The evolution of modern Dodge muscle

What’s even cooler about this era in Chrysler/Dodge performance history is that the Charger was just one of the four-door LX platform cars that the automaker offered with SRT badges and a powerful HEMI engine under the hood. Apart from the Charger, buyers could also choose from the more upscale, but ultimately short-lived SRT version of the Chrysler 300C sedan or the Dodge Magnum SRT8 station wagon.

The original Charger SRT8 marked the beginning of a long run of increasingly powerful, high-performance models. In the early 2010s, the Charger SRT8’s 6.1 HEMI was replaced by the larger and more powerful 6.4/392 HEMI, with that motor eventually becoming available in the less expensive Charger R/T Scat Pack. Then, of course, came the Charger SRT Hellcat, with a 707-hp, supercharged 6.2-liter that turned the car into a genuine super sedan.

So is the original Charger SRT8 a guaranteed future classic? Classified listings show that clean examples still bring decent money today, but the fact that it was followed by improved models may ultimately limit its potential for becoming a true, mega-desirable collector car. Regardless, though, the Charger SRT8’s accomplishments in modern muscle car history are not to be taken lightly.





Source link