Back to Mastra

Google | Models

docs/src/content/en/models/providers/google.mdx

2025-12-1812.8 KB
Original Source

Google

Access 30 Google models through Mastra's model router. Authentication is handled automatically using the GOOGLE_GENERATIVE_AI_API_KEY environment variable.

Learn more in the Google documentation.

bash
GOOGLE_GENERATIVE_AI_API_KEY=your-api-key
typescript
import { Agent } from "@mastra/core/agent";

const agent = new Agent({
  id: "my-agent",
  name: "My Agent",
  instructions: "You are a helpful assistant",
  model: "google/gemini-1.5-flash"
});

// Generate a response
const response = await agent.generate("Hello!");

// Stream a response
const stream = await agent.stream("Tell me a story");
for await (const chunk of stream) {
  console.log(chunk);
}

Models

<ProviderModelsTable models={[ { "model": "google/gemini-1.5-flash", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": false, "contextWindow": 1000000, "maxOutput": 8192, "inputCost": 0.075, "outputCost": 0.3 }, { "model": "google/gemini-1.5-flash-8b", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": false, "contextWindow": 1000000, "maxOutput": 8192, "inputCost": 0.0375, "outputCost": 0.15 }, { "model": "google/gemini-1.5-pro", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": false, "contextWindow": 1000000, "maxOutput": 8192, "inputCost": 1.25, "outputCost": 5 }, { "model": "google/gemini-2.0-flash", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": false, "contextWindow": 1048576, "maxOutput": 8192, "inputCost": 0.1, "outputCost": 0.4 }, { "model": "google/gemini-2.0-flash-lite", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": false, "contextWindow": 1048576, "maxOutput": 8192, "inputCost": 0.075, "outputCost": 0.3 }, { "model": "google/gemini-2.5-flash", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.3, "outputCost": 2.5 }, { "model": "google/gemini-2.5-flash-image", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": true, "contextWindow": 32768, "maxOutput": 32768, "inputCost": 0.3, "outputCost": 30 }, { "model": "google/gemini-2.5-flash-image-preview", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": true, "contextWindow": 32768, "maxOutput": 32768, "inputCost": 0.3, "outputCost": 30 }, { "model": "google/gemini-2.5-flash-lite", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.1, "outputCost": 0.4 }, { "model": "google/gemini-2.5-flash-lite-preview-06-17", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.1, "outputCost": 0.4 }, { "model": "google/gemini-2.5-flash-lite-preview-09-2025", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.1, "outputCost": 0.4 }, { "model": "google/gemini-2.5-flash-preview-04-17", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.15, "outputCost": 0.6 }, { "model": "google/gemini-2.5-flash-preview-05-20", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.15, "outputCost": 0.6 }, { "model": "google/gemini-2.5-flash-preview-09-2025", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.3, "outputCost": 2.5 }, { "model": "google/gemini-2.5-flash-preview-tts", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 8000, "maxOutput": 16000, "inputCost": 0.5, "outputCost": 10 }, { "model": "google/gemini-2.5-pro", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 1.25, "outputCost": 10 }, { "model": "google/gemini-2.5-pro-preview-05-06", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 1.25, "outputCost": 10 }, { "model": "google/gemini-2.5-pro-preview-06-05", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 1.25, "outputCost": 10 }, { "model": "google/gemini-2.5-pro-preview-tts", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 8000, "maxOutput": 16000, "inputCost": 1, "outputCost": 20 }, { "model": "google/gemini-3-flash-preview", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.5, "outputCost": 3 }, { "model": "google/gemini-3-pro-preview", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1000000, "maxOutput": 64000, "inputCost": 2, "outputCost": 12 }, { "model": "google/gemini-3.1-flash-image-preview", "imageInput": true, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": true, "contextWindow": 131072, "maxOutput": 32768, "inputCost": 0.25, "outputCost": 60 }, { "model": "google/gemini-3.1-flash-lite-preview", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.25, "outputCost": 1.5 }, { "model": "google/gemini-3.1-pro-preview", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 2, "outputCost": 12 }, { "model": "google/gemini-3.1-pro-preview-customtools", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 2, "outputCost": 12 }, { "model": "google/gemini-embedding-001", "imageInput": false, "audioInput": false, "videoInput": false, "toolUsage": false, "reasoning": false, "contextWindow": 2048, "maxOutput": 3072, "inputCost": 0.15, "outputCost": null }, { "model": "google/gemini-flash-latest", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.3, "outputCost": 2.5 }, { "model": "google/gemini-flash-lite-latest", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 1048576, "maxOutput": 65536, "inputCost": 0.1, "outputCost": 0.4 }, { "model": "google/gemini-live-2.5-flash", "imageInput": true, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 128000, "maxOutput": 8000, "inputCost": 0.5, "outputCost": 2 }, { "model": "google/gemini-live-2.5-flash-preview-native-audio", "imageInput": false, "audioInput": true, "videoInput": true, "toolUsage": true, "reasoning": true, "contextWindow": 131072, "maxOutput": 65536, "inputCost": 0.5, "outputCost": 2 } ]} />

Advanced configuration

Custom headers

typescript
const agent = new Agent({
  id: "custom-agent",
  name: "custom-agent",
  model: {
    id: "google/gemini-1.5-flash",
    apiKey: process.env.GOOGLE_GENERATIVE_AI_API_KEY,
    headers: {
      "X-Custom-Header": "value"
    }
  }
});

Dynamic model selection

typescript
const agent = new Agent({
  id: "dynamic-agent",
  name: "Dynamic Agent",
  model: ({ requestContext }) => {
    const useAdvanced = requestContext.task === "complex";
    return useAdvanced
      ? "google/gemini-live-2.5-flash-preview-native-audio"
      : "google/gemini-1.5-flash";
  }
});

Provider Options

Google supports the following provider-specific options via the providerOptions parameter:

typescript
const response = await agent.generate("Hello!", {
  providerOptions: {
    google: {
      // See available options in the table below
    }
  }
});

Available Options

<PropertiesTable content={[ { "name": "responseModalities", "type": "("TEXT" | "IMAGE")[] | undefined", "description": "", "isOptional": true }, { "name": "thinkingConfig", "type": "{ thinkingBudget?: number | undefined; includeThoughts?: boolean | undefined; thinkingLevel?: "minimal" | "low" | "medium" | "high" | undefined; } | undefined", "description": "", "isOptional": true }, { "name": "cachedContent", "type": "string | undefined", "description": "", "isOptional": true }, { "name": "structuredOutputs", "type": "boolean | undefined", "description": "", "isOptional": true }, { "name": "safetySettings", "type": "{ category: "HARM_CATEGORY_UNSPECIFIED" | "HARM_CATEGORY_HATE_SPEECH" | "HARM_CATEGORY_DANGEROUS_CONTENT" | "HARM_CATEGORY_HARASSMENT" | "HARM_CATEGORY_SEXUALLY_EXPLICIT" | "HARM_CATEGORY_CIVIC_INTEGRITY"; threshold: "HARM_BLOCK_THRESHOLD_UNSPECIFIED" | ... 4 more ... | "OFF"; }[] | undefined", "description": "", "isOptional": true }, { "name": "threshold", "type": ""HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_ONLY_HIGH" | "BLOCK_NONE" | "OFF" | undefined", "description": "", "isOptional": true }, { "name": "audioTimestamp", "type": "boolean | undefined", "description": "", "isOptional": true }, { "name": "labels", "type": "Record<string, string> | undefined", "description": "", "isOptional": true }, { "name": "mediaResolution", "type": ""MEDIA_RESOLUTION_UNSPECIFIED" | "MEDIA_RESOLUTION_LOW" | "MEDIA_RESOLUTION_MEDIUM" | "MEDIA_RESOLUTION_HIGH" | undefined", "description": "", "isOptional": true }, { "name": "imageConfig", "type": "{ aspectRatio?: "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "4:5" | "5:4" | "9:16" | "16:9" | "21:9" | undefined; imageSize?: "1K" | "2K" | "4K" | undefined; } | undefined", "description": "", "isOptional": true }, { "name": "retrievalConfig", "type": "{ latLng?: { latitude: number; longitude: number; } | undefined; } | undefined", "description": "", "isOptional": true } ]} />

Direct provider installation

This provider can also be installed directly as a standalone package, which can be used instead of the Mastra model router string. View the package documentation for more details.

bash
npm install @ai-sdk/google