// System prompt as text blocks with cache_control // STATUS: LIVE_VERIFIED 2026-09-18 with @anthropic-ai/sdk 0.126.0. // Run: node --env-file=.env --experimental-strip-types examples/anthropic/messages/system.ts (ANTHROPIC_API_KEY read from env by the SDK) import Anthropic from "@anthropic-ai/sdk"; import { appendFileSync } from "node:fs"; const client = new Anthropic(); const MODEL = "claude-haiku-4-5-20251001"; const log = (path: string, status: number, note: string) => appendFileSync("reports/live-requests.jsonl", JSON.stringify({ ts: new Date().toISOString().replace(/\.\d+Z$/, "Z"), provider: "anthropic", method: "POST", path, status, est_cost_usd: 0.00005, note }) + "\n"); const msg = await client.messages.create({ model: MODEL, max_tokens: 16, system: [{ type: "text", text: "You are terse. Answer in one word.", cache_control: { type: "ephemeral" } }], messages: [{ role: "user", content: "Reply with OK." }], }); console.log(msg.content[0]?.type === "text" ? msg.content[0].text : "", "| cache_creation:", JSON.stringify(msg.usage.cache_creation)); log("/v1/messages", 200, "example system.ts");