Open AI Chat Endpoints: Stop Strangers Spending Your Tokens

Adding an AI chat to your app is easy. Leaving the route open so anyone can use your credits is easier. Here is how it happens, what it costs and how to lock it down.

Dr. Security3 MIN READ

๐Ÿ’ก The short version: if your app has a route that forwards messages to a paid AI model and it doesn't check who is asking, anyone who finds it can use your credits. The fix is boring and effective: sign-in, limits per user, a cap on what each call may cost, and a spending limit at the provider.

Adding an AI chat box to your app takes an afternoon now. The part that quietly goes missing is the question who is allowed to talk to it? The model doesn't care. It answers whoever asks, and the bill goes to you. ๐Ÿ’ธ

๐Ÿ” How it happens

  1. Your frontend calls a route on your own site, something like /api/chat, to avoid putting the provider key in the browser. Good instinct.
  2. That route takes whatever it receives and forwards it to the model, using your key on the server. Also fine.
  3. But nothing checks that the caller is signed in, so the route works for everyone. The route's address is sitting in your public JavaScript, where anyone can read it.

Now a stranger doesn't need your key. They only need your route. They can use it as a free AI backend for their own product, or just hammer it for fun, and your usage graph climbs.

๐Ÿงฏ The fix, in order

  1. Require sign-in. No session, no answer. Check it on the server, every request.
  2. Limit per user. A daily or hourly cap per account, and a cap per address for anything anonymous (a public demo, for instance).
  3. Cap each call. Set the maximum output length on the server. Don't let the browser choose the model or the length, because then the browser chooses your cost.
  4. Set a spending limit at the provider. Many providers let you set a monthly budget, and some also send alerts. Know the difference: an alert only tells you, while a hard limit actually stops the spending (OpenAI's docs say alerts don't stop requests, and Anthropic's Console lets you set your own monthly spend limit that stops requests when it's reached). Do it today. It is the seatbelt for every mistake above.
  5. Keep the key on the server only. If it ever reached the browser, rotate it. Here's how to find and replace a leaked key.
  6. Watch for spikes. An alert on unusual usage is cheap and catches what you forgot.

๐Ÿ“‹ Quick self-check

QuestionGood answer
Can I call my chat route without being signed in?No
Can one account send unlimited messages?No, there is a limit
Can the browser set the model or the maximum length?No, the server decides
Is there a hard spending limit at the provider?Yes

You can test the first one in thirty seconds: open a private window, find the request your chat sends in the browser's Network tab and replay it without your session.

๐Ÿค– What a scan does about it

On a paid plan, once you've verified you own the site, Dr. Security looks for chat or completion routes of your site written in your public scripts. It sends each one a single tiny request with no credentials and never repeats it, so testing costs you a handful of tokens at most. An anonymous answer that looks like a model reply is a high-severity finding. A route that asks for sign-in is a pass. The reply itself is never kept.

Building with an AI editor? These are the ten mistakes AI-written code keeps making, and an open AI route is number six.

๐Ÿš€ Curious what else your site shows a stranger? Run a free scan and see.

  • ai endpoint security
  • openai api key abuse
  • llm cost abuse
  • ai proxy security
  • vibe coding security

FIND OUT WHAT YOU'RE EXPOSING.