[PR #342] [CLOSED] feat(providers): use env variable instead of hardcoded api key in auth.json #9593

Closed
opened 2026-02-16 18:13:49 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opencode/pull/342
Author: @GitMurf
Created: 6/23/2025
Status: Closed

Base: devHead: allow-env-auth


📝 Commits (1)

  • bab7bad feat(gemini): use env variable instead of hardcoded api key

📊 Changes

2 files changed (+12 additions, -1 deletions)

View changed files

📝 packages/opencode/src/auth/index.ts (+6 -1)
📝 packages/opencode/src/provider/provider.ts (+6 -0)

📄 Description

I am doing this specifically for Gemini (Google), but this should work with any provider.

This is NOT available in the UI of opencode auth login because I am not sure what the UX there should be like, so instead you can just "manually" update your opencode auth.json to something like the following:

{
  "google": {
    "type": "env",
    "env": "GEMINI_API_KEY"
  }
}

This allows you to have opencode leverage an environment variable for an API Key instead of having to "hardcode" it into the opencode auth.json.

This should somewhat resolve #318


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opencode/pull/342 **Author:** [@GitMurf](https://github.com/GitMurf) **Created:** 6/23/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `allow-env-auth` --- ### 📝 Commits (1) - [`bab7bad`](https://github.com/anomalyco/opencode/commit/bab7bad80c0f6e7af6354b2a0dcbc31ea18d8aa3) feat(gemini): use env variable instead of hardcoded api key ### 📊 Changes **2 files changed** (+12 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/opencode/src/auth/index.ts` (+6 -1) 📝 `packages/opencode/src/provider/provider.ts` (+6 -0) </details> ### 📄 Description I am doing this specifically for Gemini (Google), but this should work with any provider. This is NOT available in the UI of `opencode auth login` because I am not sure what the UX there should be like, so instead you can just "manually" update your opencode `auth.json` to something like the following: ```json { "google": { "type": "env", "env": "GEMINI_API_KEY" } } ``` This allows you to have opencode leverage an environment variable for an API Key instead of having to "hardcode" it into the opencode `auth.json`. This should somewhat resolve #318 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 18:13:49 -05:00
yindo closed this issue 2026-02-16 18:13:49 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9593