#20866: fix: disable prompt caching for non-Anthropic Bedrock models
agents
size: XS
Cluster:
Bedrock and Caching Improvements
When using non-Anthropic models on Bedrock (like Amazon Nova or Mistral), the upstream pi-ai provider injects `cachePoint` blocks into message content by default. These models don't support the Anthropic-specific cache point extension and reject requests with 'extraneous key [cachePoint] is not permitted'.
This passes `cacheRetention: "none"` to the pi-ai stream options for non-Anthropic Bedrock models, which prevents cachePoint blocks from being added in the first place. Anthropic models on Bedrock are unaffected and keep their existing caching behavior.
Fixes #20815
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes Bedrock API errors when using non-Anthropic models (Amazon Nova, Mistral) by disabling prompt caching for them. The pi-ai Bedrock provider injects `cachePoint` blocks by default, but only Claude models support this Anthropic-specific extension.
The fix adds a detection function to identify Claude model IDs (matching `anthropic.claude` or `anthropic/claude`) and wraps the stream function to pass `cacheRetention: "none"` for all other Bedrock models. This prevents the upstream provider from injecting unsupported cache control metadata that would cause API rejection errors.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The fix is narrowly scoped, well-documented, and follows existing patterns in the codebase. The detection logic correctly identifies Anthropic models using case-insensitive string matching, and the wrapper correctly chains with existing streamFn wrappers. No tests need updating since this is defensive behavior that prevents errors rather than changing existing functionality.
- No files require special attention
<sub>Last reviewed commit: 2302126</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#22303: fix: extend cacheRetention auto-injection and runtime pass-through ...
by snese · 2026-02-21
87.9%
#8963: fix(bedrock): fix amazon bedrock model problem of dealing with profile
by 67ailab · 2026-02-04
80.1%
#17560: fix: Anthropic Prompt Caching Not Working - Missing cache_control H...
by MisterGuy420 · 2026-02-15
79.6%
#17015: fix: correct Claude 4.5 context limits in model registry
by Limitless2023 · 2026-02-15
76.9%
#14508: fix(models): allow forward-compat models in allowlist check
by jonisjongithub · 2026-02-12
76.4%
#5500: Fix #5290 Bedrock Auto Discovery fails to retrieve or support Inferen…
by heqiqi · 2026-01-31
76.3%
#9905: fix: require provider prefix for models set without alias (#5790)
by petter-b · 2026-02-05
74.6%
#6136: fix(agents): cast streamParams to allow cacheRetention property ass...
by macd2 · 2026-02-01
74.5%
#13119: fix: add forward-compat for google-antigravity claude-opus-4-6 models
by sdb001 · 2026-02-10
74.4%
#13401: fix: slug generator should use agent's primary model instead of har...
by pahud · 2026-02-10
74.1%