Inference latency measures the time required to obtain an output from a deployed AI model. It applies to both traditional machine learning, such as fraud classification, and generative AI, such as text generation. Engineers must define the measurement boundary: model execution latency measures processing within the serving system, whereas application end-to-end latency can also include network transport, authentication, retrieval, queueing, and response delivery.
For text generation, distinguish time to first token from time to complete the response. Time to first token measures how long a user waits before generation becomes visible. Total response latency measures how long the full answer takes. Streaming lets the application display partial output as it arrives, improving perceived responsiveness without necessarily reducing total generation time or the number of billable tokens.
Tokens are the units a language model processes and generates. A token can represent part of a word, a whole word, or punctuation; token counts vary by tokenizer and language. Input tokens include the submitted instructions, conversation history, and retrieved context. Output tokens are the generated answer. Longer inputs generally require more processing before generation begins, while longer outputs generally take longer because autoregressive models generate tokens sequentially.
Many managed generative AI APIs charge separately for input and output tokens, often with different rates. A basic request-cost estimate is input tokens multiplied by the input rate, plus output tokens multiplied by the output rate, using matching billing units. For a hypothetical model priced at $1 per million input tokens and $4 per million output tokens, a request with 2,000 input tokens and 500 output tokens costs $0.004. Actual rates depend on the model, service, and inference option. Provisioned capacity and self-hosted endpoints may instead involve capacity-based charges.
Reducing unnecessary conversation history or irrelevant retrieved passages can lower input charges and improve processing time. Asking for a concise answer can reduce generated tokens, lowering output charges and completion latency. Setting a maximum output-token limit establishes a ceiling rather than forcing the model to generate that many tokens; an excessively low limit can truncate useful answers. Neither token count nor token price alone reliably predicts latency across different models and hardware.
Cloud deployments also introduce capacity trade-offs. Larger models may provide better task quality but require more resources or take longer to respond. Faster accelerators and additional serving capacity can reduce latency at higher infrastructure cost. Batching can improve aggregate throughput but may increase individual request waiting time. Autoscaling helps handle changing demand, although scaling delays and model initialization can still produce slow requests.
For example, a customer-support assistant might retrieve only the most relevant document excerpts, use a smaller model for routine questions, and stream concise answers. Engineers should compare answer quality, cost per successful task, time to first token, and total latency under realistic concurrent traffic. Monitor percentile latency, especially p95 or p99, because averages can hide occasional long waits. For offline document processing, batch inference may be more economical even when individual results take longer to become available.