@standardagents/google
v0.13.2
Published
Google Gemini provider for Standard Agents
Readme
@standardagents/google
Google Gemini and Imagen provider for Standard Agents.
This package exports a Standard Agents provider factory for Google's Gemini chat/multimodal models and Imagen image models. It handles:
- model discovery via the Google model list API
- Standard Agents message and tool translation to Google
generateContentrequests - Gemini text, JSON, tools, and multimodal inputs
- Imagen generation and image-edit style requests
- usage and cost calculation from Google usage metadata
Install
npm install @standardagents/google @standardagents/specUsage
import { google } from '@standardagents/google';
const provider = google({
apiKey: process.env.GOOGLE_API_KEY!,
});
const result = await provider.generate({
model: 'gemini-2.5-flash',
messages: [
{
role: 'user',
content: 'Write a one sentence summary of Saturn.',
},
],
});
console.log(result.content);
console.log(result.usage?.cost);Factory
The package exports:
google(config)- provider factoryGoogleProvider- provider classgoogleProviderOptions- Zod schema for provider-specific options
Factory config follows ProviderFactoryConfig from @standardagents/spec:
type ProviderFactoryConfig = {
apiKey: string;
baseUrl?: string;
timeout?: number;
};Supported Features
The provider exposes capabilities per model where available. In practice:
- Gemini models support text generation, streaming, tool calling, and multimodal input
- Gemma hosted models support text and selected multimodal inputs, with more limited tool support
- Imagen models support image generation/edit-style requests and are handled as non-streaming image models
Use getModels() and getModelCapabilities() to inspect the currently available surface:
const models = await provider.getModels?.();
const capabilities = await provider.getModelCapabilities?.('gemini-2.5-pro');Provider Options
This package validates Google-specific provider options through google.providerOptions.
Common options:
candidateCountresponseModalitiessafetySettingsthinkingConfigimageConfignumberOfImagesaspectRationegativePromptguidanceScaleoutputMimeTypelanguageeditMode
Example:
const result = await provider.generate({
model: 'gemini-2.5-pro',
messages: [
{ role: 'user', content: 'Return valid JSON with a title and summary.' },
],
responseFormat: {
type: 'json',
schema: {
type: 'object',
properties: {
title: { type: 'string' },
summary: { type: 'string' },
},
required: ['title', 'summary'],
},
},
providerOptions: {
candidateCount: 1,
safetySettings: [
{ category: 'HARM_CATEGORY_HARASSMENT', threshold: 'BLOCK_ONLY_HIGH' },
],
},
});Images
For multimodal Gemini requests, pass Standard Agents image parts or image attachments and the provider will translate them to Google inline parts. For Imagen requests, the provider will route through the image generation path automatically when the target model is an Imagen model.
Debugging
Use inspectRequest() to view the transformed Google-native request body:
const inspected = await provider.inspectRequest?.({
model: 'gemini-2.5-flash',
messages: [{ role: 'user', content: 'hello' }],
});
console.log(inspected?.body);Notes
- Model IDs are normalized so variants like
google/...,models/..., andpublishers/google/models/...resolve to the same pricing and capability entries where possible. - Cost is computed from Google usage metadata and pricing tables when available; Google does not currently return a direct monetary cost field for Gemini requests.
