AI Tokenomics · Part 178% of My AI Bill Was Waste: Where Prompt Discipline Ends and Runtime Guards Begin
6 min read

78% of My AI Bill Was Waste: Where Prompt Discipline Ends and Runtime Guards Begin

Routing everything to the frontier model bills trivial tasks at $2.00 per 1M tokens.

Each bar splits one workload by the model that serves it, and the price on the right is what 1M tokens cost. On top, all traffic goes to the frontier model at $2.00. Below, 80% goes to the fast model at $0.75 and 20% to the frontier model, so 1M tokens cost $1.00.Columns show who gets the traffic and the cost per 1M tokens. A cross marks All to frontier: traffic is 100% frontier model, and the cost is a long bar, $2.00. A check marks 80/20 routing: traffic splits into 80% fast model and 20% frontier, and the cost is a short bar, a dashed 50% saved box, then $1.00. A legend gives frontier model $2.00 and fast model $0.75. who gets the traffic cost per 1M tokens All to frontier 100% frontier model $2.00 80/20 routing 80% fast model 20% frontier 50% saved $1.00 frontier model $2.00 fast model $0.75 Each bar splits one workload by the model that serves it, and the price on the right is what 1M tokens cost. On top, all traffic goes to the frontier model at $2.00. Below, 80% goes to the fast model at $0.75 and 20% to the frontier model, so 1M tokens cost $1.00.Columns show who gets the traffic and the cost per 1M tokens. A cross marks All to frontier: traffic is 100% frontier model, and the cost is a long bar, $2.00. A check marks 80/20 routing: traffic splits into 80% fast model and 20% frontier, and the cost is a short bar, a dashed 50% saved box, then $1.00. A legend gives frontier model $2.00 and fast model $0.75. per 1M tokens frontier $2.00 fast $0.75 All to frontier traffic 100% frontier cost $2.00 80/20 routing traffic 80% fast 20% frontier cost 50% saved $1.00
Figure 1. Each bar splits one workload by the model that serves it, and the price on the right is what 1M tokens cost. On top, all traffic goes to the frontier model at $2.00. Below, 80% goes to the fast model at $0.75 and 20% to the frontier model, so 1M tokens cost $1.00.

The 11 Principles of AI Tokenomics by Alex Astrum and Luke Schlangen cover development. Live traffic needs guards in code, so I add 80/20 tier routing, atomic token buckets, idempotency keys, and a hard circuit breaker.

Listen to the audio overview(2:13)Fenrir Studio Voice
0:00
2:13

I checked one month of my cloud inference bill across five production AI services. 78% of the money paid for waste. I sent the same System prompt Fixed instructions at the start of every request. They tell the model its role and its rules. again on every call. I kept old conversation history that the model did not need. I sent simple classification tasks to Frontier model The largest, most capable and most expensive tier of models. I keep it for the hardest reasoning. reasoning models, the most expensive kind. Developer guides teach caching and short prompts. Those habits lower my cost while I build. They cannot save me from financial ruin when live production traffic spikes. For that, my live apps need defense in code that acts the same way every time.

In 11 Principles of AI Tokenomics, Alex Astrum and Luke Schlangen set the baseline for how a developer saves Token A small piece of text, often part of a word. Models read, write and bill text by the token.. My apps grow to thousands of users at the same time. At that scale, prompt discipline alone fails. It cannot stop runaway loops, bot scraping, or bursts from clients that nobody meters. My live runtimes need hardware Attestation Proof, signed by the device or platform, that a request comes from my real app and not from a script., atomic Token bucket A per user allowance that refills at a steady rate. Each request spends from it, and an empty bucket refuses. and hard Circuit breaker Code that stops further calls once a limit is crossed, until a person or a timer resets it. in the app.

The tokenomics reality: Prompt discipline lowers my token use while I build. My live apps also need defenses that run in code: Idempotency key A unique ID sent with a request, so a retry of the same request takes effect only once., circuit breakers, and spend limits that keep state.
PART 01

Developer discipline: Where prompt tokenomics excels

The original eleven principles are good at one job. They cut waste while I write prompts and call models:

01

Model sizing and prompt caching

I use light models for simple, frequent work: classification, pulling structured JSON out of text, and checking tool calls. I keep heavy reasoning models for the final answer. My large prompt templates use context caching on Gemini Enterprise Agent Platform (formerly Vertex AI). That cuts my input token cost by up to 90%.

02

Subagent delegation and session brevity

I hand repetitive, token-heavy data work to specialized Subagent A helper agent that a main agent starts to do one part of a job, often in parallel with others.. I also prune conversation history hard. I do not pass the whole multi-turn chat to every later model call in my system.

I pay for every token of dead history I resend. The model's Attention The step where a model compares each token with the tokens before it to decide what matters. work grows even faster. Each new token looks back at every token before it, so the attention grid grows with tokens times tokens. Four tokens make a 4 × 4 grid of 16 cells. Eight tokens make an 8 × 8 grid of 64 cells. The lab below starts from a clean context of 2,048 tokens. One button adds an unpruned tool trace of 8,192 dead tokens, 10,240 in all. That is 5 times the tokens and 25 times the grid. The pruner drops the dead branch, and the grid shrinks back. Its timer measures a real, scaled-down attention pass on the CPU of the device you read this on.

Each token looks back at every earlier one

Step 1: the four-token prompt Fix the failing test as a grid, one row per token. Each row fills the cells of the tokens before it, and the last token, test, checks all of them. token earlier tokens Fix the failing test empty: not written yet test checks all earlier tokens

Twice the tokens, four times the grid

Step 2: four tokens make a 4 by 4 grid of 16 cells. Eight tokens make an 8 by 8 grid of 64 cells. 4 tokens 4 × 4 = 16 cells 8 tokens 8 × 8 = 64 cells double the tokens

A dead tool trace grows the grid 25×

Step 3: an unpruned tool trace of 8,192 dead tokens joins a clean context of 2,048 tokens. 10,240 tokens is 5 times the tokens and 25 times the grid. tokens 2,048 clean 8,192 dead tool trace grid 10,240 tokens 5× the tokens 25× the grid

Prune it, and the grid shrinks back

Step 4: pruning drops the 8,192 dead tokens. The context is 2,048 tokens again and the grid is back to its first size. tokens 2,048 clean pruned grid 2,048 tokens back to the first grid
1 of 4
Figure 2. Four steps with one prompt. Each row of a grid is one token, and its filled cells are the earlier tokens it looks back at. Twice the tokens make four times the cells. A dead tool trace of 8,192 tokens makes the context 5 times longer and its grid 25 times larger; pruning it brings back the 2,048-token grid.
Interactive Lab · webgpu-kv-thermalWebGPU KV-Cache Attention Thermal Profiler

Add an unpruned 8,192-token tool trace or a retry loop to a 2,048-token context, watch the causal attention grid grow with tokens times tokens, then prune it back.

03

Interactive simulator: The 80/20 tier-routing principle

In production, I never send 100% of traffic to expensive frontier models. A smart gateway sends 80% of routine traffic to Gemini 3.6 Flash and 20% of complex turns to Gemini 3.1 Pro. That cuts my cost by 50%, with the same reasoning quality.

Here are the numbers behind the 50%. My gateway benchmark sends 250,000 requests a month, at about 1,500 input tokens each. That is 375M tokens. On the frontier tier at $2.00 per 1M, the month costs $750. If I route 80% to the fast serverless tier, at its $0.75 promotional input rate, the blended rate drops to $1.00 per 1M. The month then costs $375.00.

A context cache goes further. Say 1,000 of the 1,500 tokens are the shared system prompt, and every request hits the cache. That prefix then bills at the cached rate: $0.075 on the fast tier and $0.20 on the frontier tier. The blend falls to $0.40 per 1M, and the month costs $150.00 before cache storage fees.

LIVE SIMULATOR

80/20 tier-routing blend vs. 100% frontier model

100% Gemini 3.1 Pro$750.00At $2.00 / 1M input tokens
80/20 Hybrid Blend$375.0080% Flash ($0.75) + 20% Pro ($2.00)
Net Monthly Savings: $375.00 (50.0% Saved)Open full tokenomics solver in Calculator →
PART 02

Runtime defense: Why code-level guardrails are mandatory

The circuit breaker below uses small numbers on purpose. My budget is $2.00. One call without the cache costs $0.10. At a 50% cache hit rate, the call costs $0.05. The agent must reconcile 500 invoices through a vendor API. The API keeps returning 500 errors. With discipline only, the agent retries 120 times. It spends $6.00, three times the budget, and reconciles zero invoices. Caching halved the price of each call. It did nothing about the number of calls. With the guard on, the idempotency key for invoice 4417 repeats on call 25. The breaker rejects that call before the model runs. Spend stops at $1.20, after 24 billed calls.

Interactive Lab · tokenomics-guardPrompt-Loop Circuit Breaker

Discipline alone cannot stop an autonomous loop: fire unbounded tool retries at a budget and watch the idempotency guard trip before the bill does.

eleven-principles-of-ai-tokenomics-demoRendered scene
Un-Cached Linear Token Burn vs 81% Cost Reduction via Context Caching & Tier Routing Proof
Three steps with the same retry loop at $0.05 a call against a $2.00 budget. The vendor API fails, so the agent retries. With discipline only, it retries 120 times and spends $6.00 for zero reconciled invoices. With the idempotency guard, the key for invoice 4417 repeats on call 25 and the breaker rejects it unbilled, so spend stops at $1.20. No guard 120 retries, 0 invoices $6.00 Idempotency guard key repeats on call 25, breaker opens $1.20 $2.00 budget $0.05 a call Three steps with the same retry loop at $0.05 a call against a $2.00 budget. The vendor API fails, so the agent retries. With discipline only, it retries 120 times and spends $6.00 for zero reconciled invoices. With the idempotency guard, the key for invoice 4417 repeats on call 25 and the breaker rejects it unbilled, so spend stops at $1.20. No guard 120 retries, 0 invoices $6.00 Idempotency guard key repeats on call 25, breaker opens $1.20 $2.00 budget $0.05 a call

A failing API, a $2.00 budget

Step 1: the agent has 500 invoices to reconcile. Each call to the vendor API costs $0.05 and returns a 500 error, so the agent retries. The budget for the whole job is $2.00. Agent 500 invoices to do Vendor API returns 500 errors call, $0.05 error, retry $2.00 budget for the whole job

No guard: 120 retries spend $6.00

Step 2: with no guard the agent retries 120 times and spends $6.00, three times the $2.00 budget, for zero invoices. No guard 120 retries, 0 invoices $6.00 $2.00 budget $0.05 a call

The guard stops the loop at $1.20

Step 3: with the idempotency guard, the key repeats on call 25, the breaker opens, and spend stops at $1.20, under the $2.00 budget. The no-guard bar at $6.00 stays for comparison. No guard 120 retries, 0 invoices $6.00 Idempotency guard key repeats on call 25, breaker opens $1.20 $2.00 budget $0.05 a call
1 of 3
Figure 3. Three steps with the same retry loop at $0.05 a call against a $2.00 budget. The vendor API fails, so the agent retries. With discipline only, it retries 120 times and spends $6.00 for zero reconciled invoices. With the idempotency guard, the key for invoice 4417 repeats on call 25 and the breaker rejects it unbilled, so spend stops at $1.20.
  • Prompt discipline and model selection. Trims my prompt tokens, uses context caching, hands tasks to subagents, and keeps conversation sessions short.
  • Deterministic request protection. Guards every inference call with a per-user idempotency key in Cloud Firestore. When a failed key repeats, it opens the breaker before the LLM runs.
  • Native service spend cap. A Google Cloud spend cap on the Gemini API in this one project pauses that service if the rate limiters and app quotas in front of it fail. It is not a hard limit: it trips minutes late, and the overage is still billed.
PART 03

Production idempotency guard in TypeScript

A network retry can call the LLM twice for one request, and I pay for the tokens twice. To stop that, I claim each user's idempotency key in a Cloud Firestore transaction before the model runs. The pattern follows the IETF Idempotency-Key HTTP Header draft:

server/idempotencyGuard.ts
TypeScript
// Claim the key in a short Firestore transaction, then bill the model call once per claim
import { getApps, initializeApp } from "firebase-admin/app";
import { getFirestore, Timestamp } from "firebase-admin/firestore";
import { createHash, randomUUID } from "node:crypto";

const LEASE_MS = 120_000; // longer than the model call's own timeout, or a retry after it bills twice
const sha256 = (s: string) => createHash("sha256").update(s).digest("hex");

export class GuardRejection extends Error {}

export async function executeIdempotentInference(
  uid: string, // from the verified ID token, never from the request body
  idempotencyKey: string,
  requestBody: string,
  inferenceFn: () => Promise<string>
): Promise<string> {
  if (!getApps().length) initializeApp(); // here, not at import, so the entry file can initialize first
  const db = getFirestore();
  const claim = randomUUID(); // fences this call's late writes
  const ref = db.collection("inference_idempotency").doc(sha256(`${uid}:${idempotencyKey}`));
  const requestHash = sha256(requestBody);

  // Firestore may re-run this callback, so it only reads and writes documents
  const cached = await db.runTransaction(async (tx) => {
    const prior = (await tx.get(ref)).data();
    if (prior) {
      if (prior.requestHash !== requestHash) throw new GuardRejection("Key reused with a different body"); // 422
      if (prior.status === "done") return prior.result as string;
      if (prior.status === "failed") throw new GuardRejection("Failed key repeated: breaker open");
      if (prior.leaseUntil.toMillis() > Date.now()) throw new GuardRejection("Request in flight"); // 409
    }
    tx.set(ref, {
      requestHash,
      claim,
      status: "pending",
      leaseUntil: Timestamp.fromMillis(Date.now() + LEASE_MS),
      expireAt: Timestamp.fromMillis(Date.now() + 86_400_000), // TTL policy field
    });
    return null;
  });
  if (cached !== null) return cached;

  // Fenced write: a call that outlived its lease must not overwrite a newer claim
  const settle = (fields: { status: string; result?: string }) =>
    db.runTransaction(async (tx) => {
      if ((await tx.get(ref)).get("claim") === claim) tx.update(ref, fields);
    });
  let result: string;
  try {
    result = await inferenceFn(); // outside the transaction: one bill per claim
  } catch (err) {
    await settle({ status: "failed" }); // the next call with this key opens the breaker
    throw err;
  }
  await settle({ status: "done", result }); // outside the try: a billed result is never marked failed
  return result;
}
Architectural takeaway: I pair prompt discipline while I build with idempotency guards in code. Together they stop duplicate token use and protect my production runtimes.

The guard costs one document read per request. A key seen for the first time adds a second read and two writes. The first write is the claim. The second is the result, and it lands only if the claim token still matches. That cost is fixed per request and does not grow with prompt size. The duplicate frontier call it prevents does grow: it bills 1,500 tokens every time a client retries.

Interactive tool: Try 80/20 tier routing and context caching discounts in my AI Tokenomics Solvency Calculator →

Industry validation and benchmarks

First published 30 Jul 2026 · last revised 8 Oct 2026 · 48 revisions

Hand this to your agent

You

Read this essay by Ibrahim Ulukaya, https://ulukaya.dev/posts/eleven-principles-of-ai-tokenomics, and look at my project. Where do my model calls lack tier routing, an atomic token bucket, an idempotency key, or a circuit breaker? Name the file and line for each finding.

Cited by
  1. Instrument: Prompt-Loop Circuit Breaker

    Discipline alone cannot stop an autonomous loop: fire unbounded tool retries at a budget and watch the idempotency guard trip before the bill does.

  2. Instrument: WebGPU KV-Cache Attention Thermal Profiler

    Add an unpruned 8,192-token tool trace or a retry loop to a 2,048-token context, watch the causal attention grid grow with tokens times tokens, then prune it back.