Skip to content

feat(cli): update @anthropic-ai/sdk to 0.92.0 with prompt caching#245

Open
0xAxiom wants to merge 1 commit intomainfrom
feat/update-anthropic-sdk-with-caching
Open

feat(cli): update @anthropic-ai/sdk to 0.92.0 with prompt caching#245
0xAxiom wants to merge 1 commit intomainfrom
feat/update-anthropic-sdk-with-caching

Conversation

@0xAxiom
Copy link
Copy Markdown
Owner

@0xAxiom 0xAxiom commented May 1, 2026

What

Updates the Anthropic SDK from 0.32.1 to 0.92.0 (60 releases) and adds prompt caching to cut costs on repeated pipeline runs.

Changes in CLI/src/core/anthropic.ts

Prompt caching — the biggest functional improvement. AppFactory runs multi-stage pipelines where large system prompts are sent to Claude on every stage call. By marking system prompts with cache_control: { type: "ephemeral" }, the Anthropic API caches the tokenised system prompt for 5 minutes and applies a ~90% discount on cached input tokens.

// Before
system: systemPrompt

// After — system prompt is cached between repeated calls
system: [{ type: 'text', text: systemPrompt, cache_control: { type: 'ephemeral' } }]

Updated default modelclaude-sonnet-4-20250514claude-sonnet-4-6 (latest Sonnet generation).

Typed error handling — replaced fragile string-matching retry logic (msg.includes('rate')) with proper SDK error classes:

// Before
if (errorMessage.includes('rate') || errorMessage.includes('429')) { ... }

// After
if (err instanceof Anthropic.RateLimitError) return true;
if (err instanceof Anthropic.InternalServerError) return true;

Idiomatic streamingstreamClaude now uses .on('text', ...) + finalMessage() instead of manually iterating raw SSE events.

Why

  • @anthropic-ai/sdk 0.32.1 is ~60 minor versions behind the current 0.92.0, missing improvements to types, error handling, and streaming helpers
  • Prompt caching directly reduces per-run API costs; pipeline runs with large shared system prompts are a perfect fit for it
  • String-based retry detection is fragile — using the SDK's typed error hierarchy is more reliable and maintainable

Tested

  • TypeScript compiles clean (tsc --noEmit)
  • All 252 unit + integration tests pass (npm run test)
  • No behaviour changes in stub/test mode (existing test coverage validates all paths)

- Bump @anthropic-ai/sdk 0.32.1 -> 0.92.0 (60 releases of improvements)
- Update DEFAULT_MODEL to claude-sonnet-4-6 (latest Sonnet)
- Add prompt caching: system prompts now use cache_control: ephemeral,
  cutting input token costs ~90% on repeated pipeline calls that share
  the same large system instructions
- Replace string-matching retry logic with typed SDK error classes
  (Anthropic.RateLimitError, Anthropic.InternalServerError) for more
  accurate retry decisions
- Switch streamClaude to the idiomatic .on('text') + finalMessage()
  pattern instead of manual event iteration

All 252 tests pass.
@0xAxiom 0xAxiom requested a review from MeltedMindz as a code owner May 1, 2026 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant