Skip to content

feat(js/plugins/anthropic): add prompt caching support#4189

Merged
cabljac merged 13 commits intogenkit-ai:mainfrom
invertase:add-prompt-caching-2
Jan 23, 2026
Merged

feat(js/plugins/anthropic): add prompt caching support#4189
cabljac merged 13 commits intogenkit-ai:mainfrom
invertase:add-prompt-caching-2

Conversation

@cabljac
Copy link
Copy Markdown
Contributor

@cabljac cabljac commented Jan 19, 2026

This PR adds support for prompt caching to the anthropic js plugin.

Supersedes invertase#25

Test app covers:

  • System prompt caching
  • User prompt caching
  • Tool prompt caching
  • Image prompt caching
  • PDF prompt caching

Checklist (if applicable):

@github-actions github-actions Bot added docs Improvements or additions to documentation js config labels Jan 19, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @cabljac, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Anthropic plugin's prompt caching capabilities by moving from a global "cacheSystemPrompt" configuration to a more granular, message-part-level "cache_control" metadata. This allows developers to precisely define caching behavior for different elements within a prompt, including text, images, PDFs, and tool calls. The update also introduces detailed cache-related token usage metrics and provides extensive documentation and examples to facilitate adoption of this new, flexible caching approach.

Highlights

  • Granular Prompt Caching: Introduced the ability to specify "cache_control" metadata directly on individual message parts (text, media, tools) within system and user messages, allowing for more fine-grained control over caching behavior.
  • Removal of Global Caching Option: Deprecated and removed the "cacheSystemPrompt" configuration option from the Anthropic plugin, shifting caching control to message-level metadata.
  • Enhanced Usage Metrics: Added new custom usage metrics to the response, providing detailed token counts related to cache creation and reads (e.g., "cache_creation_input_tokens", "cache_read_input_tokens", "ephemeral_5m_input_tokens", "ephemeral_1h_input_tokens").
  • Updated Documentation and Examples: Included new documentation in "README.md" and comprehensive example flows in "js/testapps/anthropic/src/stable/prompt_caching.ts" to demonstrate the new caching mechanism across various content types (system, user, image, PDF, tool calls).
  • Refactored Internal Logic: Modified the Anthropic plugin's internal runner logic to process "cache_control" metadata from message parts and removed the previous beta header for prompt caching, streamlining the API integration.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@cabljac cabljac changed the title Add prompt caching 2 feat(js/plugins/anthropic): add prompt caching support Jan 19, 2026
Comment thread js/plugins/anthropic/README.md Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces prompt caching functionality by allowing cache_control metadata on message parts, replacing the global cacheSystemPrompt option. The changes are well-implemented across the plugin, including updates to message processing, request body generation, and documentation. I've provided a couple of suggestions to improve documentation clarity and clean up a redundant test case. Overall, this is a solid contribution that enhances the plugin's capabilities.

Comment thread js/plugins/anthropic/README.md
Comment thread js/plugins/anthropic/tests/stable_runner_test.ts Outdated
@cabljac cabljac requested a review from dackers86 January 19, 2026 15:16
@cabljac cabljac marked this pull request as ready for review January 19, 2026 16:34
@cabljac cabljac enabled auto-merge (squash) January 19, 2026 16:35
Comment thread js/testapps/anthropic/src/stable/prompt_caching.ts Outdated
@cabljac cabljac force-pushed the add-prompt-caching-2 branch from bba1b6a to 58ce6df Compare January 23, 2026 15:41
@cabljac cabljac force-pushed the add-prompt-caching-2 branch from a615e2e to fc2c7d3 Compare January 23, 2026 16:45
@cabljac cabljac merged commit 554bff3 into genkit-ai:main Jan 23, 2026
5 checks passed
@yesudeep yesudeep mentioned this pull request Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config docs Improvements or additions to documentation js

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants