-
-
Notifications
You must be signed in to change notification settings - Fork 925
fix(auth): use backend project ID for free tier Gemini CLI OAuth users #861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(auth): use backend project ID for free tier Gemini CLI OAuth users #861
Conversation
Fixes issue where free tier users cannot access Gemini 3 preview models due to frontend/backend project ID mapping. ## Problem Google's Gemini API uses a frontend/backend project mapping system for free tier users: - Frontend projects (e.g., gen-lang-client-*) are user-visible - Backend projects (e.g., mystical-victor-*) host actual API access - Only backend projects have access to preview models (gemini-3-*) Previously, CLIProxyAPI ignored the backend project ID returned by Google's onboarding API and kept using the frontend ID, preventing access to preview models. ## Solution ### CLI (internal/cmd/login.go) - Detect free tier users (gen-lang-client-* projects or FREE/LEGACY tier) - Show interactive prompt allowing users to choose frontend or backend - Default to backend (recommended for preview model access) - Pro users: maintain original behavior (keep frontend ID) ### Web UI (internal/api/handlers/management/auth_files.go) - Detect free tier users using same logic - Automatically use backend project ID (recommended choice) - Pro users: maintain original behavior (keep frontend ID) ### Deduplication (internal/cmd/login.go) - Add deduplication when user selects ALL projects - Prevents redundant API calls when multiple frontend projects map to same backend - Skips duplicate project IDs in activation loop ## Impact - Free tier users: Can now access gemini-3-pro-preview and gemini-3-flash-preview models - Pro users: No change in behavior (backward compatible) - Only affects Gemini CLI OAuth (not antigravity or API key auth) ## Testing - Tested with free tier account selecting single project - Tested with free tier account selecting ALL projects - Verified deduplication prevents redundant onboarding calls - Confirmed pro user behavior unchanged
Summary of ChangesHello @umairimtiaz9, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves an issue preventing free tier Gemini CLI users from accessing preview models by ensuring the correct backend project ID is used during authentication. It introduces logic to detect free tier users and either prompts them (for CLI) or automatically selects (for Web UI) the backend project ID, which is essential for preview model access. Additionally, a deduplication step is added to optimize project activation. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly addresses an issue for free-tier Gemini users by ensuring the backend project ID is used, which enables access to preview models. The changes are well-contained, with separate logic for the CLI (interactive prompt) and the Web UI (automatic selection). The addition of project ID deduplication is also a good improvement.
My review includes a critical fix for error handling in the new interactive prompt, and a couple of suggestions to improve maintainability by reducing code duplication and refactoring the newly added UI logic into a separate function. Overall, this is a solid contribution that improves the user experience for a specific user group while maintaining backward compatibility.
| choice, _ := reader.ReadString('\n') | ||
| choice = strings.TrimSpace(choice) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error returned by reader.ReadString('\n') is ignored. If an I/O error occurs (e.g., os.Stdin is closed or redirected from an empty file), choice will be empty, and the code will silently default to using the recommended backend project ID. While this fallback is reasonable, ignoring errors is poor practice as it can hide underlying issues. The error should be checked and handled, for instance by logging a warning before proceeding with the default. It's also good practice to handle io.EOF gracefully, which can occur if the user signals end-of-input.
choice, err := reader.ReadString('\n')
if err != nil && err != io.EOF {
log.Warnf("Failed to read user input, defaulting to backend project ID: %v", err)
}
choice = strings.TrimSpace(choice)| isFreeUser := strings.HasPrefix(projectID, "gen-lang-client-") || | ||
| strings.EqualFold(tierID, "FREE") || | ||
| strings.EqualFold(tierID, "LEGACY") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic to determine if a user is on a free tier is duplicated here and also in internal/api/handlers/management/auth_files.go (lines 2106-2108). To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, this logic should be extracted into a shared helper function.
For example, you could create a function in a shared package like internal/auth/gemini:
// IsFreeTierUser checks if the user is on a free tier based on project and tier IDs.
func IsFreeTierUser(projectID, tierID string) bool {
return strings.HasPrefix(projectID, "gen-lang-client-") ||
strings.EqualFold(tierID, "FREE") ||
strings.EqualFold(tierID, "LEGACY")
}This would make the code cleaner and easier to update in the future.
| if isFreeUser { | ||
| // Interactive prompt for free users | ||
| fmt.Printf("\n⚠️ Google returned a different project ID:\n") | ||
| fmt.Printf(" Requested (frontend): %s\n", projectID) | ||
| fmt.Printf(" Returned (backend): %s\n\n", responseProjectID) | ||
| fmt.Printf("ℹ️ Backend project IDs have access to preview models (gemini-3-*).\n") | ||
| fmt.Printf(" This is normal for free tier users.\n\n") | ||
| fmt.Printf("Which project ID would you like to use?\n") | ||
| fmt.Printf(" [1] Backend (recommended): %s\n", responseProjectID) | ||
| fmt.Printf(" [2] Frontend: %s\n\n", projectID) | ||
| fmt.Printf("Enter choice [1]: ") | ||
|
|
||
| reader := bufio.NewReader(os.Stdin) | ||
| choice, _ := reader.ReadString('\n') | ||
| choice = strings.TrimSpace(choice) | ||
|
|
||
| if choice == "2" { | ||
| log.Infof("Using frontend project ID: %s", projectID) | ||
| fmt.Println("⚠️ Warning: Frontend project IDs may not have access to preview models.") | ||
| finalProjectID = projectID | ||
| } else { | ||
| log.Infof("Using backend project ID: %s (recommended)", responseProjectID) | ||
| finalProjectID = responseProjectID | ||
| } | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The performGeminiCLISetup function has expanded to include the interactive user prompt for project ID selection. To improve readability and separation of concerns, consider extracting this UI-related logic into a new, dedicated function. For example, a function like promptForProjectIDChoice(projectID, responseProjectID string) string could encapsulate the interaction and return the selected project ID. This would make performGeminiCLISetup more focused on the core onboarding flow and easier to test and maintain.
Cherry-picked from upstream PR router-for-me#861
|
On the main branch gemini-cli oauth seems to be broken. I can login with my account in gemini-cli (pro user) but CLIPRoxyAPI auth fails with a project related error stating onboarding failed as it is unable to identify a project id. Does this pr address this isssue in any way? I might merge it locally |
|
yeah that might be due to google changing something on their end, this PR only provides better UX specifcally for free users. also I'll try to submit a PR for automatically creating a project and getting its projectid if no project is available. |
Problem
Google's Gemini API uses a frontend/backend project mapping system for free tier users:
gen-lang-client-*) are user-visiblemystical-victor-*) host actual API accessgemini-3-*)Previously, CLIProxyAPI ignored the backend project ID returned by Google's onboarding API and kept using the frontend ID, preventing access to preview models.
Solution
CLI (
internal/cmd/login.go)gen-lang-client-*projects orFREE/LEGACYtier)Web UI (
internal/api/handlers/management/auth_files.go)Deduplication (
internal/cmd/login.go)Impact
gemini-3-pro-previewandgemini-3-flash-previewmodelsTesting
Files Changed
internal/cmd/login.go: +44 lines (interactive prompt + deduplication)internal/api/handlers/management/auth_files.go: +15 lines (auto-backend for free users)