> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # ![Mastra ロゴ](https://mastra.ai/brand/logo.svg)Mastra Gateway は [Observational Memory](https://gateway.mastra.ai/docs/features#observational-memory) を内蔵した OpenAI 互換 API proxy です。HTTP client、SDK、framework の接続先を Gateway に設定するだけで、Memory 管理コードを書かずにすべての会話が自動的に記憶されます。 詳しくは、[Gateway のドキュメント](https://gateway.mastra.ai/docs)を参照してください。 ## API key の取得 [gateway.mastra.ai](https://gateway.mastra.ai) で Mastra account を作成します。onboarding 中に、リクエストの認証に使用する個人用 API key が発行されます。 ## 使用方法 API key を環境変数として定義します。 ```bash MASTRA_GATEWAY_API_KEY=your-gateway-key ``` Gateway のモデル ID を設定します。 ```typescript import { Agent } from "@mastra/core/agent"; const agent = new Agent({ id: "my-agent", name: "My Agent", instructions: "You are a helpful assistant", model: "mastra/openai/gpt-5-mini" }); ``` Gateway 経由で実行する Embedding モデルにも同じ prefix を使用します。 ```typescript import { ModelRouterEmbeddingModel } from "@mastra/core/llm"; const embedder = new ModelRouterEmbeddingModel("mastra/openai/text-embedding-3-small"); ``` レスポンスを生成または stream するときに `memory.thread` と `memory.resource` を渡すと、Observational Memory が有効になります。 ```typescript import { weatherAgent } from "./agents/weather-agent"; const memory = { thread: "assistant-thread-1", resource: "user-42", }; const result = await weatherAgent.stream("My name is Alex and I prefer concise answers.", { memory, }); for await (const chunk of result.textStream) { process.stdout.write(chunk); } ``` ## 設定 ```bash # Use gateway API key MASTRA_GATEWAY_API_KEY=your-gateway-key ``` ## 関連情報 - [機能](https://gateway.mastra.ai/docs/features) - [モデル](https://gateway.mastra.ai/docs/models) - [制限](https://gateway.mastra.ai/docs/limits) - [API Reference](https://gateway.mastra.ai/docs/api/overview) - [例](https://gateway.mastra.ai/docs/examples/)