zidane/ providers/ google
The Google Gemini providers, on the Gemini API with an API key or on Vertex AI with Google Cloud credentials.
import { … } from 'zidane/providers/google'src/providers/google.ts
Use google() for the Gemini API (Google AI Studio). With no key passed, it reads GEMINI_API_KEY, then GOOGLE_API_KEY. Use googleVertex() for Vertex AI. It uses a Vertex API key (GOOGLE_CLOUD_API_KEY) when one is set. Otherwise it uses Google Cloud credentials (GOOGLE_APPLICATION_CREDENTIALS, or the gcloud Application Default Credentials) for GOOGLE_CLOUD_PROJECT in GOOGLE_CLOUD_LOCATION, which defaults to global. Both providers keep the Gemini thought signatures in the session and send them back to the route that issued them. Gemini 3 needs them for multi-step tool use. Without an API key, Vertex AI also takes a service-account key or the metadata server on Google Cloud. Files such as PDFs go to the model as file parts. googleCompatible() runs the same plumbing over another Gemini-wire backend, such as an extension's transport: the route sends the request zidane builds and returns the SSE response.
import { createAgent } from 'zidane'
import { google, googleVertex } from 'zidane/providers/google'
const agent = createAgent({ provider: google({ defaultModel: 'gemini-3.8-flash' }) })
await agent.run({ prompt: 'Summarize README.md in three bullets.' })
const vertex = createAgent({ provider: googleVertex({ project: 'my-project', location: 'us-central1' }) })
await vertex.run({ prompt: 'List the files in this directory.' })Functions#
classifyGoogleErrorFunction#
Classify a Gemini API / Vertex AI error.
function classifyGoogleError(err: unknown, label?: string): ClassifiedError | nullParameters
| Name | Type | Default | Description |
|---|---|---|---|
| err | unknown | Error a Google provider threw. | |
| label? | string | 'Gemini' | Product a limit's message names; routes over other services (Antigravity) pass their own. |
Returns
ClassifiedError | nullgoogleFunction#
Creates the Google Gemini provider on the Gemini API (Google AI Studio).
Authenticates with apiKey, else GEMINI_API_KEY, else GOOGLE_API_KEY.
function google(params?: GoogleParams): ProviderParameters
| Name | Type | Description |
|---|---|---|
| params? | GoogleParams | API key, default model, capabilities and extra headers. |
Returns
Example
import { createAgent } from 'zidane'
import { google } from 'zidane/providers/google'
const agent = createAgent({
provider: google({ apiKey: process.env.GEMINI_API_KEY }),
})
await agent.run({ prompt: 'Say hello.' })googleCompatibleFunction#
Creates a provider over another Gemini-wire backend: an extension supplies
the transport (send, parseChunk) and model records; message
conversion, thought signatures (tagged with the route's scope, never
replayed elsewhere), tool names, thinking levels, SSE parsing, usage and
cost come from the same plumbing as google and
googleVertex.
function googleCompatible(
route: GoogleCompatibleRoute,
params?: GoogleSharedParams,
): ProviderParameters
| Name | Type | Description |
|---|---|---|
| route | GoogleCompatibleRoute | The backend: name, transport and models. |
| params? | GoogleSharedParams | Default model, capabilities and extra headers. |
Returns
Example
import { googleCompatible } from 'zidane/providers'
const provider = googleCompatible({
name: 'my-gateway',
isOAuth: false,
send: (turn, fetch) => fetch(`https://gateway.example/v1beta/models/${turn.model.id}:streamGenerateContent?alt=sse`, {
method: 'POST',
headers: { 'content-type': 'application/json', 'authorization': `Bearer ${process.env.MY_GATEWAY_KEY}` },
body: JSON.stringify(turn.body),
signal: turn.signal,
}),
resolveModel: id => myModels[id],
}, { defaultModel: 'gemini-3.8-flash' })googleVertexFunction#
Creates the Google Vertex AI provider. Authenticates with a pinned
account's Google sign-in, else a Vertex API key (apiKey or
GOOGLE_CLOUD_API_KEY), else the active "Sign in with Google" grant, else
Google Cloud credentials for project in location. See
resolveVertexAuth.
function googleVertex(params?: GoogleVertexParams): ProviderParameters
| Name | Type | Description |
|---|---|---|
| params? | GoogleVertexParams | Credentials, project, location, default model, capabilities and extra headers. |
Returns
Example
import { createAgent } from 'zidane'
import { googleVertex } from 'zidane/providers/google'
// After `gcloud auth application-default login`:
const agent = createAgent({
provider: googleVertex({ project: 'my-project' }),
})
await agent.run({ prompt: 'Say hello.' })resolveGoogleModelFunction#
Model record for modelId on route: the registry's entry, else a
GOOGLE_EXTRA_MODELS overlay, else the default model's shape under
the requested id. A catalog entry overlays whichever applies.
function resolveGoogleModel(
route: GoogleRouteName,
modelId: string,
catalog?: ModelCatalog,
): GoogleWireModelParameters
| Name | Type | Description |
|---|---|---|
| route | GoogleRouteName | Backend the request goes to. |
| modelId | string | Requested model id. |
| catalog? | ModelCatalog | Per-run catalog override. |
Returns
resolveVertexAuthFunction#
Where a Vertex AI request goes and its credentials, read per turn so a credential configured after the provider was built still applies. In order: a pinned account's sign-in, a Vertex API key, the active "Sign in with Google" grant, then Google Cloud credentials for the project (a credentials file, gcloud's Application Default Credentials, the metadata server), a fresh token minted per request.
function resolveVertexAuth(
params?: GoogleVertexParams,
callbacks?: StreamCallbacks,
signal?: AbortSignal,
): Promise<VertexRequestAuth>Parameters
| Name | Type | Description |
|---|---|---|
| params? | GoogleVertexParams | Explicit settings; environment variables fill the rest. |
| callbacks? | StreamCallbacks | Stream callbacks, for the OAuth refresh hook. |
| signal? | AbortSignal | Aborts a token request. |
Returns
Promise<VertexRequestAuth>toGeminiContentsFunction#
Converts session messages to Gemini contents.
An assistant turn stays whole: Gemini signs only the FIRST function call of a parallel step, so splitting the calls into separate model turns would leave the others unsigned. Its results follow in call order, in one user turn, with the synthetic placeholder for any the history lost.
function toGeminiContents(
messages: SessionMessage[],
model: GoogleWireModel,
scope: GeminiSignatureScope,
provider?: string,
): GeminiContent[]Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| messages | SessionMessage[] | Session messages, tool names already on the wire. | |
| model | GoogleWireModel | Target model. | |
| scope | GeminiSignatureScope | Signature scope of the target. | |
| provider? | string | scope | Provider named in unsupported-media errors. Defaults to |
Returns
Constants#
GOOGLE_DEFAULT_MODELConstant#
Model used when a request names none. Served on free-tier Gemini API keys.
const GOOGLE_DEFAULT_MODEL = 'gemini-3.8-flash'GOOGLE_EXTRA_MODELSConstant#
Models pi-ai's registry hasn't bundled yet, served on both routes. A pi-ai release that bundles one supersedes its entry (bundled metadata always wins), so delete the entry then.
const GOOGLE_EXTRA_MODELS: readonly GoogleExtraModel[]Interfaces#
GeminiContentInterface#
One turn of the conversation.
interface GeminiContentProperties
| Name | Type | Description |
|---|---|---|
| parts | GeminiPart[] | What was said. |
| role | 'user' | 'model' | Who spoke. |
GeminiFunctionDeclarationInterface#
A tool the model may call.
interface GeminiFunctionDeclarationProperties
| Name | Type | Description |
|---|---|---|
| description | string | What it does. |
| name | string | Function name. |
| parameters? | unknown | OpenAPI-subset schema of the arguments (the legacy field some backends translate). |
| parametersJsonSchema? | unknown | Full JSON Schema of the arguments. |
GeminiGenerationConfigInterface#
Generation settings.
interface GeminiGenerationConfigProperties
| Name | Type | Description |
|---|---|---|
| maxOutputTokens? | number | Output ceiling in tokens. |
| temperature? | number | Sampling temperature. |
| thinkingConfig? | GeminiThinkingConfig | Thinking settings. |
GeminiPartInterface#
One part of a turn.
interface GeminiPartProperties
| Name | Type | Description |
|---|---|---|
| functionCall? | GeminiFunctionCall | A function call. |
| functionResponse? | GeminiFunctionResponse | A function result. |
| inlineData? | GeminiBlob | Inline media or file. |
| text? | string | Text, or a thought summary when |
| thought? | boolean | Marks |
| thoughtSignature? | string | Opaque signature of the model's reasoning, replayed as received. |
GeminiRequestInterface#
A GenerateContentRequest body.
interface GeminiRequestProperties
| Name | Type | Description |
|---|---|---|
| contents | GeminiContent[] | The conversation. |
| generationConfig? | GeminiGenerationConfig | Generation settings. |
| systemInstruction? | { parts: { text: string }[]; role: 'user' } | The system prompt. |
| toolConfig? | GeminiToolConfig | Function-calling mode. |
| tools? | { functionDeclarations: GeminiFunctionDeclaration[] }[] | Function declarations. |
GeminiResponseChunkInterface#
One streamed GenerateContentResponse.
interface GeminiResponseChunkProperties
| Name | Type | Description |
|---|---|---|
| candidates? | { content?: { parts?: GeminiPart[]; role?: string }; finishReason?: string }[] | Candidates; zidane reads the first. |
| responseId? | string | Response id. |
| usageMetadata? | GeminiUsageMetadata | Token counts so far. |
GeminiThinkingConfigInterface#
Thinking settings.
interface GeminiThinkingConfigProperties
| Name | Type | Description |
|---|---|---|
| includeThoughts? | boolean | Stream thought summaries. |
| thinkingBudget? | number | Token budget (Gemini 2.5); |
| thinkingLevel? | 'MINIMAL' | 'LOW' | 'MEDIUM' | 'HIGH' | Discrete level (Gemini 3+). |
GeminiToolInterface#
A tool as formatTools hands it to the request: name, description, JSON Schema.
interface GeminiToolProperties
| Name | Type | Description |
|---|---|---|
| description | string | What it does. |
| name | string | Function name on the wire. |
| parameters | Record<string, unknown> | JSON Schema of its arguments. |
GeminiToolConfigInterface#
Function-calling mode.
interface GeminiToolConfigProperties
| Name | Type | Description |
|---|---|---|
| functionCallingConfig | { allowedFunctionNames?: string[]; mode: 'AUTO' | 'ANY' | 'NONE' | 'VALIDATED' } |
|
GoogleCompatibleRouteInterface#
A Gemini-wire backend for googleCompatible: where requests go and
how they authenticate (send), how its stream events read
(parseChunk) and which models it serves (resolveModel). Message
conversion, thought-signature bookkeeping, tool names, thinking levels,
SSE parsing, usage and cost stay in the shared plumbing.
interface GoogleCompatibleRouteProperties
| Name | Type | Description |
|---|---|---|
| classifyError? | (err: unknown) => ClassifiedError | null | Error classification. Defaults to |
| isOAuth | boolean | Whether the provider runs on an OAuth credential. |
| name | string | Provider name ( |
| parseChunk? | (payload: unknown) => GeminiResponseChunk | One SSE event's JSON to a |
| resolveModel | (modelId: string, catalog?: ModelCatalog) => GoogleWireModel | Model record for a requested model id. Its |
| send | (request: GoogleTurnRequest, fetch: typeof fetch) => Promise<Response> | Sends one turn and returns the streaming response
( |
| signatureScope? | (modelId: string) => string | Signature scope of a model: the tag its thought signatures carry, and
the only scope they replay to. Defaults to |
GoogleExtraModelInterface#
A Google model pi-ai's registry hasn't bundled yet: a bundled template with the same thinking shape, under its own id.
interface GoogleExtraModelProperties
| Name | Type | Description |
|---|---|---|
| contextWindow | number | Context window in tokens. |
| id | string | Model id sent to the API. |
| maxTokens | number | Largest output in tokens. |
| name | string | Display name. |
| rates | () => Required<ModelCostRates> | A function, so a dated price change applies to long-running hosts. |
| template | string | A bundled model with the same thinking levels and budgets. |
GoogleParamsInterface#
Options for google.
interface GoogleParams extends GoogleSharedParamsProperties
| Name | Type | Default | Description |
|---|---|---|---|
| apiKey? | string | Gemini API key. Defaults to | |
capabilities?from GoogleSharedParams | ProviderCapabilities | Provider capability flags. Gemini takes images and files (PDFs and others) in prompts and in tool results; audio and video are refused. | |
defaultModel?from GoogleSharedParams | string | 'gemini-3.8-flash' | Model used when a request does not set one. |
extraHeaders?from GoogleSharedParams | Record<string, string> | Extra HTTP headers sent on every request. |
GoogleSharedParamsInterface#
Settings shared by the Google providers.
interface GoogleSharedParamsProperties
| Name | Type | Default | Description |
|---|---|---|---|
| capabilities? | ProviderCapabilities | Provider capability flags. Gemini takes images and files (PDFs and others) in prompts and in tool results; audio and video are refused. | |
| defaultModel? | string | 'gemini-3.8-flash' | Model used when a request does not set one. |
| extraHeaders? | Record<string, string> | Extra HTTP headers sent on every request. |
GoogleTurnRequestInterface#
One turn's request, handed to a GoogleCompatibleRoute's send.
interface GoogleTurnRequestProperties
| Name | Type | Description |
|---|---|---|
| body | GeminiRequest | The standard |
| callbacks | StreamCallbacks | Stream callbacks, for OAuth refresh hooks. |
| headers | Record<string, string> | The provider's extra headers ( |
| maxTokens? | number | Output ceiling as requested (the body's is already resolved). |
| model | GoogleWireModel | The model record the route resolved. |
| signal? | AbortSignal | Aborts the request. |
| thinking? | 'off' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max' | 'adaptive' | Thinking level as requested, for a backend that maps it its own way. |
GoogleVertexParamsInterface#
Options for googleVertex.
interface GoogleVertexParams extends GoogleSharedParamsProperties
| Name | Type | Default | Description |
|---|---|---|---|
| account? | string | Run on one stored "Sign in with Google" account (its stable id) rather
than the active one. See | |
| apiKey? | string | Vertex AI API key (express mode). Defaults to | |
capabilities?from GoogleSharedParams | ProviderCapabilities | Provider capability flags. Gemini takes images and files (PDFs and others) in prompts and in tool results; audio and video are refused. | |
| credentialsFile? | string | Service-account or authorized-user credentials file. Defaults to
| |
defaultModel?from GoogleSharedParams | string | 'gemini-3.8-flash' | Model used when a request does not set one. |
extraHeaders?from GoogleSharedParams | Record<string, string> | Extra HTTP headers sent on every request. | |
| location? | string | Vertex AI location. Defaults to | |
| project? | string | Google Cloud project. Defaults to |
GoogleWireModelInterface#
A model on a Gemini wire: what the request builder and the cost need. The
Google routes read it from pi-ai's model registry; a
googleCompatible backend builds its own.
interface GoogleWireModelProperties
| Name | Type | Description |
|---|---|---|
| baseUrl? | string | API base URL (the Gemini API's, or Vertex's |
| contextWindow | number | Context window in tokens. |
| cost | GeminiModelCost | Prices per million tokens; zero rates report no cost. |
| id | string | Model id sent on the wire. |
| input | readonly string[] | Input kinds; a model without |
| maxTokens | number | Output ceiling in tokens. |
| name | string | Display name. |
| provider | string | Provider that serves it. |
| reasoning | boolean | Whether it thinks. |
| thinkingLevelMap? | Partial<Record<string, string | null>> | zidane level → Gemini level, |
VertexRequestAuthInterface#
Where a Vertex AI request goes and how it authenticates.
interface VertexRequestAuthProperties
| Name | Type | Description |
|---|---|---|
| headers | Record<string, string> | Auth headers: |
| url | (modelId: string) => string | The |
Types#
GoogleRouteNameType#
Zidane provider (and signature route) names of the two Google backends.
type GoogleRouteName = 'google' | 'google-vertex'