How to Estimate an LLM API Bill from Token Counts and Pricing
Work out what an LLM API call will cost from the token counts and the pricing page, before the invoice arrives.
THE FIELD GUIDE
Understand model formats, context windows, quantization, embeddings, and sampling before choosing settings for a real task.
Work out what an LLM API call will cost from the token counts and the pricing page, before the invoice arrives.
Count the tokens in your prompt with tiktoken before you send it, so the bill and the context window hold no surprises.
Read cache usage from API responses to find out whether your prompt prefix is actually being reused, or silently reprocessed every time.
Put the unchanging part of your prompt first so the provider can cache it, and stop paying to reprocess the same text…
Split a context window into instructions, retrieved chunks and output space, so the model never runs out of room mid-answer.
Work out how much GPU memory one long-context request needs for its KV cache, before it crowds out the model itself.
Work out how much memory a quantized model needs from its parameter count and bits per weight, before you download it.
Test a quantized model in the languages your readers use, because quantization can hurt non-English text far more than the English benchmark…
Use an importance matrix when quantizing, so the weights that matter most keep more precision and the rest can shrink further.
Test FP8 quantization for GPU serving with vLLM, where 8-bit weights are close to free on quality and fast on modern cards.