> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # ![OpenAI ロゴ](https://models.dev/logos/openai.svg)OpenAI Mastra のモデルルーターを通じて 47 個の OpenAI モデルを利用できます。認証には `OPENAI_API_KEY` 環境変数が自動的に使用されます。 詳しくは、[OpenAI のドキュメント](https://platform.openai.com/docs/models)を参照してください。 ```bash OPENAI_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: "openai/chatgpt-image-latest" }); // 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 | | ------------------------------- | ------- | ----- | --------- | ----- | ----- | ----- | ---------- | ----------- | | `openai/chatgpt-image-latest` | — | | | | | | — | — | | `openai/gpt-4.1` | 1.0M | | | | | | $2 | $8 | | `openai/gpt-4.1-mini` | 1.0M | | | | | | $0.40 | $2 | | `openai/gpt-4o` | 128K | | | | | | $3 | $10 | | `openai/gpt-4o-2024-08-06` | 128K | | | | | | $3 | $10 | | `openai/gpt-4o-2024-11-20` | 128K | | | | | | $3 | $10 | | `openai/gpt-4o-mini` | 128K | | | | | | $0.15 | $0.60 | | `openai/gpt-5` | 400K | | | | | | $1 | $10 | | `openai/gpt-5-mini` | 400K | | | | | | $0.25 | $2 | | `openai/gpt-5-nano` | 400K | | | | | | $0.05 | $0.40 | | `openai/gpt-5-pro` | 400K | | | | | | $15 | $120 | | `openai/gpt-5.1` | 400K | | | | | | $1 | $10 | | `openai/gpt-5.2` | 400K | | | | | | $2 | $14 | | `openai/gpt-5.2-chat-latest` | 128K | | | | | | $2 | $14 | | `openai/gpt-5.2-pro` | 400K | | | | | | $21 | $168 | | `openai/gpt-5.3-chat-latest` | 128K | | | | | | $2 | $14 | | `openai/gpt-5.3-codex` | 400K | | | | | | $2 | $14 | | `openai/gpt-5.3-codex-spark` | 128K | | | | | | $2 | $14 | | `openai/gpt-5.4` | 1.1M | | | | | | $3 | $15 | | `openai/gpt-5.4-mini` | 400K | | | | | | $0.75 | $5 | | `openai/gpt-5.4-nano` | 400K | | | | | | $0.20 | $1 | | `openai/gpt-5.4-pro` | 1.1M | | | | | | $30 | $180 | | `openai/gpt-5.5` | 1.1M | | | | | | $5 | $30 | | `openai/gpt-5.5-pro` | 1.1M | | | | | | $30 | $180 | | `openai/gpt-5.6` | 1.1M | | | | | | $5 | $30 | | `openai/gpt-5.6-luna` | 1.1M | | | | | | $0.20 | $1 | | `openai/gpt-5.6-sol` | 1.1M | | | | | | $5 | $30 | | `openai/gpt-5.6-terra` | 1.1M | | | | | | $2 | $12 | | `openai/gpt-image-1-mini` | — | | | | | | — | — | | `openai/gpt-image-1.5` | — | | | | | | — | — | | `openai/gpt-image-2` | — | | | | | | $5 | $30 | | `openai/gpt-realtime-2.1` | 128K | | | | | | $4 | $24 | | `openai/o3` | 200K | | | | | | $2 | $8 | | `openai/o3-pro` | 200K | | | | | | $20 | $80 | | `openai/text-embedding-3-large` | 8K | | | | | | $0.13 | — | | `openai/text-embedding-3-small` | 8K | | | | | | $0.02 | — | | `openai/text-embedding-ada-002` | 8K | | | | | | $0.10 | — | ## 高度な設定 ### カスタムヘッダー ```typescript const agent = new Agent({ id: "custom-agent", name: "custom-agent", model: { id: "openai/chatgpt-image-latest", apiKey: process.env.OPENAI_API_KEY, headers: { "X-Custom-Header": "value" } } }); ``` ### 動的なモデル選択 ```typescript const agent = new Agent({ id: "dynamic-agent", name: "Dynamic Agent", model: ({ requestContext }) => { const useAdvanced = requestContext.task === "complex"; return useAdvanced ? "openai/text-embedding-ada-002" : "openai/chatgpt-image-latest"; } }); ``` ## Provider オプション OpenAI は `providerOptions` パラメーターを通じて、次の Provider 固有オプションをサポートします。 ```typescript const response = await agent.generate("Hello!", { providerOptions: { openai: { // See available options in the table below } } }); ``` ### 利用可能なオプション **conversation** (`string | null | undefined`) **include** (`("web_search_call.results" | "file_search_call.results" | "message.output_text.logprobs" | "reasoning.encrypted_content")[] | null | undefined`) **instructions** (`string | null | undefined`) **logprobs** (`number | boolean | undefined`) **maxToolCalls** (`number | null | undefined`) **metadata** (`any`) **parallelToolCalls** (`boolean | null | undefined`) **previousResponseId** (`string | null | undefined`) **promptCacheKey** (`string | null | undefined`) **promptCacheOptions** (`{ mode?: "explicit" | "implicit" | undefined; ttl?: "30m" | undefined; } | undefined`) **promptCacheRetention** (`"in_memory" | "24h" | null | undefined`) **reasoningEffort** (`string | null | undefined`) **reasoningMode** (`"standard" | "pro" | undefined`) **reasoningContext** (`"auto" | "current_turn" | "all_turns" | undefined`) **reasoningSummary** (`string | null | undefined`) **safetyIdentifier** (`string | null | undefined`) **serviceTier** (`"auto" | "default" | "flex" | "priority" | null | undefined`) **store** (`boolean | null | undefined`): OpenAI がモデルのトレーニング用に API リクエストを保存するかどうかを制御します。組織で zero data retention が有効な場合は、必ず "false" に設定してください。参照: https\://platform.openai.com/docs/guides/your-data#zero-data-retention **passThroughUnsupportedFiles** (`boolean | undefined`) **strictJsonSchema** (`boolean | null | undefined`) **textVerbosity** (`"low" | "medium" | "high" | null | undefined`) **truncation** (`"auto" | "disabled" | null | undefined`) **user** (`string | null | undefined`) **systemMessageMode** (`"remove" | "system" | "developer" | undefined`) **forceReasoning** (`boolean | undefined`) **allowedTools** (`{ toolNames: string[]; mode?: "auto" | "required" | undefined; } | undefined`) ## Provider を直接インストールする この Provider はスタンドアロン package として直接インストールし、Mastra のモデルルーター文字列の代わりに使用することもできます。詳しくは、[package のドキュメント](https://www.npmjs.com/package/@ai-sdk/openai)を参照してください。 **npm**: ```bash npm install @ai-sdk/openai ``` **pnpm**: ```bash pnpm add @ai-sdk/openai ``` **Yarn**: ```bash yarn add @ai-sdk/openai ``` **Bun**: ```bash bun add @ai-sdk/openai ``` Provider 固有の詳細については、[AI SDK OpenAI Provider のドキュメント](https://ai-sdk.dev/providers/ai-sdk-providers/openai)を参照してください。