fix: correct authType for Gemini CLI API key authentication#926
fix: correct authType for Gemini CLI API key authentication#926tommy-ca wants to merge 2 commits intoeyaltoledano:nextfrom
Conversation
Resolves the "Failed to initialize Gemini model: Error: Error creating contentGenerator: Unsupported authType: undefined" error. ## Root Cause The ai-sdk-provider-gemini-cli package's initializeGeminiClient function only recognizes these authType values: - 'gemini-api-key' → maps to AuthType.USE_GEMINI - 'oauth-personal' → maps to AuthType.LOGIN_WITH_GOOGLE_PERSONAL - 'vertex-ai' → maps to AuthType.USE_VERTEX_AI Our implementation was using 'api-key' which didn't match any condition, causing authType to become undefined and triggering the error. ## Solution Changed authType from 'api-key' to 'gemini-api-key' for API key authentication to match the SDK's expected values. ## Files Changed - src/ai-providers/gemini-cli.js: Updated authType value - tests/unit/ai-providers/gemini-cli.test.js: Updated test expectations ## Testing All 46 Gemini CLI provider tests pass, confirming the fix resolves the authentication error while maintaining full functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull Request Overview
Addresses an authentication mismatch for the Gemini CLI provider by aligning the authType string with the underlying SDK’s expectations.
- Changes
authTypefrom'api-key'to'gemini-api-key'in provider code and all related tests.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/ai-providers/gemini-cli.js | Updated the authType literal to gemini-api-key |
| tests/unit/ai-providers/gemini-cli.test.js | Updated expected authType values and test names |
src/ai-providers/gemini-cli.js
Outdated
| // API key provided - use it for compatibility | ||
| authOptions = { | ||
| authType: 'api-key', | ||
| authType: 'gemini-api-key', |
There was a problem hiding this comment.
[nitpick] Consider extracting the 'gemini-api-key' string into a shared constant (e.g. GEMINI_AUTH_TYPE_API_KEY) to reduce duplication and prevent typos in both code and tests.
Addresses PR review feedback by replacing magic strings with named constants for better maintainability. ## Changes - Added GEMINI_AUTH_TYPES constant with API_KEY and OAUTH_PERSONAL values - Updated implementation to use constants instead of hardcoded strings - Updated all tests to import and use the constants - Exported constants for reuse in tests and other modules ## Benefits - Reduces risk of typos when referencing auth types - Makes code more maintainable when auth type values need to change - Improves readability and self-documentation - Follows DRY principle by centralizing auth type definitions ## Testing All 46 Gemini CLI provider tests pass, confirming the refactoring maintains full functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
|
Good catch, I honestly didn’t have/test a Google API Key - fix seems reasonable. I’m curious, what is the use case for using Gemini CLI with API Key through task master, instead of just using the Google provider directly? It would seem to me that if paying for use with API Key, Google APIs direct would be preferred to Gemini CLI? Doesn’t mean it shouldn’t work, that’s why I included support for it… but just curious why one would use API Key through Gemini CLI in Task Master instead of direct to Google APIs. Maybe I’m missing an interesting use case? |
|
@jaruesink nice catch - It looks like Google merged a PR after this PR had been written/tested/merged into the ‘next’ branch. They introduced a breaking change in google-cli with this commit: ● Bash(git show 3587054d32372874a4e067ae050f861ad1cec2b4 --stat) ● Yes! The AuthType enum did change recently. Here's what happened: On June 30, 2025 (commit 3587054d), there was a breaking change that renamed:
The commit message was: "Rename AuthType LOGIN_WITH_GOOGLE_PERSONAL -> LOGIN_WITH_GOOGLE (#2769)" This change affected 13 files across the codebase. The enum value itself ('oauth-personal') remained the same, but the enum key changed from LOGIN_WITH_GOOGLE_PERSONAL to LOGIN_WITH_GOOGLE. This explains why your library is using LOGIN_WITH_GOOGLE_PERSONAL - it was the correct enum value until just a fewdays ago. The change appears to be part of a broader effort to simplify the authentication options, as there was also an |
|
@tommy-ca and @jaruesink - I've made updates to |
|
@ben-vargas since we merged your PR, is this PR still relevant ? I'm struggling to understand what this PR truly does other than a simple enum refactor |
This PR can be closed - @tommy-ca and @jaruesink found valid issues and helped a lot on root cause to prompt toward a fix. One issue caused by Google's breaking change on OAuth and one caused by the ai-sdk provider implementation expecting gemini-cli's "gemini-api-key" but task-master using "api-key" (ai-sdk standard). I thought it better ai-sdk-provider-gemini-cli handle both "api-key" or "gemini-api-key" auth options interchangeably for API Key to deliver to standards AI-SDK uses but also provide backwards compatibility for apps opting to use "gemini-api-key" since that's what gemini-cli uses. |
|
Great stuff, thanks for the feedback @ben-vargas |

Summary
Root Cause
The ai-sdk-provider-gemini-cli package's initializeGeminiClient function only recognizes these authType values:
Our implementation was using 'api-key' which didn't match any condition, causing authType to become undefined and triggering the error.
Test plan
🤖 Generated with Claude Code