AI SDK Provider for Gemini CLI
raw JSON →The 'ai-sdk-provider-gemini-cli' package serves as a community-developed provider for the Vercel AI SDK, enabling seamless integration with Google's Gemini large language models. Unlike direct API clients, this provider leverages the official Google Gemini CLI/SDK, specifically the '@google/gemini-cli-core' package, and utilizes Google Cloud Code endpoints. The current stable version is 2.0.1, offering full compatibility with AI SDK v6. This project maintains an active release cadence, frequently updating to support new Gemini models and AI SDK features. Key differentiators include its reliance on the robust Gemini CLI for authentication and model access, support for multimodal inputs (text, images, PDFs, audio, video), advanced tool/function calling, and native structured output with Zod schemas. It also provides specific configuration options like 'thinkingConfig' for fine-tuning reasoning levels in Gemini 3 models, and a flexible logging system. To use, developers must first globally install and authenticate the '@google/gemini-cli'.
Common errors
error Error: Command failed: gemini generate --help gemini: command not found ↓
npm install -g @google/gemini-cli to install the Gemini CLI globally. Ensure your npm global bin directory is in your system's PATH. error Error: Request failed with status code 401: You must be logged in to use this command. Run 'gemini' for interactive setup. ↓
gemini in your terminal and follow the interactive prompts to authenticate your Google account via OAuth. error TypeError: (0, _ai_sdk__WEBPACK_IMPORTED_MODULE_0__.generateText) is not a function ↓
package.json includes "type": "module" for ESM support. Use import { generateText } from 'ai'; and other ESM import syntax. If using older AI SDK versions, verify your bundler configuration. error Error: The model 'gemini-1.5-flash-latest' does not support structured output with 'responseJsonSchema'. ↓
responseJsonSchema, such as gemini-3-pro-preview. Ensure your ai-sdk-provider-gemini-cli version is >=1.4.0 for native structured output support. error Error: Your Node.js version (18.x.x) is not supported. This package requires Node.js >= 20. ↓
nvm (e.g., nvm install 20 && nvm use 20). Warnings
breaking Version 2.0.0 introduced significant breaking changes to align with Vercel AI SDK v6. This includes changes to the provider interface (`ProviderV2` → `ProviderV3`), token usage reporting (flat → hierarchical), warning format (`unsupported-setting` → `unsupported`), method renames (`textEmbeddingModel()` → `embeddingModel()`), and the finish reason structure (string → `{ unified, raw }` object). ↓
breaking A Node.js version of `>=20` is required since `ai-sdk-provider-gemini-cli` v1.3.0 and `gemini-cli-core` v0.16.0. Earlier Node.js versions will lead to runtime errors. ↓
gotcha This provider requires the `@google/gemini-cli` to be installed globally and authenticated separately before it can function. Without this setup, the provider cannot access Gemini models. ↓
gotcha Different major versions of `ai-sdk-provider-gemini-cli` are tied to specific major versions of the Vercel AI SDK. Version 2.x supports AI SDK v6 (NPM tag `latest`), version 1.x supports AI SDK v5 (NPM tag `ai-sdk-v5`), and version 0.x supports AI SDK v4 (NPM tag `ai-sdk-v4`). ↓
gotcha Prior to v2.0.1, when defining function tool parameter schemas, if only `properties` were provided, the `type: "object"` was not implicitly added, leading to Gemini function declaration validation errors. ↓
Install
npm install ai-sdk-provider-gemini-cli yarn add ai-sdk-provider-gemini-cli pnpm add ai-sdk-provider-gemini-cli Imports
- createGeminiProvider wrong
const createGeminiProvider = require('ai-sdk-provider-gemini-cli').createGeminiProvider;correctimport { createGeminiProvider } from 'ai-sdk-provider-gemini-cli'; - generateText wrong
const { generateText } = require('ai');correctimport { generateText } from 'ai'; - ThinkingLevel
import { ThinkingLevel } from 'ai-sdk-provider-gemini-cli';
Quickstart
import { generateText } from 'ai';
import { createGeminiProvider } from 'ai-sdk-provider-gemini-cli';
async function main() {
// Ensure @google/gemini-cli is installed globally and authenticated
// npm install -g @google/gemini-cli
// gemini (then follow interactive setup)
const gemini = createGeminiProvider({
authType: 'oauth-personal', // Uses credentials from ~/.gemini/oauth_creds.json
// apiKey: process.env.GEMINI_API_KEY ?? '', // Alternative API key auth
});
try {
const result = await generateText({
model: gemini('gemini-3-pro-preview', {
temperature: 0.7,
maxOutputTokens: 50,
}),
prompt: 'Write a haiku about a majestic cat watching the sunrise.',
});
console.log('Generated Haiku:\n', result.text);
} catch (error) {
console.error('Error generating text:', error);
}
}
main();