Skip to content

fix confusing 400 when GEMINI_API_KEY isn't set (closes #202) - #206

Merged
jspada200 merged 2 commits into
AcademySoftwareFoundation:mainfrom
lukalul:fix-gemini-missing-api-key-error
Sep 29, 2026
Merged

jspada200 merged 2 commits into
AcademySoftwareFoundation:mainfrom
lukalul:fix-gemini-missing-api-key-error

Conversation

@lukalul

@lukalul lukalul commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

GeminiProvider just passed self.api_key straight to AsyncOpenAI without checking it was actually set. if GEMINI_API_KEY is missing, AsyncOpenAI quietly falls back to looking for OPENAI_API_KEY instead, so you get an error mentioning OpenAI even though you're trying to set up Gemini. that's almost certainly what happened in #202, no repro steps but "400 error when using gemini" lines up exactly with this.

repro'd it locally: with no key set at all, the error you get back is "The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable" - useless if you did set GEMINI_API_KEY and it just didn't make it into the container's env.

CustomProvider already has a workaround for this same openai-sdk quirk (falls back to a dummy key since ollama doesn't need one). did the same idea here but raise a clear GEMINI_API_KEY-specific error instead, since gemini's api actually requires a real key unlike local/custom providers.

added a test for the missing-key case.

closes #202

…reFoundation#202)

GeminiProvider just passed self.api_key straight to AsyncOpenAI without checking it was actually set. if GEMINI_API_KEY is missing, AsyncOpenAI quietly falls back to looking for OPENAI_API_KEY instead, so you get an error mentioning OpenAI even though you're trying to set up Gemini. that's almost certainly what happened in AcademySoftwareFoundation#202, no repro steps but "400 error when using gemini" lines up exactly with this.

repro'd it locally: with no key set at all, the error you get back is "The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable" - which is useless if you set GEMINI_API_KEY and it just didn't make it into the container's env.

CustomProvider already has a workaround for this same openai-sdk quirk (falls back to a dummy key since ollama doesn't need one). did the same idea here but raise a clear GEMINI_API_KEY-specific error instead, since gemini's api actually requires a real key unlike local/custom providers.

added a test for the missing-key case.

Signed-off-by: luka <158089407+lukalul@users.noreply.github.com>
@lukalul
lukalul force-pushed the fix-gemini-missing-api-key-error branch from 232ca2d to 6291731 Compare September 22, 2026 21:38
@jspada200 jspada200 added devdays2026 devdays26 bug Something isn't working Backend Work Associated with the backend labels Sep 29, 2026
@jspada200
jspada200 merged commit ce0b2ba into AcademySoftwareFoundation:main Sep 29, 2026
4 checks passed
@jspada200

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend Work Associated with the backend bug Something isn't working devdays26 devdays2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

400 error when using Gemini

2 participants