Skip to content

feat: add prompt caching + upgrade @anthropic-ai/sdk to 0.91.1#237

Open
0xAxiom wants to merge 1 commit intomainfrom
fix/add-prompt-caching
Open

feat: add prompt caching + upgrade @anthropic-ai/sdk to 0.91.1#237
0xAxiom wants to merge 1 commit intomainfrom
fix/add-prompt-caching

Conversation

@0xAxiom
Copy link
Copy Markdown
Owner

@0xAxiom 0xAxiom commented Apr 30, 2026

What

  • Prompt caching: system prompts in callClaude() and streamClaude() are now marked with cache_control: { type: 'ephemeral' }, enabling Anthropic's prompt caching for all API calls that pass a system prompt
  • SDK upgrade: @anthropic-ai/sdk bumped from ^0.32.0^0.91.1 — the old version lacked TypeScript types for cache_control on TextBlockParam and cache_read_input_tokens/cache_creation_input_tokens on Usage
  • Cache logging: debug-level log line shows cache hit tokens vs creation tokens so users can see savings
  • Ajv bug fix: new Ajv.default() in stages.ts was incorrectly double-dereferencing the ESM default export — changed to new Ajv() (pre-existing bug)

Why

AppFactory pipeline runs pass large system prompts (stage templates, standards files) on every Claude call. Without caching, each call pays full input-token cost for the same repeated context. With ephemeral caching enabled:

  • Latency drops significantly on cache hits (tokens served from cache, not re-processed)
  • Cost reduces by ~90% on cached input tokens (Anthropic's published cache-hit pricing)
  • No behaviour change — the API response content is identical

Tested

  • npm run type-check:cli — passes clean (0 errors)
  • npm run test:unit — 159/159 tests pass
  • Streaming and non-streaming paths both updated consistently

🤖 Generated with Claude Code

- Enable ephemeral prompt caching on system prompts in callClaude()
  and streamClaude() — reduces latency and cost on repeated pipeline
  runs that reuse the same large system prompt
- Log cache_read_input_tokens / cache_creation_input_tokens at debug
  level so users can see caching savings
- Bump @anthropic-ai/sdk ^0.32.0 → ^0.91.1 to get proper TypeScript
  types for cache_control on TextBlockParam and UsageCacheStats
- Fix pre-existing Ajv.default() instantiation bug in stages.ts
  (ESM default import was incorrectly double-dereferenced)
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