How to stop an AI feature from running up your bill

Rate limits, spending caps and a server in between: the three controls every AI feature needs before strangers can use it.

An AI feature that anyone can call, as often as they like, is an open invoice in your name. The fix has three parts: keep the provider key on a server, limit how often each user can call it, and set a hard spending cap with the provider so a mistake stops at a number you chose.

Where does the money actually leak?

  • The key is in the browser. Anyone can copy it from your JavaScript and use your account for their own projects. In the Wake Forest study of iPhone apps we covered in our piece on leaked keys, this was the most common failure.
  • The route has no limit. The key is safely on a server, but the endpoint accepts unlimited requests from anyone with the URL. A script can run it in a loop all night.
  • Prompts grow without a cap. Users paste a whole document, the app sends it all, and a single request costs a hundred times what you tested with.

What does a safe AI route look like?

  • Server only. The browser calls /api/assist on your own backend. The backend holds the key and calls the provider. The key never ships to a client.
  • Authenticated. Anonymous visitors get a small free allowance or none. Each request is tied to a user id.
  • Rate limited per user. For example 20 requests a minute and 200 a day, enforced in the route with a counter in Redis or your database. Return 429 when exceeded.
  • Capped per request. Truncate input to a maximum number of tokens, set max_tokens on the output, and pick the cheapest model that does the job.
  • Logged. Store user id, tokens in, tokens out and cost per call. A daily total per user shows abuse within hours.
Find an open AI route in a minute

npx sigship flags an AI key in the browser and an AI route with no rate limit, and writes the fix brief for Cursor, Bolt, Claude or Replit.

Run npx sigship

What should you set with the provider?

Application code can have bugs. Provider limits cannot be bypassed by your own mistake. OpenAI's spend limits let you set a monthly budget per project with a hard stop, and other providers offer similar controls. Set them on day one, at a number you would not mind losing, and raise them when real usage justifies it. Use a separate project and key per environment so a leaked test key cannot touch production spend.

How do you know if your app has the problem today?

Run npx sigship in the repository. Two of its checks cover exactly this: ai-key-in-browser (SEV-1, blocks launch) and ai-route-no-rate-limit (SEV-2). It names the file and, with --prompt --tool cursor, writes a fix brief you can paste into your AI tool. It runs on your computer and uploads nothing. A GO is not proof your app is safe, but a NO-GO here is a bill waiting to happen.

What does this cost to build properly?

Less than one bad weekend. A server route, auth, a rate limiter and logging is a day or two of senior work on most stacks, and it is part of every AI feature we ship. If your prototype already has users, it belongs at the top of the list in our prototype to production checklist.

Questions

How do I stop people abusing my AI API endpoint?

Require sign-in, limit requests per user per minute and per day, cap input and output tokens, and log cost per user so abuse shows up within hours.

Can I put my OpenAI or Anthropic key in a front-end app?

No. Anyone can read it from the JavaScript or the app bundle. Call the provider from a server route that holds the key.

What is a reasonable rate limit for an AI feature?

It depends on the product, but a starting point for a consumer app is around 20 requests a minute and 200 a day per signed-in user, adjusted once you see real usage.

Do AI providers let me set a hard spending limit?

Yes. OpenAI offers project-level spend limits with a hard stop, and other providers have budget controls. Set them before launch.

How does SIGSHIP help with AI costs?

Its ai-key-in-browser and ai-route-no-rate-limit checks flag the two most common causes of runaway AI bills, with the file and a paste-ready fix.

Have an idea? See what it would take to build it.

The Idea Lab turns a two-sentence idea into a build plan: why it could work, what to get right first, the first version worth building and its price. Two minutes, from our published rates.

Open the Idea Lab

Next: 12 questions to ask a software development agency before you sign

Tell us what you're building.

Thirty minutes with a senior engineer. You leave with a plan and a price, whether or not you work with us.

Book a callGet your price