context window

The maximum number of tokens (input + output combined) a model can process in a single request. Larger windows enable longer documents and conversations.

Syntax

generative-ai
total_tokens = prompt_tokens + completion_tokens <= context_limit

Example

generative-ai
// Context window sizes (2025):
// GPT-4o: 128,000 tokens
// Claude Sonnet: 200,000 tokens
// Gemini 1.5 Pro: 2,000,000 tokens

// Managing large contexts:
// 1. Summarize older messages
// 2. Use RAG to retrieve only relevant chunks
// 3. Sliding window approach
// 4. Semantic caching

// 100k tokens ≈ 75,000 words ≈ a 300-page book