Search across all documentation pages
Numbered practices for getting reliable, cost-efficient results out of extended thinking, the effort parameter, and multimodal input.
thinking={"type": "adaptive"} rather than guessing a fixed reasoning budget. Adaptive thinking lets Claude calibrate depth per request, avoiding both under-reasoning on hard tasks and wasted reasoning on easy ones.thinking block as expected, not an error. Simple prompts often produce no visible reasoning under adaptive thinking; only investigate if a genuinely complex prompt returns none.response.content by iterating and checking block.type, never by fixed index. The thinking block, when present, can occupy index 0, shifting the position of the text block.max_tokens generously for prompts likely to trigger deep reasoning. Reasoning tokens and answer tokens share the same output budget, and a truncated thinking block can cut off the final answer.thinking block separately from the user-facing answer. This supports debugging and auditing reasoning without conflating it with the response your users see.low, general assistant replies fit medium, code review and planning fit high, safety-critical analysis fits max.high and max can meaningfully slow down a user-facing endpoint; measure before committing.low, medium, high, max) before sending the request. Catching a typo like "med" at the call site is cheaper than debugging an opaque API error later.max effort for genuinely high-stakes calls. Applying it broadly "to be safe" inflates cost and latency across the whole application without a matching quality benefit on routine tasks.thinking blocks before appending them to a multi-turn conversation's history. Re-sending raw reasoning blocks as plain assistant text bloats token usage across a long conversation.media_type from the actual file format, never hardcode or guess it. A mismatched media_type can cause a request error or a misread image.base64.standard_b64encode(...).decode("utf-8") before assigning to data. The API expects a base64 string, not raw bytes or a file path.file_id durably, not just in a local variable. Persisting file_id alongside your own document identifier avoids redundant uploads across process runs.file_id has expired or is invalid. Retention policies vary by account; catch the error and re-upload if the source file is still available.messages, not your entire local session history. The API only knows what's in the current request's messages list; keep fuller history locally for logging without resending all of it.purpose explicitly on every Files API upload call. Omitting or mis-setting it can make the uploaded file unusable in a document content block later.Mapping effort level to task type (practice B.1) usually has the largest cost impact, since it's the most direct lever on reasoning depth per request across your whole application.
For most workloads, yes, it lets Claude calibrate reasoning depth per request rather than you guessing a fixed setting. The exception is extremely simple, high-volume tasks where the overhead of even checking for a thinking block isn't worth it.
Occasionally, for specialized tooling audiences like developers reviewing code review output, but it should always be an explicit opt-in, not the default response surface.
Mismatching media_type with the actual file format, or sending raw un-encoded bytes instead of a base64 string, both covered under practice D.
As soon as you expect to reference the same image or document in more than one request. One-off analysis is fine inline; anything reused benefits from the Files API's upload-once model.
Start by classifying the task's stakes and complexity, then benchmark latency and cost at a couple of candidate levels against real traffic before locking in a default.
The mechanics apply the same way, but baseline reasoning capability differs by model (Fable 5, Opus 4.8, Sonnet 5, Haiku 4.5), so the same effort level won't produce identical depth or cost across models.
An invalid value like "med" instead of "medium" otherwise surfaces as an opaque API error deep in a request path, rather than a clear validation failure at the call site.
No, it's primarily a UX and data-sensitivity decision. Effort is the cost lever; display governs what reasoning content, if any, reaches the client or gets logged.
You lose the reference once the process holding it in memory ends, forcing a redundant re-upload the next time the document is needed, defeating the efficiency the Files API provides.
No, only include the prior turns relevant to the current question. Keep a fuller local history for your own tracking without resending the entire session on every call.
Yes, if high effort already produces adequate quality for that task category, max adds cost and latency without a proportional benefit. Reserve it for the genuinely highest-stakes cases identified through evaluation.
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.