fix(llm): remove top-level cache_control from Claude provider (fixes #2512)#2521
fix(llm): remove top-level cache_control from Claude provider (fixes #2512)#2521nankingjing wants to merge 1 commit into
Conversation
…ffaan-m#2512) The top-level cache_control param was being passed to Anthropic().messages.create() which the SDK rejects (cache_control belongs on individual content blocks, not the top-level request). This broke every Claude invocation. Remove the invalid top-level param. Users who need prompt caching can add cache_control to individual content blocks per the Anthropic API docs.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe Claude provider request payload removes the top-level Anthropic ChangesClaude provider request construction
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
| Filename | Overview |
|---|---|
| src/llm/providers/claude.py | Removes the invalid top-level Claude cache_control request field while keeping the rest of the request shape unchanged. |
Reviews (2): Last reviewed commit: "fix(llm): remove top-level cache_control..." | Re-trigger Greptile
| @@ -67,7 +67,6 @@ def generate(self, input: LLMInput) -> LLMOutput: | |||
| "model": model, | |||
There was a problem hiding this comment.
Prompt Caching Becomes Unreachable
When generate() builds Claude requests, callers only pass plain LLMInput messages and Message.to_dict() does not expose a way to add per-block cache_control. Removing the provider-level cache setting means existing Claude calls lose the only automatic cache breakpoint in this path, so long repeated prompts can stop producing cache token usage and pay full input cost on every request.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Verified against the SDK floor this repo pins (anthropic>=0.111.0): top-level cache_control on messages.create() is the documented automatic prompt caching parameter on the first-party Anthropic API - the SDK auto-places the breakpoint on the last cacheable block - so it is accepted, not rejected, on every SDK version the project supports. That makes this finding substantively right: the removal trades away automatic caching to fix an error that does not reproduce on a pin-compliant install. The failure reported in #2512 points to an out-of-range environment (an SDK older than the pin, or a platform without automatic caching such as Bedrock/Vertex). Deliberately not adding a regression test asserting the parameter's absence, since that would enshrine the caching regression; flagging for maintainers to confirm the #2512 reproduction environment before merging this or #2515.
daltino
left a comment
There was a problem hiding this comment.
DECISION: APPROVE
This PR removes an unused "cache_control" parameter from the generate method in the Claude provider, resolving issue #2512. The change simplifies the payload without impacting functionality, aligning with clean code practices. No additional context or documentation updates are necessary, as this is a minor fix.
|
Local review from Codex automation: this overlaps with #2515 but lacks the same regression coverage and appears to remove the top-level parameter without preserving the structured prompt-cache behavior. Recommendation: close/supersede this in favor of #2515, or add regression tests and preserve cache-control-on-system-block behavior if this PR is kept alive. |
6685dea to
78a0e21
Compare
|
@rjjelley Thanks for the pointer to #2515 - agreed the two PRs overlap. One finding worth weighing before either merges: with the SDK floor this repo pins ( |
Fixes #2512
The top-level
cache_control: {"type": "ephemeral"}param was being passed toAnthropic().messages.create()which the SDK rejects (cache_control belongs on individual content blocks, not the top-level request). This broke every Claude invocation.Fix: Remove the top-level cache_control param. Users who need cache control can add it to individual content blocks per the Anthropic API docs.