LLM cost engineering
What an inference bill is actually made of, and the arithmetic for deciding which change to it is worth an engineer's week.
An inference bill is one of the few things in a software system that is genuinely calculable in advance. It is a small number of prices multiplied by a small number of token counts, and every technique in this cluster — caching, cascading, batching, shortening the output — is a change to one of those terms. The reason bills surprise people is not that the arithmetic is hard. It is that nobody wrote it down, so nobody noticed which term was doing the damage.
So these pages are formulas with their variables defined, each followed by one worked example. The prices in the examples are inputs, not facts: per-token prices move every few months and any figure printed here would be wrong by the time you read it. What does not move is the structure — output costs several times input, a cached read costs a fraction of an uncached one, latency tolerance is worth a discount — and the structure is what the formulas are built on. Substitute your own numbers.
How LLM Pricing Works: Every Line on the Bill
Every meter a provider can bill you on — input, cached input, cache writes, output, reasoning, images — and the formula that turns them into the cost of one request.
6 min read
Cost per Request: Building a Model You Can Forecast With
How to build a per-request cost model out of token distributions rather than averages, and which variable in it actually deserves your attention.
5 min read
The 12 Levers That Cut an LLM Bill
Twelve ways to make an inference bill smaller, and a scoring formula that tells you which of them is worth doing first on your bill rather than on somebody else's.
5 min read
Model Cascading: Cheap Model First, Expensive on Failure
The design of a two-stage cascade, and the escalation rate above which it costs more than simply calling the expensive model every time.
5 min read
When a Small Model Is Genuinely Good Enough
A procedure for deciding whether a cheaper model can take a task, built around what a failure costs you rather than around benchmark scores.
5 min read
Prompt Caching: Where the Savings Actually Come From
What a prompt cache can and cannot reuse, how to order a prompt so the reuse happens, and how many hits it takes to pay back a cache write.
6 min read
Batching for Half Price
Which workloads can tolerate an asynchronous completion window, the one question that decides it, and the payback period on doing the migration.
5 min read
Output Length Control: The Most Ignored Cost Lever
How much of a request's cost is the answer, and five ways to make the answer shorter without making it less useful.
5 min read
Cost of Retries, Failovers and Timeouts
What a retry policy adds to an inference bill, why timeouts are the expensive kind of failure, and how to avoid paying twice for one answer.
5 min read
Streaming vs Non-Streaming: Any Cost Difference?
Whether turning on streaming changes what you pay, what happens to billing when a stream is abandoned, and the test that answers it for your provider.
6 min read
Free Tiers and Free Models: What They Really Cost
The four different things people mean by a free LLM, the questions each one has to answer before you build on it, and when free is the wrong choice arithmetically.
5 min read
Committed Spend and Volume Discounts: When to Sign
How to value a committed-spend agreement against an uncertain forecast, why the right commitment level is your pessimistic case, and the non-price terms that matter more than the discount.
6 min read
Self-Hosting vs API: The Real Break-Even Point
The GPU-hour arithmetic for serving your own model, including the ops cost, and why the break-even turns out to be a utilisation figure rather than a volume one.
5 min read
Budget Alerts and Hard Spend Caps
Why an alert is not a cap, how much an alert-only system can lose before a human reacts, and the architecture of a cap that actually stops spending.
5 min read
Forecasting LLM Spend as You Grow
A per-user cost model for inference spend, the three terms that make it grow faster than your user count, and how to keep it honest as the product changes.
5 min read
Unit Economics of an AI Feature
Gross margin arithmetic for a product with inference in its cost of goods, and why the margin has to be computed as a distribution rather than a number.
5 min read
Charging Users for AI: Credits, Seats or Usage
The four ways to price a product with a variable cost of goods, what each does to your margin as usage grows, and the statistic that tells you which one fits.
5 min read
The Hidden Costs: Embeddings, Storage and Egress
An inventory of the AI costs that are not inference — embeddings, vector storage, logs, egress, evaluation runs and human review — with how to size each one.
6 min read
Cost Regression: Catching a 10× Bill Before It Lands
The categories of change that multiply an inference bill, the multiplier each one carries, and a deterministic CI check that fails the pull request instead of the invoice.
5 min read
Currency, Rounding and Why Money Should Be Integers
Why floating point breaks a metered billing system, which integer scale to pick for costs that are fractions of a cent, and where rounding is allowed to happen.
6 min read
Other topics
- LLM fundamentals & architecture
- Tokens, tokenization & context windows
- Prompt engineering
- Reasoning models & test-time compute
- Multimodal AI: vision, audio, video
- RAG & retrieval
- Embeddings & vector search
- AI agents & tool use
- Structured output & function calling
- Fine-tuning & post-training
- Local inference errors, string by string
- Running local models day to day
- Testing code that calls an LLM
- Snapshot and property testing for model output
- Regression suites for prompts
- Eval gates in CI
- Flaky tests against a model
- Determinism and the cost of testing
- Contract and streaming tests
- Testing tool calls and retrieval
- Inference, serving & latency
- Rolling out a prompt change
- Testing AI systems in practice
- Forecasting a time series
- Machine learning on tabular data
- Geospatial data and models
- Understanding audio that is not speech
- Understanding video
- Core computer vision tasks
- Machine learning on graphs
- Point clouds and 3D
- Evaluation, benchmarks & LLM-as-judge
- Sensor and IoT data
- Logs and event streams
- Models over biological sequences
- Machine learning on molecules
- Embedding and searching code
- Extracting invoices and purchase orders
- Receipts, statements and tax forms
- Insurance policies and contracts
- Deeds, court filings and patents
- Extracting from medical records
- Observability & LLMOps
- CVs, certificates and identity documents
- Shipping, customs and technical documents
- Meetings, email, chat and filled-in forms
- Building an extraction pipeline
- Business, property and inspection documents
- Contract clauses and insurance claims
- Regulated and compliance documents
- Consumer, travel and closing documents
- Mapping one chat API onto another
- SDK and framework migrations
- Hallucination & failure modes
- Re-embedding and model deprecation
- Cutting over between providers
- Parity gaps, shims and legacy endpoints
- Moving between model versions
- Migrating vector stores and caches
- Mapping capabilities and parameters
- Migrating pipelines and agents
- Contracts, runbooks and rollback
- Auditing a codebase before a cutover
- Compliance and fine-tune migration
- Routing, cost tracking and multi-tenancy
- What a migration does to your prompts
- AI security & prompt injection
- Privacy, compliance & data residency
- AI governance, policy & society
- Building reliable AI applications
- AI hardware, GPUs & compute
- Open-weight models & local inference
- AI for developers & coding agents
- AI in industry: vertical playbooks
- AGI, superintelligence, alignment & the long future
- Machine learning foundations
- NLP fundamentals & classical tasks
- Data engineering for AI
- Synthetic data & dataset curation
- AI product design & UX
- Search, ranking & recommendation
- Enterprise adoption & change management
- AI careers, skills & teams
- Reading AI research
- AI in science & discovery
- Robotics & embodied AI
- AI economics, markets & business models
- AI myths, hype & media literacy
- Context engineering
- Shipping AI features: patterns & anti-patterns
- Build it: end-to-end AI tutorials
- Python for AI: hands-on recipes
- TypeScript, React and the web
- Frameworks and SDKs
- Errors and troubleshooting
- AI facts, numbers and statistics
- The history of AI
- The maths behind AI
- Architectures beyond the transformer
- Reinforcement learning
- Diffusion and generative media
- Speech, audio and voice engineering
- Benchmarks, one at a time
- AI search visibility
- Infrastructure and operations
- Databases and storage for AI
- Knowledge graphs and structured knowledge
- Classical ML in production
- Regulation, jurisdiction by jurisdiction
- Prompt recipes and pattern library
- AI for people who do not write code
- Writing, media and creative work
- Edge and on-device AI
- Interpretability and model internals
- Field notes
- OpenAI model behaviour
- Claude model behaviour
- Gemini model behaviour
- Llama model behaviour
- Mistral model behaviour
- Qwen model behaviour
- DeepSeek model behaviour
- Cohere model behaviour
- Grok model behaviour
- Small model behaviour
- Hybrid model architectures
- Token cost by language and script
- Transliteration, romanization and script handling
- Locale-correct output
- Multilingual generation quality
- Multilingual pipelines
- The EU AI Act, article by article
- AI under the GDPR and EU data law
- US AI regulation, state and sector
- International AI governance and standards
- AI litigation and enforcement
- Running AI workloads on AWS
- Running AI workloads on Google Cloud
- Running AI workloads on Azure
- AI at the edge: Workers, Vercel and Netlify
- Serving models on Kubernetes
- Operating AI infrastructure
- Quantization formats and what they cost
- llama.cpp, flag by flag
- Ollama and the desktop local-model runtimes
- Local models on Apple Silicon
- Hardware for local inference
- Running speech and embedding models locally
- Model files, adapters and conversion
- VRAM arithmetic for local models