AI Context Window Comparison 2026: Token Limits by Model
Compare representative AI context windows and token limits for GPT, Claude, Gemini, and other models, with caveats for changing provider limits and pricing.

Context Window and Token Limits Explained: A Developer's Guide#
Context windows and token limits are fundamental concepts every AI developer needs to understand. They determine how much text you can send to a model, how long responses can be, and ultimately how much each API call costs. Provider limits and prices change often, so use the table below as a representative planning guide and verify live docs before hard-coding limits.
This guide breaks down everything you need to know about context windows across all major AI models in 2026.
What is a Context Window?#
A context window is the total amount of text (measured in tokens) that an AI model can process in a single request. It includes:
- System prompt - Your instructions to the model
- Conversation history - Previous messages in the chat
- User input - The current message/question
- Model output - The generated response
Think of it like the model's "working memory" - everything it can see and reason about at once.
What is a Token?#
A token is approximately:
- English: ~4 characters or ~3/4 of a word
- Chinese: ~1-2 characters per token
- Code: Variable (keywords are often 1 token, variable names can be multiple)
Quick estimation: 1,000 tokens ~ 750 English words ~ 500 Chinese characters
# Count tokens with tiktoken (OpenAI models)
import tiktoken
encoder = tiktoken.encoding_for_model("gpt-4o")
text = "Hello, how many tokens is this sentence?"
tokens = encoder.encode(text)
print(f"Token count: {len(tokens)}") # Output: 8
Context Window Comparison: Representative Models (2026)#
Text Models#
| Model family | Typical context window | Typical max output | Pricing note |
|---|---|---|---|
| GPT-4o / GPT-4.1 family | Often 128K to 1M, depending on model and endpoint | Varies by model | Check OpenAI or gateway live pricing |
| OpenAI mini / nano models | Often 128K or higher | Varies by model | Lower-cost options for routing, summaries, and extraction |
| Claude Sonnet / Opus family | Commonly around 200K, with endpoint-specific limits | Varies by model | Confirm output caps and prompt caching rules |
| Claude Haiku family | Commonly around 200K | Varies by model | Good fit for fast, lower-cost long-context tasks |
| Gemini Pro / Flash family | Often 1M+, depending on model and access tier | Varies by model | Strong long-context option; verify tier and region limits |
| DeepSeek models | Often 64K-128K+ depending on release and provider | Varies by provider | Pricing and context can differ across official and third-party endpoints |
| Grok models | Large-context options may be available by plan/provider | Varies by provider | Verify current model availability and limits |
Key Observations#
- Long-context availability changes quickly - Gemini, GPT, Claude, DeepSeek, and Grok limits depend on model version, endpoint, and account tier
- Output limits vary widely - A large input window does not guarantee a large response cap
- Long context != better - Models often perform worse at retrieving information from the middle of very long contexts ("Lost in the Middle" problem)
- Price scales with context - Longer inputs cost more; optimize your context usage
Context Window vs. Effective Context#
An important distinction: context window is the theoretical maximum, but effective context is how much the model can actually use well.
┌────────────────────────────────────────────────────┐
│ Context Window │
│ │
│ ┌────────────┐ ┌────────────┐ │
│ │ Beginning │ ← Model pays │ End │ │
│ │ (Strong) │ attention here │ (Strong) │ │
│ └────────────┘ └────────────┘ │
│ │
│ ┌──────────────────┐ │
│ │ Middle │ ← Information │
│ │ (Weaker) │ often missed │
│ └──────────────────┘ │
│ │
└────────────────────────────────────────────────────┘
Best practices for important information:
- Place critical instructions at the beginning (system prompt)
- Place the most relevant context at the end (closest to the question)
- Use structured formatting (headers, bullet points) to help the model navigate
How to Optimize Context Usage#
1. Smart Conversation Pruning#
def prune_conversation(messages, max_tokens=100000):
"""Keep conversation within token budget."""
# Always keep system message
system = [m for m in messages if m["role"] == "system"]
conversation = [m for m in messages if m["role"] != "system"]
# Count tokens (simplified)
total_tokens = sum(len(m["content"]) // 4 for m in messages)
# Remove oldest messages until within budget
while total_tokens > max_tokens and len(conversation) > 2:
removed = conversation.pop(0)
total_tokens -= len(removed["content"]) // 4
return system + conversation
2. Summarization for Long Conversations#
from openai import OpenAI
client = OpenAI(
api_key="YOUR_CRAZYROUTER_KEY",
base_url="https://crazyrouter.com/v1"
)
def summarize_history(messages):
"""Compress conversation history into a summary."""
history_text = "\n".join(
f"{m['role']}: {m['content']}" for m in messages
)
response = client.chat.completions.create(
model="gpt-4o-mini", # Cheap model for summarization
messages=[
{"role": "system", "content": "Summarize this conversation concisely, preserving key decisions, facts, and context."},
{"role": "user", "content": history_text}
],
max_tokens=500
)
return {
"role": "system",
"content": f"Previous conversation summary: {response.choices[0].message.content}"
}
3. Chunking for Long Documents#
def chunk_document(text, chunk_size=4000, overlap=200):
"""Split a document into overlapping chunks for processing."""
words = text.split()
chunks = []
for i in range(0, len(words), chunk_size - overlap):
chunk = " ".join(words[i:i + chunk_size])
chunks.append(chunk)
return chunks
def process_long_document(document, question):
"""Process a document that exceeds context window."""
chunks = chunk_document(document)
# First pass: extract relevant information from each chunk
relevant_parts = []
for i, chunk in enumerate(chunks):
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "Extract any information relevant to the question. Return 'NOT_RELEVANT' if nothing is relevant."},
{"role": "user", "content": f"Question: {question}\n\nText chunk {i+1}:\n{chunk}"}
],
max_tokens=500
)
result = response.choices[0].message.content
if "NOT_RELEVANT" not in result:
relevant_parts.append(result)
# Second pass: synthesize the answer
synthesis = client.chat.completions.create(
model="gpt-4o", # Use a stronger model for synthesis
messages=[
{"role": "system", "content": "Synthesize a comprehensive answer from these extracted passages."},
{"role": "user", "content": f"Question: {question}\n\nRelevant passages:\n" + "\n---\n".join(relevant_parts)}
]
)
return synthesis.choices[0].message.content
4. RAG (Retrieval-Augmented Generation)#
Instead of stuffing everything into the context window, retrieve only what's relevant:
# Simplified RAG pattern
from openai import OpenAI
client = OpenAI(
api_key="YOUR_CRAZYROUTER_KEY",
base_url="https://crazyrouter.com/v1"
)
def embed_text(text):
"""Generate embeddings for semantic search."""
response = client.embeddings.create(
model="text-embedding-3-small",
input=text
)
return response.data[0].embedding
def rag_query(question, knowledge_base):
"""Answer using only the most relevant context."""
# 1. Embed the question
q_embedding = embed_text(question)
# 2. Find top-k similar documents (cosine similarity)
relevant_docs = find_similar(q_embedding, knowledge_base, top_k=5)
# 3. Build focused context (much smaller than full knowledge base)
context = "\n\n".join(doc["text"] for doc in relevant_docs)
# 4. Generate answer with focused context
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "Answer based on the provided context. Cite sources when possible."},
{"role": "user", "content": f"Context:\n{context}\n\nQuestion: {question}"}
]
)
return response.choices[0].message.content
Token Counting by Provider#
| Provider | Token Counter | Library |
|---|---|---|
| OpenAI | tiktoken | pip install tiktoken |
| Anthropic | anthropic-tokenizer | pip install anthropic (built-in) |
| vertexai.tokenization | Google Cloud SDK | |
| Universal | Approximate: len(text) / 4 | Built-in Python |
# Quick token estimation across providers
def estimate_tokens(text, language="en"):
if language == "en":
return len(text.split()) * 1.3 # ~1.3 tokens per word
elif language in ["zh", "ja", "ko"]:
return len(text) * 0.7 # ~0.7 tokens per character
else:
return len(text) / 4 # General estimate
Pricing Optimization with Crazyrouter#
Context usage directly impacts cost. Here's how to optimize:
| Strategy | Token Reduction | Cost Impact |
|---|---|---|
| Conversation pruning | 30-50% | Save 30-50% |
| RAG instead of full context | 80-95% | Save 80-95% |
| Use mini models for preprocessing | N/A | Save 90% on prep work |
| Prompt caching (Claude/GPT) | N/A | Save 50-90% on cached tokens |
| Compare through Crazyrouter | N/A | Helps compare live provider pricing and routing options |
Combined savings example: RAG + smaller preprocessing models + provider comparison can materially reduce costs compared with naively stuffing everything into a premium long-context model.
FAQ#
What is the largest context window available in 2026?#
The largest practical context window changes as providers release new model versions and access tiers. Gemini-family models are often among the long-context leaders, but verify the current provider docs before designing around a specific 1M or 2M token limit.
Does a larger context window mean better results?#
Not necessarily. Research shows that models can struggle with information in the middle of very long contexts (the "Lost in the Middle" phenomenon). For best results, keep your context focused and place important information at the beginning or end.
How do I calculate the cost of my API calls based on tokens?#
Cost = (input_tokens x input_price / 1M) + (output_tokens x output_price / 1M). For example, if a model costs 10/1M output tokens, sending 50K input tokens and receiving 1K output tokens costs: (50,000 x 10 / 1M) = 0.01 = $0.135. Check live rates in Crazyrouter or the provider console before quoting this to customers.
What happens when I exceed the context window?#
The API will return an error (typically HTTP 400). You need to reduce your input by truncating conversation history, summarizing context, or using chunking strategies. Some SDKs handle this automatically.
Is prompt caching worth it?#
Often, yes. If you're sending the same system prompt or context repeatedly, prompt caching can reduce cached-token costs on supported providers. Availability, discount size, and cache rules vary by model.
How can I use multiple models with different context windows efficiently?#
Use Crazyrouter or a similar gateway to compare models by context length, latency, and price. Short queries can go to fast low-cost models; long-context tasks can go to models with the right input window and output cap.
Summary#
Understanding context windows and token limits is essential for building cost-effective, high-quality AI applications. The key takeaways:
- Know your model's live limits - Context windows vary by model version, endpoint, and account tier
- Optimize your context - Use RAG, pruning, and summarization
- Match model to task - Use large-context models only when needed
- Monitor costs - Tokens directly translate to money
For easier model comparison, Crazyrouter provides 300+ models through one API key with live pricing and routing options.
Start optimizing your AI costs → Get your Crazyrouter API key



