AI / Claude Models Basics Interview Questions
What is Claude's context window and how are tokens counted?
Claude's context window is the total number of tokens it can process in a single API request. Tokens are the fundamental unit of text that Claude processes — roughly 3-4 characters per token for English, or about 75% of a word on average.
| Content type | Approximate token count |
|---|---|
| 1 word (English) | ~1.3 tokens on average |
| 1 page of text (~500 words) | ~650 tokens |
| 1,000 characters | ~250 tokens |
| A small image (~300×300) | ~1,000 tokens |
| A large image (1568×1568 or larger) | ~1,600 tokens (maximum, regardless of size) |
# Counting tokens before sending a request (avoids surprises) token_count = client.messages.count_tokens( model="claude-opus-4-8", system="You are a helpful assistant.", messages=[ {"role": "user", "content": "How many tokens is this message?"} ] ) print(f"Input tokens: {token_count.input_tokens}") # The response also includes token usage response = client.messages.create( model="claude-opus-4-8", max_tokens=1024, messages=[{"role": "user", "content": "Hello!"}] ) print(f"Input: {response.usage.input_tokens}, Output: {response.usage.output_tokens}")
What counts against the context window: system prompt + all conversation messages (both human and assistant turns) + tool definitions + image/PDF content + the model's own generated output. The max_tokens parameter reserves space for the output within the window.
More Related questions...