Google
Mastra のモデルルーターを通じて 41 個の Google モデルを利用できます。認証には、GOOGLE_API_KEY または GOOGLE_GENERATIVE_AI_API_KEY のいずれかの環境変数が自動的に使用されます。
詳しくは、Google のドキュメントを参照してください。
.env
GOOGLE_API_KEY=your-api-key
GOOGLE_GENERATIVE_AI_API_KEY=your-api-key
src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";
const agent = new Agent({
id: "my-agent",
name: "My Agent",
instructions: "You are a helpful assistant",
model: "google/deep-research-max-preview-04-2026"
});
// 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);
}
モデルモデルへの直接リンク
| Model | Context | Tools | Reasoning | Image | Audio | Video | Input $/1M | Output $/1M |
|---|---|---|---|---|---|---|---|---|
google/deep-research-max-preview-04-2026 | 131K | $2 | $12 | |||||
google/deep-research-preview-04-2026 | 131K | $2 | $12 | |||||
google/gemini-2.5-computer-use-preview-10-2025 | 131K | $1 | $10 | |||||
google/gemini-2.5-flash | 1.0M | $0.30 | $3 | |||||
google/gemini-2.5-flash-image | 33K | $0.30 | $30 | |||||
google/gemini-2.5-flash-lite | 1.0M | $0.10 | $0.40 | |||||
google/gemini-2.5-flash-preview-tts | 8K | $0.50 | $10 | |||||
google/gemini-2.5-pro | 1.0M | $1 | $10 | |||||
google/gemini-2.5-pro-preview-tts | 8K | $1 | $20 | |||||
google/gemini-3-flash-preview | 1.0M | $0.50 | $3 | |||||
google/gemini-3-pro-image | 131K | $2 | $120 | |||||
google/gemini-3-pro-image-preview | 131K | $2 | $120 | |||||
google/gemini-3.1-flash-image | 66K | $0.50 | $60 | |||||
google/gemini-3.1-flash-image-preview | 66K | $0.50 | $60 | |||||
google/gemini-3.1-flash-lite | 1.0M | $0.25 | $2 | |||||
google/gemini-3.1-flash-lite-image | 66K | $0.25 | $30 | |||||
google/gemini-3.1-flash-live-preview | 131K | $0.75 | $5 | |||||
google/gemini-3.1-flash-tts-preview | 8K | $1 | $20 | |||||
google/gemini-3.1-pro-preview | 1.0M | $2 | $12 | |||||
google/gemini-3.1-pro-preview-customtools | 1.0M | $2 | $12 | |||||
google/gemini-3.5-flash | 1.0M | $2 | $9 | |||||
google/gemini-3.5-flash-lite | 1.0M | $0.30 | $3 | |||||
google/gemini-3.5-live-translate-preview | 16K | $4 | $21 | |||||
google/gemini-3.6-flash | 1.0M | $2 | $8 | |||||
google/gemini-embedding-001 | 2K | $0.15 | — | |||||
google/gemini-embedding-2 | 8K | $0.20 | — | |||||
google/gemini-flash-latest | 1.0M | $2 | $9 | |||||
google/gemini-flash-lite-latest | 1.0M | $0.25 | $2 | |||||
google/gemini-omni-flash-preview | 131K | $2 | $18 | |||||
google/gemini-robotics-er-1.6-preview | 131K | $1 | $5 | |||||
google/gemma-4-26b-a4b-it | 262K | — | — | |||||
google/gemma-4-31b-it | 262K | — | — | |||||
google/lyria-3-clip-preview | 1.0M | — | — | |||||
google/lyria-3-pro-preview | 1.0M | — | — | |||||
google/veo-3.1-fast-generate-preview | 480 | — | — | |||||
google/veo-3.1-generate-preview | 480 | — | — | |||||
google/veo-3.1-lite-generate-preview | 480 | — | — |
高度な設定高度な設定への直接リンク
カスタムヘッダーカスタムヘッダーへの直接リンク
src/mastra/agents/my-agent.ts
const agent = new Agent({
id: "custom-agent",
name: "custom-agent",
model: {
id: "google/deep-research-max-preview-04-2026",
apiKey: process.env.GOOGLE_API_KEY,GOOGLE_GENERATIVE_AI_API_KEY,
headers: {
"X-Custom-Header": "value"
}
}
});
動的なモデル選択動的なモデル選択への直接リンク
src/mastra/agents/my-agent.ts
const agent = new Agent({
id: "dynamic-agent",
name: "Dynamic Agent",
model: ({ requestContext }) => {
const useAdvanced = requestContext.task === "complex";
return useAdvanced
? "google/veo-3.1-lite-generate-preview"
: "google/deep-research-max-preview-04-2026";
}
});
Provider オプションProvider オプションへの直接リンク
Google は providerOptions パラメーターを通じて、次の Provider 固有オプションをサポートします。
const response = await agent.generate("Hello!", {
providerOptions: {
google: {
// See available options in the table below
}
}
});
利用可能なオプション利用可能なオプションへの直接リンク
responseModalities?:
("TEXT" | "IMAGE")[] | undefined
thinkingConfig?:
{ thinkingBudget?: number | undefined; includeThoughts?: boolean | undefined; thinkingLevel?: "minimal" | "low" | "medium" | "high" | undefined; } | undefined
cachedContent?:
string | undefined
structuredOutputs?:
boolean | undefined
safetySettings?:
{ 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
threshold?:
"HARM_BLOCK_THRESHOLD_UNSPECIFIED" | "BLOCK_LOW_AND_ABOVE" | "BLOCK_MEDIUM_AND_ABOVE" | "BLOCK_ONLY_HIGH" | "BLOCK_NONE" | "OFF" | undefined
audioTimestamp?:
boolean | undefined
labels?:
Record<string, string> | undefined
mediaResolution?:
"MEDIA_RESOLUTION_UNSPECIFIED" | "MEDIA_RESOLUTION_LOW" | "MEDIA_RESOLUTION_MEDIUM" | "MEDIA_RESOLUTION_HIGH" | undefined
imageConfig?:
{ aspectRatio?: "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "4:5" | "5:4" | "9:16" | "16:9" | "21:9" | "1:8" | "8:1" | "1:4" | "4:1" | undefined; imageSize?: "1K" | "2K" | "4K" | "512" | undefined; personGeneration?: "PERSON_GENERATION_UNSPECIFIED" | ... 3 more ... | undefined; prominentPeople?: "PROMINENT_PEOPLE_UNSPEC...
retrievalConfig?:
{ latLng?: { latitude: number; longitude: number; } | undefined; } | undefined
streamFunctionCallArguments?:
boolean | undefined
serviceTier?:
"standard" | "flex" | "priority" | undefined
requestType?:
"shared" | undefined
Provider を直接インストールするProvider を直接インストールするへの直接リンク
この Provider はスタンドアロン package として直接インストールし、Mastra のモデルルーター文字列の代わりに使用することもできます。詳しくは、package のドキュメントを参照してください。
- npm
- pnpm
- Yarn
- Bun
npm install @ai-sdk/google
pnpm add @ai-sdk/google
yarn add @ai-sdk/google
bun add @ai-sdk/google
Provider 固有の詳細については、AI SDK Google Provider のドキュメントを参照してください。