/** * Adaptive thinking + effort with the Node SDK on claude-sonnet-5 (cheapest model supporting both): * thinking {type:"adaptive", display:"summarized"} and output_config.effort "low" then "max". * Adaptive mode may skip thinking entirely on trivial prompts (no thinking block, thinking_tokens 0). * STATUS: LIVE_VERIFIED 2026-09-18 — effort=low: text only (thinking_tokens 0); effort=max: [thinking, text] with 49 thinking tokens (~$0.0007). * Run: node --env-file=.env --experimental-strip-types examples/anthropic/thinking/adaptive_effort.ts */ import Anthropic from "@anthropic-ai/sdk"; import { appendFileSync } from "node:fs"; const MODEL = process.env.ANTHROPIC_MODEL ?? "claude-sonnet-5"; const client = new Anthropic({ maxRetries: 1 }); const log = (status: number, note: string) => appendFileSync("reports/live-requests.jsonl", JSON.stringify({ ts: new Date().toISOString(), provider: "anthropic", method: "POST", path: "/v1/messages", status, est_cost_usd: 0.0001, note }) + "\n"); for (const effort of ["low", "max"] as const) { const msg = await client.messages.create({ model: MODEL, max_tokens: 600, thinking: { type: "adaptive", display: "summarized" }, output_config: { effort }, messages: [{ role: "user", content: "What is 2+2? Reply with the number." }], } as any); const kinds = msg.content.map((b) => b.type); console.log(`effort=${effort}: blocks=${kinds.join(",")} thinking_tokens=${(msg.usage as any).output_tokens_details?.thinking_tokens} text=${msg.content.find((b) => b.type === "text")?.text}`); log(200, `example thinking/adaptive_effort.ts effort=${effort} ${MODEL}`); }