SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
14 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
1.6 KB · 27 lines typescript
Raw Blame History
1/**2 * Adaptive thinking + effort with the Node SDK on claude-sonnet-5 (cheapest model supporting both):3 * thinking {type:"adaptive", display:"summarized"} and output_config.effort "low" then "max".4 * Adaptive mode may skip thinking entirely on trivial prompts (no thinking block, thinking_tokens 0).5 * STATUS: LIVE_VERIFIED 2026-09-18 — effort=low: text only (thinking_tokens 0); effort=max: [thinking, text] with 49 thinking tokens (~$0.0007).6 * Run: node --env-file=.env --experimental-strip-types examples/anthropic/thinking/adaptive_effort.ts7 */8import Anthropic from "@anthropic-ai/sdk";9import { appendFileSync } from "node:fs";1011const MODEL = process.env.ANTHROPIC_MODEL ?? "claude-sonnet-5";12const client = new Anthropic({ maxRetries: 1 });13const log = (status: number, note: string) =>14  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");1516for (const effort of ["low", "max"] as const) {17  const msg = await client.messages.create({18    model: MODEL, max_tokens: 600,19    thinking: { type: "adaptive", display: "summarized" },20    output_config: { effort },21    messages: [{ role: "user", content: "What is 2+2? Reply with the number." }],22  } as any);23  const kinds = msg.content.map((b) => b.type);24  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}`);25  log(200, `example thinking/adaptive_effort.ts effort=${effort} ${MODEL}`);26}27