Extended Thinking, Effort & Multimodal Basics
7 examples to get you started with Extended Thinking, Effort & Multimodal - 5 basic and 2 intermediate.
Prerequisites
- Install the official SDK:
pip install anthropic. - Set your API key as an environment variable:
export ANTHROPIC_API_KEY=sk-ant-.... - Create a client once and reuse it:
client = anthropic.Anthropic(). - For image examples, have a small JPEG or PNG on disk to encode as base64.
Basic Examples
1. A Plain Request, No Thinking Configured
The starting point before any thinking or effort tuning is applied.
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=512,
messages=[{"role": "user", "content": "Summarize the tradeoffs of microservices."}],
)
print(response.content[0].text)messages.createsends a single-turn request with nothinkingconfig, so no reasoning block is returned.response.contentis a list of content blocks; for a plain text answer it usually holds one text block.- This is the baseline every other example in this page builds on.
2. Enabling Adaptive Thinking
Turn on adaptive thinking so Claude decides how much reasoning a task needs.
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
thinking={"type": "adaptive"},
messages=[{"role": "user", "content": "Plan a phased database migration."}],
)
for block in response.content:
print(block.type)thinking={"type": "adaptive"}lets Claude choose reasoning depth per request instead of a fixed budget.- Looping over
response.contentshows both athinkingblock and atextblock for a task like this. - Simple prompts may still return little or no visible reasoning, that is expected behavior.
Related: Enabling Adaptive Thinking with thinking: {type: 'adaptive'} - full walkthrough of this config
3. Reading the Thinking Block
Once thinking is enabled, extract the reasoning separately from the final answer.
thinking_text = None
answer_text = None
for block in response.content:
if block.type == "thinking":
thinking_text = block.thinking
elif block.type == "text":
answer_text = block.text
print("Reasoning:", thinking_text)
print("Answer:", answer_text)- The
thinkingblock and thetextblock are separate items in the samecontentlist. - Checking
block.typelets your application log reasoning separately from what the user sees. - Not every response includes a
thinkingblock, guard withis Nonechecks in real code.
4. Setting an Effort Level
Cap reasoning depth and cost with the effort parameter.
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
thinking={"type": "adaptive"},
output_config={"effort": "low"},
messages=[{"role": "user", "content": "Classify this ticket as billing, bug, or feature request."}],
)
print(response.content[-1].text)output_config={"effort": "low"}favors speed and low cost over deep reasoning.- Effort is independent from the
thinkingconfig, both can be set together. loweffort suits simple, high-volume tasks like classification.
Related: Tuning the effort Parameter for Cost and Speed - choosing a level per workload
5. Sending One Image Alongside Text
Ask Claude to look at an image and answer a question about it.
import base64
import anthropic
client = anthropic.Anthropic()
with open("chart.png", "rb") as f:
image_data = base64.standard_b64encode(f.read()).decode("utf-8")
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=512,
messages=[
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": image_data,
},
},
{"type": "text", "text": "What trend does this chart show?"},
],
}
],
)
print(response.content[0].text)contentbecomes a list of typed blocks when a message mixes an image with text.base64.standard_b64encodeturns the raw bytes into the string format the API expects.media_typemust match the actual file format, mismatches cause request errors.
Related: Sending Images for Vision Analysis with Base64 Encoding - deeper walkthrough of vision input
Intermediate Examples
6. Combining Adaptive Thinking, Effort, and an Image
Reason through a question that requires both looking at an image and thinking through the answer.
import base64
import anthropic
client = anthropic.Anthropic()
with open("architecture-diagram.png", "rb") as f:
image_data = base64.standard_b64encode(f.read()).decode("utf-8")
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=1500,
thinking={"type": "adaptive"},
output_config={"effort": "high"},
messages=[
{
"role": "user",
"content": [
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/png",
"data": image_data,
},
},
{"type": "text", "text": "Identify any single points of failure in this architecture."},
],
}
],
)
for block in response.content:
if block.type == "thinking":
print("Reasoning:", block.thinking[:200], "...")
elif block.type == "text":
print("Answer:", block.text)- All three settings compose:
thinking,output_config, and a multimodalcontentlist work in the same request. higheffort is appropriate here because spotting architectural flaws benefits from deeper reasoning.- Truncating the printed reasoning (
[:200]) is a common pattern when logging long thinking blocks.
7. Handling a Response That Has No Thinking Block
Write defensive code, since not every response returns visible reasoning.
def extract_answer(response):
thinking = None
answer = None
for block in response.content:
if block.type == "thinking":
thinking = block.thinking
elif block.type == "text":
answer = block.text
return thinking, answer
response = client.messages.create(
model="claude-sonnet-5",
max_tokens=256,
thinking={"type": "adaptive"},
output_config={"effort": "low"},
messages=[{"role": "user", "content": "What is the capital of France?"}],
)
thinking, answer = extract_answer(response)
print("Had reasoning:", thinking is not None)
print("Answer:", answer)- A trivial factual question with
loweffort often returns nothinkingblock at all, adaptive thinking skipped it. - Writing a small
extract_answerhelper keeps every call site from repeating the same loop. - Checking
thinking is not Nonebefore using it avoidsAttributeErrorin production code.
Related: Effort Levels and Thinking Display Options Reference - full table of levels and display modes
Stack versions: Written against the Claude model lineup current as of ~June 2026 - Claude Fable 5, Claude Opus 4.8, Claude Sonnet 5 (the default), and Claude Haiku 4.5 - and the official
anthropicPython SDK (latest 0.x release). Model names, SDK versions, and pricing move quickly - verify current specifics at platform.claude.com/docs before relying on them.