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.1 KB · 16 lines typescript
Raw Blame History
1// stop_sequences → stop_reason stop_sequence2// STATUS: LIVE_VERIFIED 2026-09-18 with @anthropic-ai/sdk 0.126.0.3// Run: node --env-file=.env --experimental-strip-types examples/anthropic/messages/stop_sequences.ts   (ANTHROPIC_API_KEY read from env by the SDK)4import Anthropic from "@anthropic-ai/sdk";5import { appendFileSync } from "node:fs";67const client = new Anthropic();8const MODEL = "claude-haiku-4-5-20251001";9const log = (path: string, status: number, note: string) =>10  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");11const msg = await client.messages.create({ model: MODEL, max_tokens: 32, stop_sequences: ["3"], system: "Output only what is asked.",12  messages: [{ role: "user", content: "Count: 1 2 3 4 5" }] });13console.log(JSON.stringify(msg.content[0]?.type === "text" ? msg.content[0].text : ""), msg.stop_reason, msg.stop_sequence);14if (msg.stop_reason !== "stop_sequence") throw new Error("expected stop_sequence");15log("/v1/messages", 200, "example stop_sequences.ts");16