Skip to content

Improved prompt caching when using Anthropic models on OpenRouter with native tool calling - #4853

Merged
chrarnoldus merged 3 commits into
mainfrom
christiaan/anthropic-caching
Jan 7, 2026
Merged

Improved prompt caching when using Anthropic models on OpenRouter with native tool calling#4853
chrarnoldus merged 3 commits into
mainfrom
christiaan/anthropic-caching

Conversation

@chrarnoldus

Copy link
Copy Markdown
Collaborator

Anthropic prompt caching has worked less well since 12 Dec: https://us.posthog.com/project/141915/insights/AhRqQwgk

@changeset-bot

changeset-bot Bot commented Jan 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 435c879

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kilo-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kilo-code-bot

kilo-code-bot Bot commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This PR introduces a new Anthropic cache breakpoint implementation (kilocode.ts) that extends caching support to include tool result messages (role: "tool"), which the original implementation didn't handle. This is important for native tool calling scenarios where tool results should also benefit from prompt caching.

Key improvements:

  • Properly handles tool role messages alongside user messages for cache breakpoints
  • Adds cache control to the last item in array content (including images)
  • Finds system prompt from messages array rather than relying on the passed parameter
  • Comprehensive test coverage for all scenarios
Files Reviewed (4 files)
  • .changeset/cute-flies-dance.md - Changeset for the patch
  • src/api/providers/openrouter.ts - Import change to use new implementation
  • src/api/transform/caching/kilocode.ts - New caching implementation with tool support
  • src/api/transform/caching/__tests__/kilocode.spec.ts - Comprehensive tests

@chrarnoldus
chrarnoldus merged commit 86d7217 into main Jan 7, 2026
12 checks passed
@chrarnoldus
chrarnoldus deleted the christiaan/anthropic-caching branch January 7, 2026 16:40
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.

2 participants