Claude and the Anthropic SDK (TypeScript) · Chapter 15 of 21
Adaptive thinking and effort
By the end of this chapter you can read and pay for Claude's thinking, ask for a summary of it, set how hard Claude works with effort, measure what each effort level costs and gets right, pick the cheapest effort that is good enough for each kind of question, and explain why last year's thinking budget is now a 400. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Cost
- 4 tasks
- TypeScript
- In the all labs plan
The first 2 chapters of Claude and the Anthropic SDK (TypeScript) are free. This one comes with the all labs plan.
Why you need this
Ramesh Sharma's pneumonia claim (CLM-2416) has five rules to check: waiting periods, non-payable items, sub-limits, the room and ICU limits, and the co-payment for a 64-year-old. Sahay on Opus 5.5 gets it right. Farhan looks at the usage: 665 output tokens for an answer of four lines, and 494 of them were thinking that nobody saw.
He asks two fair questions. Can we see what we are paying for? And do we need all of it on every question? "Is the ambulance paid?" is one line of the policy; working out CLM-2416 is a page of arithmetic. Thinking is how Claude gets the hard ones right, and effort is the one setting that decides how much of it you buy.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
see-the-thinking.ts: see the thinking
Send claimMessage('CLM-2405') (given) to 'claude-opus-5-5' (max_tokens 4096, system: policyWording()) twice: first with no thinking field, then with thinking: { type: 'adaptive', display: 'summarized' }.
For each reply print LABEL: N characters of thinking, T thinking tokens (LABEL omitted, then summarized; N the length of the thinking block's text; T from usage.output_tokens_details.thinking_tokens). Then print summary: TEXT, the second reply's thinking text.
- Task 2
effort-sweep.ts: an effort sweep
For each effort in low, medium, high, xhigh, send every claim of TEST (given), in order, to 'claude-sonnet-5-5' (max_tokens 4096, system: policyWording(), output_config: { effort }, claimMessage(id) as the one user message). A reply is right when its text contains inr(EXPECTED[id]).
Print EFFORT: R/4 right, $COST per effort (input_tokens x input + output_tokens x output with PRICES, over 1,000,000, 6 decimals), then choose: EFFORT, the cheapest effort that got all four right.
- Task 3
route-effort.ts: effort per route
Export effortFor(question): 'high' when the question names a claim id (CLM- and four digits, any case), 'low' otherwise. Export ask(question): send it to 'claude-sonnet-5-5' (max_tokens 4096, system: policyWording(), output_config: { effort: effortFor(question) }, the question as the one user message) and return the reply's text blocks, joined.
The check calls both with its own questions.
- Task 4 · interview question
Interview: no-budget.ts
"Last year's code capped thinking with budget_tokens; on Opus 5.5 every request fails. Why, and what instead?" Send OLD_REQUEST (given), catch the Anthropic.BadRequestError and print budget: STATUS TYPE. Send it again with thinking: { type: 'disabled' } instead and print disabled: STATUS TYPE.
Then send it with no thinking field and output_config: { effort: 'low' }, and print effort low: T thinking tokens, STOP.
What you will learn
- Adaptive thinking: Claude decides when and how much to think; the thinking block and its tokens.
- display: 'summarized': seeing a summary of the thinking.
- output_config.effort: low to max, and what it changes.
- The effort table: answers right and dollars, per effort.
- Effort per route: a low effort for lookups, a high one for claims.
- What is gone: budget_tokens, and turning thinking off on Opus 5.5.
More in Cost
Build "Adaptive thinking and effort" yourself
Parchi, a Jaipur startup, helps families claim health insurance. You build Sahay, a claims assistant that reads bills and policies with Claude, and measure what caching, models and effort cost. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Claude and the Anthropic SDK (TypeScript) are free. This one comes with the all labs plan.