feat: add native Gemini provider for Google AI models

Adds Google Gemini as a first-class provider using Gemini's OpenAI-compatible
endpoint, supporting gemini-2.0-flash, gemini-2.5-pro, and gemini-2.0-flash-lite
across all three model tiers (opus/sonnet/haiku).

- Add 'gemini' to APIProvider type with CLAUDE_CODE_USE_GEMINI env detection
- Map all 11 model configs to appropriate Gemini models per tier
- Route Gemini through existing OpenAI shim (generativelanguage.googleapis.com)
- Support GEMINI_API_KEY and GOOGLE_API_KEY for authentication
- Fix model display name to show actual Gemini model instead of Claude fallback
- Add Gemini support to provider-launch, provider-bootstrap, system-check scripts
- Add dev:gemini npm script for local development

Bootstrap: bun run profile:init -- --provider gemini --api-key <key>
Launch: bun run dev:gemini

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gnanam1990
2026-04-01 14:46:04 +05:30
parent 6b6407018d
commit a3d8ab0fec
8 changed files with 185 additions and 31 deletions

View File

@@ -6,7 +6,7 @@ import {
resolveCodexApiCredentials,
} from '../src/services/api/providerConfig.js'
type ProviderProfile = 'openai' | 'ollama' | 'codex'
type ProviderProfile = 'openai' | 'ollama' | 'codex' | 'gemini'
type ProfileFile = {
profile: ProviderProfile
@@ -15,6 +15,9 @@ type ProfileFile = {
OPENAI_MODEL?: string
OPENAI_API_KEY?: string
CODEX_API_KEY?: string
GEMINI_API_KEY?: string
GEMINI_MODEL?: string
GEMINI_BASE_URL?: string
}
createdAt: string
}
@@ -28,7 +31,7 @@ function parseArg(name: string): string | null {
function parseProviderArg(): ProviderProfile | 'auto' {
const p = parseArg('--provider')?.toLowerCase()
if (p === 'openai' || p === 'ollama' || p === 'codex') return p
if (p === 'openai' || p === 'ollama' || p === 'codex' || p === 'gemini') return p
return 'auto'
}
@@ -69,7 +72,18 @@ async function main(): Promise<void> {
}
const env: ProfileFile['env'] = {}
if (selected === 'ollama') {
if (selected === 'gemini') {
env.GEMINI_MODEL = argModel || process.env.GEMINI_MODEL || 'gemini-2.0-flash'
const key = sanitizeApiKey(argApiKey || process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY || null)
if (!key) {
console.error('Gemini profile requires an API key. Use --api-key or set GEMINI_API_KEY.')
console.error('Get a free key at: https://aistudio.google.com/apikey')
process.exit(1)
}
env.GEMINI_API_KEY = key
if (argBaseUrl) env.GEMINI_BASE_URL = argBaseUrl
} else if (selected === 'ollama') {
env.OPENAI_BASE_URL = argBaseUrl || 'http://localhost:11434/v1'
env.OPENAI_MODEL = argModel || process.env.OPENAI_MODEL || 'llama3.1:8b'
const key = sanitizeApiKey(argApiKey || process.env.OPENAI_API_KEY || null)