Articles

How to stop a stranger running up your AI bill

Nov 11, 2026 · 5 min read

To stop a stranger or a script running up your AI bill through your app, require a login on the endpoint, cap each request and each user, and set a hard spend limit at your AI provider.

On this page4 sections

The maker of the security check described in step 10 wrote this page.

Before you start

You need edit access to the server code behind your AI endpoint and owner access to your AI provider account. At OpenAI, API organization owners can view billing details in the API billing overview, and API usage is billed separately from a ChatGPT subscription. The Shipmate details in step 10 were read from its site on 9 November 2026.

How a bill gets run up

Able’s guide defines a denial-of-wallet attack as making your AI service perform paid work until your bill or credit use rises, and says a broken job can cause the same harm without an attacker. RedHub names three triggers: a leaked key, a retry loop with no backoff and a runaway agent.

Aster’s guide, published 1 October 2026, covers another case. The key sits safely on the server, but the route has no login, no rate limit and no spending cap. Anyone can open DevTools, copy the request and send their own prompts on your account.

Steps to cap AI spend

  1. Test the endpoint as a stranger would. Copy the request your chat box sends from DevTools and send it again from a terminal while signed out. If it returns an answer, the route is open and the next steps apply.

  2. Keep the provider key on the server. Read it from an environment variable such as OPENAI_API_KEY in a server route, then search your browser bundle. The key should not appear, because a key in a client-side bundle can be found and used by anyone.

  3. Require a login before the model call. Put the session check first in the route handler, ahead of the OpenAI call, since everything after it can cost money, and read a user id from the session. Your signed-out request from step 1 should now be rejected.

  4. Cap what one request can cost. Limit input length: Aster’s example is 4,000 characters in a MAX_INPUT_CHARS setting, because input tokens are billed too. Add max_output_tokens, which bounds what the model generates, reasoning tokens included; without it a prompt like “write 10,000 words” is billed in full. Read the model name from an environment variable, because a client that can pick the model can pick the most expensive one.

  5. Add a per-user rate limit. Key it to the user id from step 3. Aster’s guide calls 20 messages per minute generous for a chat box. Able’s guide notes that Cloudflare AI Gateway can also reject requests after a fixed or sliding request count. A script that sends faster than your limit should start getting 429 responses.

  6. Give each user a daily token budget. A rate limit controls speed and a budget controls the total, and a script can run at exactly your rate limit all day. OpenAI returns usage on every response, so store those real token counts per user per day and refuse requests once a user reaches a limit you can afford.

  7. Set a hard spend limit at your provider. In the provider’s dashboard, set a hard project or account budget. RedHub describes a real cutoff as something that disables the key or account at a dollar ceiling, such as a proxy, a prepaid balance or a programmatic kill switch. Spend alerts email you and do not stop traffic, so Aster’s guide suggests setting them below the limit, for example at 50% and 80%. The dashboard should then show the limit you set.

  8. Cap retries and agent turns. RedHub’s list calls for a cap on retries, backoff on failures and a turn limit on any autonomous agent. A failing call should now stop at your cap instead of repeating.

  9. Test the limits in a test account. Lower a limit to a test value, send requests until it is reached and confirm the next request is rejected. Able’s guide says a text instruction to the model such as “do not spend too much” is not a billing control, so the stop must be enforced outside the conversation with the model.

  10. Optional: have a person test the AI route. Shipmate does security checks for apps built fast and delivers the fixes as one pull request that you approve. Launch Lockdown costs $950 once. A person checks every area, including AI features (prompt leaks and runaway bills), and you get fixes as pull requests, a re-check after you merge and a 15-minute call on the findings. It needs read access to your repo. The free check costs $0, needs no card or code access, scans public pages only and sends results by email, with a target of two days. Testing happens only with your written permission, nothing destructive is run on live data, and a staging copy is preferred.

If it does not work

Real users hit 429 responses. Aster’s guide says to watch your 429 responses for the first week: raise the limit if real users reach it, and lower it if nobody comes close.

Spend climbs while requests stay under the rate limit. Freemius says long prompts, multi-step agent chains, large document uploads and large outputs can make one request cost far more than expected. Go back to steps 4 and 6.

A spend limit exists but work continues. RedHub says most platform spending limits are notify-only: the key keeps working after the threshold. Able’s guide says the word budget does not prove work will stop, so look for blocks, rejects or pauses, then check the delay and any stated chance of going over while current requests finish.

A prepaid balance keeps refilling. Aster’s guide says auto-recharge is on by default when you set up prepaid billing. You can turn it off or keep it with an optional monthly recharge limit. OpenAI usage tiers also carry a monthly organization limit that rises as you spend more, a platform ceiling and not a budget you chose, so set your own lower limit.

The bill is already rising. Able’s guide lists stopping new paid work first. Work out the cause after the account is safe.