Skip to content

Conversation

@daniel-lxs
Copy link
Contributor

🧪 Evaluation PR for Testing

This is an automated test PR created for evaluation purposes.


Related GitHub Issue

Closes: #4337

Description

This PR adds support for obtaining API keys from the environment. A checkbox is added to each configuration that allows inputting an API key -- when checked, a given environment variable (eg, OPENAI_API_KEY, etc) is consulted for the key and the user is not required to provide one in the configuration. Env Var key is predictable but not editable.

Test Procedure

I tested this using VS Code run configurations, where the expected environment variable could be provided or omitted.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).

A documentation update is advised, to describe environment variable usage to supply API keys.

Summary

Adds support for using environment variables for API keys across multiple providers, updates UI components to reflect this, and enhances testing and translation capabilities.

  • Behavior:
    • Adds support for API keys from environment variables for providers like anthropic, glama, openrouter, openai, gemini, mistral, deepseek, unbound, requesty, xai, groq, chutes, litellm.
    • Updates validateModelsAndKeysProvided() to check for environment variable usage for API keys.
  • UI Components:
    • Introduces ApiKey component to handle API key input and environment variable toggle.
    • Updates various provider components to use the new ApiKey component.
  • Testing:
    • Adds comprehensive tests for environment variable integration and the ApiKey component.

suprjinx added 30 commits May 27, 2025 16:44
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
OPENAI_API_KEY env var

Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
whole process.env into webview

Signed-off-by: Geoff Wilson <[email protected]>
of api key env var; use constants for env var keys.

Signed-off-by: Geoff Wilson <[email protected]>
errant keys in test file

Signed-off-by: Geoff Wilson <[email protected]>
suprjinx and others added 24 commits August 13, 2025 10:38
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
Copy link

@roo-code-dan roo-code-dan bot left a comment

Choose a reason for hiding this comment

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

Reviewing this PR for API key environment variable support

FIREWORKS: 'FIREWORKS_API_KEY',
HUGGING_FACE: 'HUGGINGFACE_API_KEY',
IO_INTELLIGENCE: 'IOINTELLIGENCE_API_KEY',
MOONSHOOT: 'MOONSHOT_API_KEY',
Copy link

Choose a reason for hiding this comment

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

Typo in constant name

The constant name has a typo that will cause runtime errors when used.

Suggested change
MOONSHOOT: 'MOONSHOT_API_KEY',
MOONSHOOT: 'MOONSHOT_API_KEY',
MOONSHOT: 'MOONSHOT_API_KEY',


switch (apiProvider) {
case "anthropic":
if (options.anthropicConfigUseEnvVars) {
Copy link

Choose a reason for hiding this comment

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

Config mutation in buildApiHandler

The buildApiHandler function mutates the options object which is derived from destructuring the input configuration. While this works due to JavaScript's object spreading behavior, it's a code smell that could lead to unexpected behavior if the implementation changes.

Consider creating a helper function that returns the modified value instead of mutating:

const getApiKeyOrEnvVar = (envKey: string, configValue?: string, useEnvVar?: boolean) => 
    useEnvVar ? getEnvVar(envKey, configValue) : configValue

Then use it like:

case "anthropic":
    return new AnthropicHandler({
        ...options,
        apiKey: getApiKeyOrEnvVar(API_KEYS.ANTHROPIC, options.apiKey, options.anthropicConfigUseEnvVars)
    })

@DanCodeInc DanCodeInc deleted a comment from roo-code-dan bot Oct 10, 2025
@daniel-lxs daniel-lxs closed this Oct 10, 2025
@daniel-lxs daniel-lxs deleted the eval-pr-review-feat-add-api-key-env-vars-1760129927164 branch October 10, 2025 21:28
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.

3 participants