NEW · v0.12.9

An unattended AI agent can burn thousands before anyone notices. Cost Guard catches it first.

Unbounded loops around AI/LLM calls and missing output token limits are the two patterns behind almost every "we left it running and the bill was insane" story. Thuban Cost Guard finds both, automatically, in every scan — 100% locally.

Cost Guard — Overview
What it catches and why it matters.
Cost Guard — Walkthrough
A real scan, a real finding, fixed.
npx thuban protect

Cost Guard runs automatically — no flag, no config.

The scare stories are real, and getting more common

Someone builds an agent or automation to monitor something, watch a feed, or process a queue — puts the company card on the API key, and walks away. A month later the invoice arrives. Nobody was checking, because nothing was watching the watcher.

Cost Guard exists so your codebase gets checked for this before it ships, not after the bank statement does.

Two rules, built for the exact failure mode

TCG-101 · CRITICAL

Unbounded AI Loop

An OpenAI, Anthropic, or Vercel AI SDK call sitting inside a while, do-while, or for loop with no bounded exit condition and no guarded break. That's the pattern behind an agent that never stops calling the API on its own.

TCG-201 · MEDIUM–HIGH

Missing Output Token Limit

An AI SDK call with no max_tokens / maxOutputTokens set, so a single call has no ceiling on cost. Severity escalates to HIGH automatically when that same call is also inside an unbounded loop — the two rules compound.

What it looks like

// before — flagged: TCG-101 (unbounded loop) + TCG-201 (no token limit)
while (true) {
  const res = await openai.chat.completions.create({
    model: 'gpt-4',
    messages: [{ role: 'user', content: getNextTask() }],
  });
  handle(res);
}

// after — clean
let attempts = 0;
while (attempts < MAX_ATTEMPTS) {
  const res = await openai.chat.completions.create({
    model: 'gpt-4',
    messages: [{ role: 'user', content: getNextTask() }],
    max_tokens: 500,
  });
  handle(res);
  attempts++;
}

Zero false positives on the calls that actually cost money to get wrong

Cost Guard only matches known AI SDK call chains — openai.*, anthropic.messages.create, Vercel AI SDK's generateText/streamText/embed, and similar. A db.user.create(), prisma.invoice.create(), or stripe.customers.create() never trips it — verified by test, not by guesswork.

Cost Guard is already running in your next scan

It ships as part of every scan and install — nothing to turn on. Run it now and see what it finds.

npx thuban protect
Get Started Free