One endpoint, content blocks and stop reasons
Know the request shape (model, max_tokens, system, messages), the response shape (content blocks, stop_reason, usage) and the operational basics (streaming, retries, keys). That covers most Claude API interview questions.
- ModelsOpus, Sonnet and Haiku tiers and how to choose.
- RequestsMessages, system prompt, multi-turn and media.
- ProductionStreaming, stop reasons and error handling.
More and more companies build on Claude, so AI-engineering interviews now include questions on how the Anthropic API works. Interviewers check that you can make a correct request, read the response properly, hold a conversation, and handle long outputs and errors. Examples use the official Python SDK (pip install anthropic).
1. What is the Claude model family and how do you choose a model?
Claude models come in tiers. Opus is the most capable for complex reasoning, long agentic tasks and hard coding work; Sonnet balances capability and speed for everyday production use; Haiku is the fastest and cheapest, for high-volume or latency-sensitive work such as classification. At the time of writing (November 2026) the current versions are Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5, with Claude Fable 5.1 as Anthropic's most capable widely available model. Choose by measuring quality, latency and cost on your own task — not by habit.
2. Show a basic Messages API call and explain the response.
Everything goes through one endpoint, POST /v1/messages. You send the model id, a maximum output length and a list of messages; the response contains a list of content blocks (text, and possibly thinking or tool-use blocks), a stop_reason and token usage.
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
system="You are a friendly interview coach for engineering students in India.",
messages=[{"role": "user", "content": "Give me three tips for my first technical interview."}],
)
for block in response.content:
if block.type == "text":
print(block.text)
print(response.stop_reason, response.usage.input_tokens, response.usage.output_tokens)3. How do you hold a multi-turn conversation?
The API is stateless: send the full history every time, with messages alternating between user and assistant, starting with user. Append the assistant's reply (its content blocks, not just the text) before adding the next user message. For very long conversations, trim or summarise older turns, or use the API's context-management features.
history = [
{"role": "user", "content": "My name is Asha. I am preparing for a Java role."},
{"role": "assistant", "content": "Nice to meet you, Asha! Shall we start with collections?"},
{"role": "user", "content": "Yes — ask me one question."},
]
reply = client.messages.create(model="claude-opus-5-5", max_tokens=512, messages=history)
history.append({"role": "assistant", "content": reply.content})4. What does the system prompt do?
It is a top-level system parameter — not a message — that sets the role, rules, tone, background knowledge and output format for the whole conversation. Put durable instructions and reference material there, and keep it stable between requests: that improves consistency and lets prompt caching reuse it.
5. What are the possible stop reasons?
end_turn— the model finished naturally.max_tokens— output hit your limit and was cut off; raisemax_tokensor continue.stop_sequence— a custom stop string appeared.tool_use— the model wants you to run a tool.pause_turn— a long server-side step paused; send the response back to continue.refusal— the request was declined for safety reasons.
Always check stop_reason before using the output.
6. Why and how do you stream responses?
Streaming sends tokens as they are generated, so users see text immediately instead of waiting for the whole answer, and it avoids HTTP timeouts on long outputs. The SDK gives you a simple text iterator and the complete final message at the end.
with client.messages.stream(
model="claude-opus-5-5",
max_tokens=4096,
messages=[{"role": "user", "content": "Explain HashMap internals for a fresher."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)
final = stream.get_final_message() # full message with usage7. How does Claude handle images and PDFs?
Claude is multimodal: add image or document content blocks (base64 data, a URL, or a file uploaded once through the Files API) before your text question. It can read screenshots, charts, handwritten notes and multi-page PDFs including their tables.
import base64
pdf = base64.standard_b64encode(open("offer_letter.pdf", "rb").read()).decode()
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": [
{"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": pdf}},
{"type": "text", "text": "List the joining date, CTC and notice period."},
]}],
)8. How should you handle errors and rate limits?
Catch the SDK's typed exceptions from most to least specific — for example RateLimitError (429), BadRequestError (400) and the general APIStatusError. The SDK already retries connection errors, 429s and 5xx responses (twice by default) with back-off; add your own retry or queueing for heavy load, respect the retry-after header, and never retry a 400 without fixing the request. Keep API keys in environment variables or a secrets manager — never in code or the browser.
try:
response = client.messages.create(model="claude-opus-5-5", max_tokens=512, messages=msgs)
except anthropic.RateLimitError:
queue_for_later(msgs)
except anthropic.BadRequestError as e:
log.error("Fix the request: %s", e.message)
except anthropic.APIStatusError as e:
log.error("API error %s", e.status_code)Remember
Key points
- Stateless API
Send the full history on every request.
- Iterate content blocks
Check each block's type before reading text.
- Check stop_reason
max_tokens means the answer was cut off.
- Stream long outputs
Better UX and no HTTP timeouts.
Interview drill
Follow-up questions
What the interviewer asks after your first answer. Turn on practice mode, answer each one aloud, then reveal.
-
1 What is the difference between input and output tokens? Basic
Input tokens are everything you send (system prompt, history, documents); output tokens are what the model generates. Output tokens cost more per token, and both appear in
usage. -
2 Can you prefill the start of Claude's answer? Intermediate
Older models allowed ending the messages with a partial assistant turn. Current Claude models reject assistant prefill; use structured outputs or clear format instructions in the system prompt instead.
-
3 How do you get guaranteed JSON from Claude? Intermediate
Use structured outputs — a JSON schema supplied through
output_config(the Python SDK'smessages.parse()validates the result into a typed object) — or a tool withstrict: true. -
4 What is extended (adaptive) thinking? Intermediate
Claude reasons internally before answering. On current models it is adaptive — the model decides how much to think — and you steer depth and spend with the
effortsetting (low to max). Higher effort helps hard reasoning and coding; lower effort suits simple, high-volume tasks. -
5 How do you estimate cost before sending a request? Basic
Use the token-counting endpoint to count input tokens for a prompt, multiply by the model's price, and add an estimate for output tokens.