opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(providers): use env variable instead of hardcoded api key in auth.json

Open GitMurf opened this issue 6 months ago • 3 comments

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

GitMurf avatar Jun 23 '25 18:06 GitMurf

interesting but we actually have a few places in the config where people want to specify env vars. so we might just implement it at that layer

thdxr avatar Jun 23 '25 19:06 thdxr

interesting but we actually have a few places in the config where people want to specify env vars. so we might just implement it at that layer

cool, sounds good! I figured this was fairly temporary / "hacky" but figured I would push some code that worked to give you more ideas. Would you like me to cancel / close this PR @thdxr? or do you want me to keep it open as a "reminder"?

GitMurf avatar Jun 23 '25 19:06 GitMurf

interesting but we actually have a few places in the config where people want to specify env vars...

Btw, for the record, solving it in the config.json I agree with... this was just the shortest path to implementation so thought I would throw it out there.

GitMurf avatar Jun 23 '25 19:06 GitMurf