token budget
Token budget refers to the maximum number of tokens an LLM can process or generate in a single request, conversation turn, or context window, determined by the model's architecture and serving constraints. The token budget includes input prompt tokens, conversation history, retrieved context, and generated output tokens. Models have hard limits from their context window (e.g., 4K, 8K, 32K, 128K tokens), but practical budgets are often smaller due to latency, cost, or quality considerations. Longer contexts increase inference latency and memory usage linearly or quadratically (for standard attention). Token budget management is critical for applications: summarizing long documents to fit context, truncating conversation history, and limiting generation length. Techniques to work within token budgets include prompt compression, selective context retrieval, hierarchical summarization, and streaming generation. Token counting must account for tokenization—different tokenizers produce different token counts for the same text. Exceeding token budgets causes truncation or errors. Efficient token budget allocation balances completeness (including relevant context) against cost and latency.