Planning an AI application requires more than choosing a model and multiplying a published price by request volume. This guide provides a repeatable worksheet for estimating input and output tokens, monthly API cost, latency, throughput, and context-window risk before launch. The formulas use your provider’s current pricing and limits as inputs, so you can revisit the estimates when your traffic, prompts, retrieval design, or vendor terms change.
Overview
An AI API estimate should answer four practical questions:
- How many tokens will each request consume?
- What will the workload cost at expected volume?
- How quickly can the application respond?
- Can the system handle peak demand within its rate limits?
These questions are related but not interchangeable. A smaller prompt may reduce cost and improve latency, but a high request rate can still create a throughput bottleneck. A large context window may accommodate more retrieved material, but it does not automatically produce better answers or predictable response times.
Use this article as an architecture worksheet rather than a permanent calculator. Record the assumptions behind every estimate, including the selected model or model class, prompt version, retrieval settings, expected traffic, and output limit. Then compare the estimate with measurements from a representative test set.
For prompt-specific cost controls, see the token-budgeting workflow for reducing LLM API costs. If your application uses multiple providers, the LLM prompt portability guide can help you identify assumptions that may not transfer cleanly.
How to estimate
1. Define the unit of work
Start with one measurable unit, such as a chat turn, document summary, support classification, extraction job, or RAG answer. Do not combine unrelated workflows in a single average. A short classification prompt and a long document-analysis prompt have different token and latency profiles.
For each unit, record:
- Requests per user action or business event
- Expected requests per hour, day, and month
- Normal and peak concurrency
- Whether requests are synchronous, asynchronous, or batchable
- Whether a failed or incomplete request is retried
2. Estimate input and output tokens
Separate the input into stable and variable parts. Stable input may include a system instruction, formatting rules, tool definitions, and a few-shot example set. Variable input may include the user message, retrieved passages, conversation history, or document content.
A useful request-level estimate is:
Total input tokens = system tokens + instructions + examples + history + retrieved context + user input
Then estimate output tokens separately. Set an output ceiling in the API where possible, but do not assume every response reaches that ceiling. Use observed or test-set averages alongside a conservative upper bound.
Token counts depend on the provider’s tokenizer and the actual text. Character counts and word counts are only rough planning proxies. Before committing to an estimate, run representative prompts through the tokenizer associated with the intended model or measure usage from API responses.
3. Convert usage into cost
Use the provider’s current rates as variables rather than copying prices into application logic or documentation. If input and output are billed differently, calculate them independently:
Cost per request = (input tokens ÷ billing unit × input rate) + (output tokens ÷ billing unit × output rate)
For monthly planning:
Monthly cost = cost per request × monthly requests
Add separate line items for retries, tool calls, embeddings, reranking, file processing, storage, observability, and any other billable component. If a workflow can make multiple model calls, estimate each call and multiply by its expected frequency.
4. Estimate latency and throughput
Break latency into stages instead of treating it as one model property:
Total latency = queue time + network time + time to first token + generation time + post-processing time
Streaming can improve perceived responsiveness by showing partial output earlier, but it does not necessarily reduce the total generation time. Measure both time to first token and time to completion when the user experience depends on either one.
For throughput, calculate the token demand created by peak traffic:
Peak input tokens per minute = peak requests per minute × average input tokens
Peak output tokens per minute = peak requests per minute × average output tokens
Compare those figures with the provider’s current request-per-minute and token-per-minute limits. Leave room for bursts, retries, and other workloads sharing the same account. A design that fits the monthly budget can still fail if it exceeds a minute-level limit.
Inputs and assumptions
Use the following worksheet for every important AI workflow. Keep measured values and assumptions in separate columns.
| Input | What to record | Why it matters |
|---|---|---|
| Model or model class | Exact endpoint, version, or fallback | Rates, limits, context behavior, and output quality can differ. |
| Input tokens | Average, p95, and maximum | Long-tail prompts often drive context failures and cost. |
| Output tokens | Average, p95, and configured ceiling | Long responses increase cost and generation time. |
| Requests | Daily volume, monthly volume, and peak requests per minute | Determines total spend and rate-limit pressure. |
| Retries | Expected retry percentage and retry causes | Retries can materially increase usage during incidents. |
| Context budget | Instruction, history, retrieval, and output allocation | Prevents the prompt from consuming the entire context window. |
| Latency target | Time to first token and completion target | Guides model, prompt, streaming, and queue decisions. |
| Caching or batching | Eligible content and expected hit rate | Can reduce repeated work, but may add freshness or scheduling constraints. |
For context planning, reserve space for the output before filling the input window. A practical allocation might divide the available budget among system instructions, conversation history, retrieved context, the current request, and a safety margin. The exact proportions depend on the workflow, but a zero-margin design is fragile: one unusually long user message or retrieved passage can cause truncation or rejection.
Retrieved context deserves special attention in RAG systems. Measure the number of chunks, average chunk size, duplicate content, and the proportion of retrieved text that is actually used. If a prompt includes more context than the model needs, test smaller retrieval sets, compression, deduplication, or structured extraction before increasing the context budget.
Worked examples
Example A: Monthly cost estimate
Assume a support assistant makes one model request per user turn. For planning purposes, use these hypothetical inputs:
- Average input: 1,800 tokens
- Average output: 450 tokens
- Monthly volume: 40,000 requests
- Retry allowance: 5% of requests
- Input and output rates: entered from the selected provider’s current pricing page
First calculate billable requests: 40,000 × 1.05 = 42,000. Next calculate monthly usage: 75.6 million input tokens and 18.9 million output tokens. Apply the current input rate to the first figure and the current output rate to the second, then add any separate tool, retrieval, or embedding charges. This approach keeps the worksheet reusable when rates or model choices change.
Example B: Peak throughput
Suppose the same application receives 30 requests per minute during a launch window. Its estimated demand is:
- 54,000 input tokens per minute (30 × 1,800)
- 13,500 output tokens per minute (30 × 450)
Compare both figures, plus expected retries, with the endpoint’s current token and request limits. If the margin is narrow, possible responses include queueing non-urgent work, reducing unnecessary history, routing simple tasks to a smaller model, using asynchronous processing, or requesting a higher limit where appropriate. Validate that each change preserves the required quality and safety behavior.
Example C: Batching and caching decisions
Batching is a candidate when tasks are independent and do not require an immediate response, such as overnight classification or metadata extraction. It may improve operational efficiency, but it changes completion timing and error handling. Caching is useful when the same instructions, retrieved material, or user-independent computation is repeated. Avoid caching content that must reflect a fresh permission state, rapidly changing record, or sensitive user-specific result without a clear invalidation strategy.
Use a simple decision test: if the work is not interactive and can tolerate delay, evaluate batching; if identical work repeats and freshness is defined, evaluate caching; if neither condition holds, prioritize prompt reduction, request shaping, and model selection.
When to recalculate
Recalculate the worksheet whenever an input changes, not only when an invoice is unexpectedly high. At minimum, revisit it:
- When provider pricing, billing units, context limits, or rate-limit terminology changes
- When you change the model, endpoint, fallback, tokenizer, or API parameters
- When a prompt, system instruction, few-shot example, tool schema, or response format changes
- When conversation history or RAG retrieval settings are expanded
- When traffic forecasts, peak events, retry behavior, or concurrency changes
- When measured latency or token usage differs materially from the test estimate
- Before a production launch, architecture review, or monthly usage audit
Maintain separate baseline, expected, and stress-case scenarios. The stress case should use longer inputs, larger outputs, peak traffic, and a realistic retry allowance rather than an arbitrary worst case. After launch, compare estimates with actual token counts, latency percentiles, error rates, and request volume.
Finally, version the worksheet with the prompt and application release. A prompt change that adds examples or retrieved context can alter cost and throughput even when the user-facing feature appears unchanged. For production governance, see the guide to prompt versioning and governance. If the workflow handles private information, pair performance planning with the PII detection and safe prompting checklist.
The practical next step is to create one row per workflow, fill in measured token and latency values from representative requests, enter the provider’s current rates and limits, and review the result under normal and peak traffic. This turns AI API cost estimation from a one-time guess into a maintainable part of AI development planning.