AI SDK Provider for Gemini CLI

2.0.1 · active · verified Wed Apr 22

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

Warnings

Install

Imports

Quickstart

Demonstrates basic text generation using the Gemini provider with OAuth authentication and a specific Gemini 3 model, printing a haiku.

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();

view raw JSON →