Gemini ProviderInitError
Description
When I configure my GEMINI_API_KEY in bash and then run opencode, I get ProviderInitError data: { providerID: "gemini" }
Anthropic, OpenAI, Openrouter all seem to work.
The key works fine in other tools, e.g. Aider.
I am able to authenticate and use the key after I delete any opencode cache file. .
OpenCode version
1.0.35
Steps to reproduce
I have tried to have gemini setup in a global config:
"gemini": { "name": "Google Gemini (API Key)", "options": { "apiKey": "{env:GEMINI_API_KEY}", "baseURL": "https://generativelanguage.googleapis.com/v1" }, "models": { "gemini-2.5-flash": { "options": { "temperature": 0.5, "maxTokens": 8192, "stream": true } }, "gemini-2.5-pro": { "options": { "temperature": 0.5, "maxTokens": 8192 } } } },
Start up opencode from the terminal.
Change to gemini model.
ask question
error message and line numbers/code show up in terminal, but I can't copy them.
Screenshot and/or share link
No response
Operating System
OSX 15.7.1
Terminal
iTerm2
@planetmcd you shouldn't need to edit opencode.json i'd actually recommend undoing those changes.
Can you undo them, then do opencode auth login -> google -> paste key
then try?
If you have GEMINI_API_KEY exported it should just work.
@planetmcd you shouldn't need to edit
opencode.jsoni'd actually recommend undoing those changes.Can you undo them, then do
opencode auth login-> google -> paste keythen try?
If you have
GEMINI_API_KEYexported it should just work.
Thanks for the quick reply. I've seen other comments like that. I can get Gemini to work if I auth and paste in my key. So I'm not stuck in that regard. I cannot get it to work if I merely export the key as an environmental variable. It does not work whether I set it in the config file or just picking it up from the environment.
My goal here is to prevent keys being in 2 locations. If I rotate a key, I just want to rotate it in my environment and not also in opencode's meta files.
@planetmcd okay if you don't want it in auth.json, can u do:
opencode auth list and show me output?
@planetmcd okay if you don't want it in auth.json, can u do:
opencode auth listand show me output?
Of course. This is what I get:
opencode auth list
┌ Credentials ~/.local/share/opencode/auth.json
│
● Google api
│
└ 1 credentials
┌ Environment
│
● Google GEMINI_API_KEY
│
● OpenAI OPENAI_API_KEY
│
● OpenRouter OPENROUTER_API_KEY
│
● Anthropic ANTHROPIC_API_KEY
│
└ 4 environment variables```
I should have included this:
I get a wierd error message layout that I can't copy and paste. It has lines starting at 527 and the file name src/provider/provider.ts. Presumably it is this file: https://github.com/sst/opencode/blob/dev/packages/opencode/src/provider/provider.ts
This is what it looks like after I try to send a message to a Gemini model.
Hm the first thing i'd recommend is removing google from the auth.json if u wanna use the env var
Second thing is remove any google stuff from your opencode.json
In your opencode.json are u setting a "model": "...." anywhere?
Normally provider init error (which shouldn't cause this tui bug ik we need to fix) comes from an invalid model name or maybe it failed to download the google ai sdk package
I have tried it without the auth.json. I just happened to run the command you asked when it was in there.
When I completely delete my opencode.json and run opencode, it finds the other providers, but when I search for gemini, it only returns the gemini through openrouter.
On Thu, Nov 6, 2025 at 4:12 PM Aiden Cline @.***> wrote:
rekram1-node left a comment (sst/opencode#3999) https://github.com/sst/opencode/issues/3999#issuecomment-3499410910
Hm the first thing i'd recommend is removing google from the auth.json if u wanna use the env var
Second thing is remove any google stuff from your opencode.json
In your opencode.json are u setting a "model": "...." anywhere?
Normally provider init error (which shouldn't cause this tui bug ik we need to fix) comes from an invalid model name or maybe it failed to download the google ai sdk package
— Reply to this email directly, view it on GitHub https://github.com/sst/opencode/issues/3999#issuecomment-3499410910, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAP2FLITEJ7ZNJUXY4G3NT33O2VJAVCNFSM6AAAAACLLVGLWGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIOJZGQYTAOJRGA . You are receiving this because you were mentioned.Message ID: @.***>
the provider is google not gemini maybe thats the issue? also what if u login with dummy key and then replace it with env in auth.json?
https://github.com/sst/models.dev/tree/dev/providers/google
I added the provider google to my config file.
"google": {
"options": {
"apiKey": "{env:GEMINI_API_KEY}",
},
"models": {
"gemini-2.5-flash": {
"options": {
"temperature": 0.5,
"maxTokens": 8192,
"stream": true
}
},
"gemini-2.5-pro": {
"options": {
"temperature": 0.5,
"maxTokens": 8192
}
}
}
},
And it now works.
Thanks for the help.
On Thu, Nov 6, 2025 at 5:34 PM Shariq Riaz @.***> wrote:
shariqriazz left a comment (sst/opencode#3999) https://github.com/sst/opencode/issues/3999#issuecomment-3499656106
the provider is google not gemini maybe thats the issue? also what if u login with dummy key and then replace it with env in auth.json?
https://github.com/sst/models.dev/tree/dev/providers/google
— Reply to this email directly, view it on GitHub https://github.com/sst/opencode/issues/3999#issuecomment-3499656106, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAP2FJ7B3WTQLCXBYKIA4D33PEHJAVCNFSM6AAAAACLLVGLWGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTIOJZGY2TMMJQGY . You are receiving this because you were mentioned.Message ID: @.***>