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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
