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/googleAuthentication
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:
LanguageModelinterface 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
systemInstructionfield 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
AbortSignalthroughAbortSignalconfig mapping, allowing active HTTP connection termination on model timeout events. - Token Usage Mapping: Automatically translates
promptTokenCount,candidatesTokenCount, andtotalTokenCountfrom Gemini response metadata into Chai AI's standardTokenUsageformat.