Why is my OpenAI API bill so high? No rate limiting on your AI endpoints
Symptoms
- Your OpenAI or Anthropic bill jumps into the hundreds or thousands overnight, before you notice anything is wrong
- The provider's 'usage limit' email arrives after the money is already spent
- Usage logs show your LLM endpoint hammered by a bot, a competitor's scraper, or one determined user in a loop
- Documented cases include four-figure bills from a single exposed key in under 24 hours
- Automated abuse against reasoning models has generated $500 to $5,000 per day
Why it happens
AI-generated backends ship without working rate limiting
A Tenzai study of 15 AI-generated apps found only one even attempted rate limiting, and that one was bypassable. Scaffolded code optimizes for working, not for surviving contact with the public internet.
Limiter middleware written but never wired in
DryRun Security found agents writing rate-limit middleware into files without ever connecting it to the app. The code exists, passes review, and does nothing in production.
Provider 'usage limits' that notify instead of stop
OpenAI's dashboard usage limit has historically behaved as a notification threshold rather than a hard stop, so alerts fire while requests keep processing and billing.
A public endpoint that proxies a paid API
Any unauthenticated route that forwards requests to an LLM is free compute for whoever finds it. Bots and scrapers do find it.
How to fix it
- Contain the spend firstIf the bill is actively climbing, take the costly endpoint offline or put it behind auth immediately, and rotate any API key that may have leaked. Every minute the endpoint stays open and anonymous costs you money.
- Add rate limiting at the edgePut limits in front of your app, not buried inside it: Vercel WAF rules, Cloudflare rate limiting, or middleware such as @upstash/ratelimit keyed on both IP and user ID. Edge enforcement rejects abusive traffic before it ever triggers a paid API call.
- Require authentication on anything that costs money per callAnonymous access to an LLM proxy is an open wallet. Every endpoint that results in a provider charge should verify a session or token before doing anything else.
- Set hard spend controls and independent alertsUse project-level budgets and limits where the provider supports them, and add billing alerts you control on top. Do not assume a 'usage limit' field is a cap; verify what it actually does before you rely on it.
- Add per-user quotas in application logicCap each account at N requests per day so a single authenticated user cannot drain the budget either. Rate limiting by IP alone does not stop a logged-in user running a loop.
- Prove the limiter actually firesLoad-test the endpoint and confirm requests get rejected at the threshold. A limiter that is defined but never wired in passes code review and fails in production, so watch usage dashboards daily during launch week.
How to prevent it
- Ship rate limiting with the first deploy of any endpoint that calls a paid API, not as a later hardening pass
- Never expose an anonymous LLM proxy, even for a demo
- Set provider budgets and independent billing alerts on day one
- Load-test the limiter before launch to prove it triggers
- Check usage dashboards daily during launch week
Tools that actually fix this
Recommended because they address the failure mode above, not because of the payout. Some are affiliate links; see how we choose.
Uptime, heartbeat, and log monitoring built for indie devs. Heartbeats catch the dead background job your app never noticed, and log alerts surface the errors it never handled. Real free tier.
Try Better Stack →One line to proxy your LLM calls and suddenly you can see cost per request, catch a runaway loop, and cache repeat calls before the bill arrives. Free hobby tier, open source, self-hostable.
Try Helicone →Frequently asked questions
Why is my OpenAI API bill so high all of a sudden?
A sudden spike in an OpenAI API bill usually means an endpoint or key is being abused: a bot, a scraper, or one user in a loop hitting an LLM endpoint that has no rate limiting. Documented cases include four-figure bills from a single exposed key in under 24 hours. Check your usage dashboard for the request pattern, then lock the endpoint down with auth and edge rate limiting.
Does the OpenAI usage limit stop requests once I hit it?
Historically, OpenAI's dashboard usage limit has behaved as a notification threshold rather than a hard stop, so alerts fire but requests keep processing and billing. Treat any usage limit field as unverified until you confirm what it actually does. Set project-level budgets where supported and keep independent billing alerts as a backstop.
How do I add rate limiting to an AI app?
Add rate limiting at the edge, in front of the app: Vercel WAF rules, Cloudflare rate limiting, or middleware such as @upstash/ratelimit keyed on IP and user ID. Combine it with required authentication and per-user daily quotas so neither anonymous bots nor a single logged-in account can run up the bill. Then load-test to prove the limiter actually rejects requests.
Why didn't the AI add rate limiting when it built my backend?
AI-generated backends almost never ship working rate limiting: a Tenzai study of 15 AI-generated apps found only one attempted it, and that one was bypassable. DryRun Security also found agents writing limiter middleware into files without wiring it into the app. Assume rate limiting is missing until you have tested that it fires.
Sources
- Zuplo: Vibe coding and API security
- Capped: Why is my OpenAI bill so high?
- Rafter: OpenAI API key exposure
- How to stop your OpenAI API bill from spiraling out of control
Related errors
The AI put your API key in the frontend: OpenAI, Stripe, or Supabase keys visible in the JS bundle
No auth on your AI-generated API endpoints: anyone can call your backend
Accidentally committed an API key to GitHub
Replit API key exposed: secrets leaking from a public Repl
The Vibe Oops briefing
One email when something ships to production that should not have. New incidents, new error guides, no filler.