Finding · affects your ai bill

Public endpoints that spend your LLM budget

A route that calls a model on your key without a signed-in user lets anyone on the internet spend your budget.

Why it matters

Your organic traffic sets the expected bill. A public AI endpoint's real ceiling is set by whoever finds it: a script looping on the URL is limited only by the provider's rate limit on your account.

It's the most common way small AI apps get a surprise invoice, because it works perfectly in testing and nothing breaks when it's abused. The money just leaves.

What it looks like

A Next.js route handler with no session check before the model call:

Before
export async function POST(req: Request) {
  const { prompt } = await req.json();
  // no session, no rate limit
  return Response.json(await generateText({ model, prompt }));
}

How to fix it

After
export async function POST(req: Request) {
  const session = await auth();
  if (!session) return new Response("Sign in first", { status: 401 });
  await rateLimit(session.user.id); // per user, at the edge if you can
  const { prompt } = await req.json();
  return Response.json(await generateText({ model, prompt, maxOutputTokens: 800 }));
}
  1. Require a session, or a signed and expiring token for anonymous trials, before any model call.
  2. Rate-limit per user and per IP. Edge middleware or your host's firewall rules are cheapest.
  3. Cap output on the same call, because public and uncapped together is the worst case.

How Skeram detects it

Skeram reads each route's auth check and each model call's key source. A route that calls a model on the platform's key and is reachable without a session is flagged. If the call also has no output cap, the finding is critical.

When it starts to hurt: From the first user: there's no audience size at which a public spend endpoint is safe.

Every finding cites the file and line it came from, and scanning again after a fix shows it resolved in History. How the analysis works.

Questions

My endpoint is only called by my own frontend. Is it still public?

Yes. Anything your frontend can call, a script can call with the same request. The browser isn't a security boundary.

Is a CAPTCHA enough?

It slows casual abuse. A session plus a per-user rate limit is what actually bounds the bill.

Related findings

  • LLM calls with no output cap: A model call without max_tokens lets every answer be as long as the model wants, and output tokens are the expensive ones.

Find it in your code

Skeram reads your repo, prices every model call from 100 to 100,000 users, and flags these patterns with the file and line.