API Reference

@chai-ai/google

Google Gemini model provider adapter for Chai AI SDK.

The @chai-ai/google package provides the adapter layer for connecting Chai AI agents to Google's Gemini models using the official @google/genai client.


Installation

Ensure you have installed the Google provider package alongside chai-ai:

npm install @chai-ai/google

Authentication

The provider automatically reads the Google API Key from the environment:

export GOOGLE_GENERATIVE_AI_API_KEY="your-gemini-api-key"

API Reference

google(modelId)

Creates a LanguageModel descriptor for a Gemini model.

  • Parameters:
    • modelId: string — The identifier of the Gemini model (e.g., "gemini-3.1-pro-preview", "gemini-2.5-flash").
  • Returns: LanguageModel interface instance.
import { Agent } from "chai-ai";
import { google } from "@chai-ai/google";

const model = google("gemini-3.1-pro-preview");

const agent = new Agent({
  name: "google-agent",
  instructions: "You are a Google Gemini-powered agent.",
  model,
});

Features & Implementation Details

  • System Instructions: Google Gemini models require system instructions to be passed in a separate systemInstruction field in the request config. The adapter automatically extracts system messages from the history and puts them in this field.
  • Client-Side Cancellation: The adapter supports passing an AbortSignal through AbortSignal config mapping, allowing active HTTP connection termination on model timeout events.
  • Token Usage Mapping: Automatically translates promptTokenCount, candidatesTokenCount, and totalTokenCount from Gemini response metadata into Chai AI's standard TokenUsage format.

On this page