Gemini CLI Provider
The ai-sdk-provider-gemini-cli community provider enables using Google's Gemini models through the @google/gemini-cli-core library. It's useful for developers who want to use their existing Gemini Code Assist subscription or API key authentication.
Version Compatibility
| Provider Version | AI SDK Version | NPM Tag | Status |
|---|---|---|---|
| 2.x | v6 | latest | Stable |
| 1.x | v5 | ai-sdk-v5 | Maintenance |
| 0.x | v4 | ai-sdk-v4 | Legacy |
# AI SDK v6 (default)npm install ai-sdk-provider-gemini-cli ai
# AI SDK v5npm install ai-sdk-provider-gemini-cli@ai-sdk-v5 ai@^5.0.0
# AI SDK v4npm install ai-sdk-provider-gemini-cli@ai-sdk-v4 ai@^4.0.0Setup
pnpm add ai-sdk-provider-gemini-cli
Provider Instance
Import createGeminiProvider and create a provider instance with your authentication settings:
import { createGeminiProvider } from 'ai-sdk-provider-gemini-cli';
// OAuth authentication (default if authType omitted)const gemini = createGeminiProvider({ authType: 'oauth-personal' });
// API key authenticationconst gemini = createGeminiProvider({ authType: 'api-key', // or 'gemini-api-key' apiKey: process.env.GEMINI_API_KEY,});
// Vertex AI authenticationconst gemini = createGeminiProvider({ authType: 'vertex-ai', vertexAI: { projectId: 'my-project', location: 'us-central1', },});
// Google Auth Libraryconst gemini = createGeminiProvider({ authType: 'google-auth-library', googleAuth: myGoogleAuthInstance,});Authentication options:
- authType 'oauth' | 'oauth-personal' | 'api-key' | 'gemini-api-key' | 'vertex-ai' | 'google-auth-library' - Optional. Defaults to
'oauth-personal'. - apiKey string - Required for
'api-key'/'gemini-api-key'. - vertexAI { projectId, location } - Required for
'vertex-ai'. - googleAuth GoogleAuth - Required for
'google-auth-library'. - cacheDir string - Optional directory for OAuth credentials cache.
- proxy string - HTTP/HTTPS proxy URL.
Language Models
Create models that call Gemini through the CLI using the provider instance:
const model = gemini('gemini-2.5-pro');Supported models:
- gemini-3-pro-preview: Latest model with enhanced reasoning (supports
thinkingLevel) - gemini-3-flash-preview: Fast Gemini 3 model (supports
thinkingLevel) - gemini-2.5-pro: Production-ready model with 64K output tokens (supports
thinkingBudget) - gemini-2.5-flash: Fast, efficient model with 64K output tokens (supports
thinkingBudget)
Example
import { createGeminiProvider } from 'ai-sdk-provider-gemini-cli';import { generateText } from 'ai';
const gemini = createGeminiProvider({ authType: 'oauth-personal',});
const { text } = await generateText({ model: gemini('gemini-2.5-pro'), prompt: 'Write a vegetarian lasagna recipe for 4 people.',});Model Settings
const model = gemini('gemini-3-pro-preview', { temperature: 0.7, topP: 0.95, topK: 40, maxOutputTokens: 8192, thinkingConfig: { thinkingLevel: 'medium', // 'low' | 'medium' | 'high' | 'minimal' }, verbose: true, // Enable debug logging logger: customLogger, // Custom logger (or false to disable)});Model Capabilities
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming |
|---|---|---|---|---|
gemini-3-pro-preview | ||||
gemini-3-flash-preview | ||||
gemini-2.5-pro | ||||
gemini-2.5-flash |
Images must be provided as base64-encoded data. Image URLs are not supported.
Authentication
OAuth Authentication (Recommended)
Install and authenticate the Gemini CLI globally:
npm install -g @google/gemini-cligemini # Follow the interactive authentication setupThen use OAuth authentication in your code with authType: 'oauth-personal'.
API Key Authentication
- Generate an API key from Google AI Studio.
- Set it as an environment variable:
export GEMINI_API_KEY="YOUR_API_KEY" - Use
authType: 'api-key'with your key.
Requirements
- Node.js 20 or higher
- Gemini CLI installed globally for OAuth authentication
- Valid Google account or Gemini API key
For more details, see the provider documentation.