Skip to content

API key from Env Var support #6178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

suprjinx
Copy link

@suprjinx suprjinx commented Jul 24, 2025

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, OPEN_AI_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.

Additionally, added an option to generate placeholder translation keys in supported locale files. Was useful in an earlier iteration but not used now (no new translations).

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.

Screenshots / Videos

Documentation Updates

Additional Notes

Get in Touch


Important

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 in provider-settings.ts.
    • Updates validateModelsAndKeysProvided() in validate.ts to check for environment variable usage for API keys.
  • UI Components:
    • Introduces ApiKey component in ApiKey.tsx to handle API key input and environment variable toggle.
    • Updates various provider components like Anthropic.tsx, Chutes.tsx, DeepSeek.tsx, etc., to use the new ApiKey component.
  • Testing:
    • Adds tests for environment variable integration in index.spec.ts and ApiKey.spec.tsx.
  • Misc:
    • Adds --create-missing option in find-missing-translations.js for generating placeholder translation keys.

This description was created by Ellipsis for f154eb2. You can customize this summary. It will automatically update as commits are pushed.

suprjinx added 6 commits May 27, 2025 16:44
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
…ssage

Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 24, 2025
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
suprjinx added 11 commits July 24, 2025 14:17
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
…viders

Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
@suprjinx suprjinx marked this pull request as ready for review July 25, 2025 18:01
@suprjinx suprjinx requested review from mrubens, cte and jr as code owners July 25, 2025 18:01
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. documentation Improvements or additions to documentation labels Jul 25, 2025
@dosubot dosubot bot added the enhancement New feature or request label Jul 25, 2025
setApiKeyUseEnvVar={(value: boolean) => setApiConfigurationField("openAiNativeApiKeyUseEnvVar", value)}
apiKeyLabel={t("settings:providers.openAiNativeApiKey")}
getApiKeyUrl="https://platform.openai.com/api-keys"
getApiKeyLabel={t("settings:providers.getopenAiNativeApiKey")}
Copy link

Choose a reason for hiding this comment

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

Typographical error: The translation key "settings:providers.getopenAiNativeApiKey" appears to have a lower-case 'o'. Should it be "settings:providers.getOpenAiNativeApiKey" to maintain consistency with other key naming?

Suggested change
getApiKeyLabel={t("settings:providers.getopenAiNativeApiKey")}
getApiKeyLabel={t("settings:providers.getOpenAiNativeApiKey")}

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

suprjinx added 2 commits July 25, 2025 14:07
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
Signed-off-by: Geoff Wilson <geoff@gr-oss.io>
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 25, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request PR - Needs Preliminary Review size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
Status: PR [Needs Prelim Review]
Development

Successfully merging this pull request may close these issues.

Obtain API keys from environment in addition to UI form
2 participants