AI Cost Tutorial: Per-Token Economics

TL;DRAI economics run on per-token costs — input and output tokens priced separately.

Using a hosted LLM, you pay per token, usually with output tokens costing more than input. Costs scale with prompt size (context), output length, and model tier — so a chatbot with a huge system prompt on every call gets expensive fast. Levers: smaller models where adequate, prompt caching, trimming context, capping output, and batching. Track cost per request like any other unit economic.

Key points

Common mistakes

Try it: List three ways to cut per-request LLM cost.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>cost ≈ input tokens + output tokens × tier
cut: smaller model · cache prefix · trim context · cap output</pre></body></html>
Open the interactive lesson →
Agi · The Moving Target Latency · Ttft · Tps · Streaming