Cost engineering
Budget from workload shape—not model hype
The cheapest model per token is not always the cheapest system. Poor output can trigger retries, longer prompts, additional validation, or human review. Start with token economics, then measure task success and total cost per completed outcome.
What changes an LLM bill
Input-to-output ratio
Output is usually priced higher than input. Summarization and extraction workloads often behave differently from long-form generation or reasoning-heavy agents.
Prompt caching
Stable system prompts, large reference contexts, and repeated tool definitions can benefit from cached-input pricing when the provider and request pattern support it.
Retries and agent loops
A single user action may trigger planning, retrieval, tool calls, validation, and retries. Estimate the entire workflow rather than only the final completion.
Batch and asynchronous work
Providers often discount batch processing, but latency and availability differ. Use standard prices here, then evaluate batch APIs for offline workloads.
Count your prompt tokens
Get an exact OpenAI-compatible token count before estimating cost.
Model your RAG ingestion
Estimate chunks, overlap duplication, retrieval context, and vector storage.
Frequently asked questions
How do you calculate LLM API cost?
Multiply input tokens by the provider's input price per million tokens, multiply output tokens by its output price, then add both amounts. For repeated workloads, multiply tokens per request by total requests first. Cached input uses the provider's lower cache-read rate when available.
Why are output tokens usually more expensive?
Generating tokens requires autoregressive model inference for every new token, while processing input can be parallelized more efficiently. Reasoning or thinking tokens are generally billed as output even when they are not all shown to the user.
Does this calculator include every provider charge?
No. It estimates standard text-token inference. Search grounding, tool calls, audio, images, storage, containers, regional premiums, taxes, batch discounts, and negotiated enterprise rates may change the final bill.
How often should model pricing be checked?
Check official provider pages before committing a production budget. Model names, rates, context tiers, promotions, and retirement schedules can change quickly.