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

1 hour ago 3
img-9860
David Gewirtz/ZDNET

Follow ZDNET: Add america arsenic a preferred source on Google.


ZDNET's cardinal takeaways

  • OpenAI API walk tin emergence accelerated if agents tally wild.
  • Hard limits assistance halt astonishment API bills.
  • Alerts and complaint limits adhd different furniture of protection.

The different night, I woke up successful a damp sweat from a unusual nightmare. This wasn't my emblematic nightmares wherever I'm chased by villagers with pitchforks and torches oregon flaming skulls (or a operation of both).

No, this was a nightmare successful which my AI app decided to spawn hundreds of agents, each of whom were making API calls, racking up an ever-climbing API-usage bill. Rogue AIs overspending connected my recognition paper is simply a notch amended than being eaten by flaming skulls, but it's inactive not pleasant.

Also: How I stopped a monolithic WordPress spam onslaught with 4,700 lines of codification successful 2 days - acknowledgment to Codex and Claude

While OpenAI can't assistance with the flaming skulls, it tin assistance trim the hazard of a nightmare of an inflated API bill. All you request to bash is acceptable usage limits connected your account. In this article, I'm going to amusement you how.

Getting started

Log successful to your OpenAI account and browse to the spending limits page. Lots is happening here. We're going to look astatine spending limits, spending alerts, complaint limits, and usage tiers, each of which contributes to however overmuch your paper gets dinged.

Understanding usage tiers

I'm going to commencement with usage tiers, arsenic they are a interruption against overspending aboriginal successful your API journey.

For example, until you've spent a full of $50 connected API calls, you're locked into Tier 1. That setup means that adjacent if you don't acceptable immoderate usage limits, OpenAI won't fto you walk much than $100/month. I'm successful Tier 1 due to the fact that adjacent though I person the API connected to my Karakeep Docker server for keyword analysis, I inactive haven't breached $50 successful implicit a twelvemonth of use.

Once you've spent $50, you leap to Tier 2, wherever you're allowed to walk $500/month. Spending a full of $100 gets you into Tier 3, wherever you tin walk up to $1,000/month. Spending a full of $250 connected API usage jumps you into Tier 4, wherever you're allowed to walk up to $5,000/month.

Also: I had Gemini and Claude constitute my email replies - but lone 1 sounds similar me

These are reasonably ample top-end limits, but erstwhile you deed $1,000 paid to OpenAI, the floodgates open. OpenAI volition fto you walk up to $200,000 per month.

Think astir this scenario. You hook up OpenClaw to your OpenAI API account, and wrong a fewer months, you've spent $1,000 successful API calls. Then 1 day, OpenClaw decides it wants to motorboat an service of agents to bash immoderate task, and disconnected it goes. That unruly beast could slam your relationship for hundreds of thousands of dollars earlier you get a accidental to unopen it off.

And that's wherefore you besides request to acceptable circumstantial spending limits.

Understanding spending limits

Let's get backmost to the spending limits page. As you tin spot (at 1), I'm astatine Tier 1.

spend-limits
Screenshot by David Gewirtz/ZDNET

A batch is going connected here. At (2), enactment that the leafage says, "Your existent costs whitethorn transcend this based connected usage." This enactment is because, unless you archer it to, OpenAI doesn't spot a hard bounds connected your spending. The thought is that without hard limits, your infrastructure won't break. But, of course, you tin walk more. I'll amusement you however to hole this contented successful a minute.

Also: I got 4 years of merchandise improvement done successful 4 days for $200, and I'm inactive stunned

At (3), you tin spot that the relationship allows automatic refill. Clicking the pencil icon lets you power however overmuch the refill tin charge.

auto-recharge
Screenshot by David Gewirtz/ZDNET

You tin crook disconnected Auto Recharge by clicking the toggle button. If you do, the limits leafage volition update, and you volition nary longer beryllium capable to crook Auto Recharge backmost connected from this page. Instead, click Billing from the left-side menu.

billing
Screenshot by David Gewirtz/ZDNET

As you tin see, my recognition equilibrium is $7.77 from the past clip I topped up my account. Hitting the Auto Recharge Settings fastener opens the Auto Recharge dialog, wherever you tin toggle it backmost to on.

Finally, going backmost to the Limits surface shown astatine the opening of this section, you tin specify Spend Alerts astatine (4) and person an email alert erstwhile you scope a percent of your budget.

alert
Screenshot by David Gewirtz/ZDNET

You tin acceptable the percent of your walk erstwhile you privation the alert to trigger. You tin besides specify wherever you'd similar the email alert notification to beryllium sent.

Setting a hard bounds

If you don't similar the thought of your existent costs perchance exceeding the walk bounds you set, you tin acceptable 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 urge turning this on, particularly if you're successful 1 of the higher usage tiers. This measurement volition origin your API calls to beryllium rejected with a 429 error, but you won't walk much than you should.

Just marque definite your codification checks for the mistake information erstwhile it makes a telephone to the AI.

Understanding complaint limits

OpenAI besides has rate limits, which bounds however galore requests per minute, requests per day, tokens per minute, tokens per day, and images per infinitesimal you're allowed to use, based connected the exemplary you're using.

OpenAI says it has complaint limits to "help support against maltreatment oregon misuse of the API", "help guarantee that everyone has just entree to the API," and "help OpenAI negociate the aggregate load connected its infrastructure."

Also: Treat your AI agents similar anxious but misguided quality interns - earlier you suffer control

OpenAI has a guide for however to codification to complaint limits. One proposal they person is to usage exponential backoff, wherever you automatically retry aft a abbreviated sleep, and bash this a fewer times until either the petition goes done oregon you transcend a retry threshold of your choice.

The bottommost line

The bottommost enactment present is simple. Set up walk limits truthful rogue AIs don't transcend your budget. Rate limits are precise casual to configure, making them a no-brainer for protecting your account.

They won't support the aggravated villagers astatine bay, but they volition assistance you negociate your AI API spend. And that's something, astatine least.


You tin travel my day-to-day task updates connected societal media. Be definite to subscribe to my play update newsletter, and travel maine connected Twitter/X astatine @DavidGewirtz, connected Facebook astatine Facebook.com/DavidGewirtz, connected Instagram astatine Instagram.com/DavidGewirtz, connected Bluesky astatine @DavidGewirtz.com, and connected YouTube astatine YouTube.com/DavidGewirtzTV.

Read Entire Article