Skip to content

feat: Add Anthropic implicit caching support#140

Merged
seanbrar merged 1 commit intomainfrom
feat/anthropic-implicit-caching
Mar 6, 2026
Merged

feat: Add Anthropic implicit caching support#140
seanbrar merged 1 commit intomainfrom
feat/anthropic-implicit-caching

Conversation

@seanbrar
Copy link
Owner

@seanbrar seanbrar commented Mar 6, 2026

Summary

Adds support for Anthropic's implicit caching mechanism, allowing caching of prompt prefixes in generated responses. Introduces a new implicit_caching option with smart defaults (enabled for single calls, disabled for fan-out) to optimize costs, while remaining capability-transparent.

Related issue

None

Test plan

Added unit and provider characterization tests in tests/test_pipeline.py and tests/test_providers.py covering:

  • Single-call Anthropic workloads defaulting implicit_caching on.
  • Multi-call fan-out defaulting implicit_caching off.
  • Explicit implicit_caching=True requests correctly failing with a ConfigurationError on unsupported providers (e.g. Gemini).
  • Anthropic capability correctly passing cache_control={"type": "ephemeral"}.
    just check passes with all the tests successfully passing.

Notes

Anthropic caching applies a 1.25x premium on cache writes, so the default for run_many fan-outs is disabled to prevent runaway costs on concurrent requests that would simultaneously write the same prefix.


  • PR title follows conventional commits
  • make check passes
  • Tests cover the meaningful cases, not just the happy path
  • Docs updated (if this changes public API or user-facing behavior)

- Implement `implicit_caching` option for Anthropic provider
- Set smart defaults: enabled for single-call, disabled for fan-out
- Update ProviderCapabilities to enforce caching support
- Add runtime errors for unsupported providers
- Document caching approaches in docs (caching.md, portable-code.md, etc.)
- Add test coverage for new caching behavior
@seanbrar seanbrar merged commit 9869d96 into main Mar 6, 2026
10 checks passed
@seanbrar seanbrar deleted the feat/anthropic-implicit-caching branch March 6, 2026 01:13
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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