Skip to content

Conversation

@cabljac
Copy link
Contributor

@cabljac cabljac commented Jan 27, 2026

This PR should resolve #4245

Checklist (if applicable):

@cabljac cabljac force-pushed the @invertase/anthropic-runtime-apikey branch from bfb38cb to b14f089 Compare January 27, 2026 18:41
@gemini-code-assist
Copy link
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 API key handling by introducing lazy and per-request API key resolution. This change allows developers to defer API key provision until a model request is made, or to override a default key for specific requests. This flexibility is crucial for multi-tenant applications or scenarios where API keys need to be managed dynamically, moving the responsibility of client instantiation and API key validation closer to the point of use.

Highlights

  • Lazy API Key Calculation: The Anthropic plugin now calculates the API key lazily at request time, rather than requiring it during plugin initialization. This allows for more flexible API key management.
  • Per-Request API Key Support: Users can now provide an apiKey directly within the config object of a model request. This config.apiKey takes precedence over plugin-level or environment variable keys, enabling per-request authentication.
  • Deferred API Key Validation: The plugin can be initialized with apiKey: false to explicitly defer API key validation. In this mode, an API key must be provided with each request via config.apiKey, or an error will be thrown at request time.
  • Refactored Client Instantiation: The internal logic for creating Anthropic client instances has been refactored. Clients are now instantiated dynamically within the claudeRunner function, ensuring they are built with the correct API key at the moment of execution.
  • Enhanced API Key Resolution Logic: A new calculateApiKey utility function has been introduced to centralize the logic for determining the effective API key, prioritizing request.config.apiKey, then pluginApiKey, and finally the ANTHROPIC_API_KEY environment variable.
  • Updated Testing and Examples: New unit and live tests have been added to cover the apiKey: false scenario and per-request API key overrides. A new test application demonstrates how to use this feature.

🧠 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.

Copy link
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 a valuable feature for lazily calculating the Anthropic API key at request time, which is particularly useful for multi-tenant applications. The implementation is well-structured, refactoring the client initialization logic and propagating the necessary changes throughout the plugin. The inclusion of comprehensive unit and live tests ensures the new functionality is robust. I have one suggestion to improve the readability and error messaging of the new calculateApiKey helper function, but overall, this is a solid contribution.

@cabljac cabljac marked this pull request as ready for review January 28, 2026 10:05
@cabljac
Copy link
Contributor Author

cabljac commented Jan 28, 2026

/gemini review

Copy link
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 effectively refactors the Anthropic plugin to support lazy initialization of the API key, allowing it to be provided on a per-request basis. The changes are well-structured, with clear separation of concerns and updated type definitions. The addition of comprehensive unit tests, live tests, and an example application is excellent.

I've identified one significant performance consideration related to the creation of new Anthropic client instances on every request, which I've detailed in a specific comment. Addressing this would make the implementation more robust for production environments.

Comment on lines +224 to +231
const client = testClient
? testClient
: new Anthropic({
apiKey: calculateApiKey(
pluginApiKey,
normalizedRequest.config?.apiKey
),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Creating a new Anthropic client instance for every request can lead to performance issues. Each new instance may establish a new TCP connection and perform a new TLS handshake, adding significant latency to each API call. This prevents connection reuse (HTTP keep-alive).

Consider caching Anthropic client instances based on their API key. The cache could be maintained at the plugin level and passed down to the runner. This would allow reusing clients for subsequent requests that use the same API key, improving performance by reusing existing connections.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My take is that the bottleneck would be inference, optimising here for TLS handshake is adding complexity for marginal gain. Not caching the client is a pattern in other plugins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[JS] [Antropic] should support providing api key at runtime

2 participants