> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # ![Mastra 標誌](https://mastra.ai/brand/logo.svg)Mastra Gateway 是與 OpenAI 相容的 API Proxy,並內建 [Observational Memory](https://gateway.mastra.ai/docs/features#observational-memory)。將任何 HTTP Client、SDK 或 Framework 指向 Gateway,每段對話都會自動保留記憶,無須撰寫任何 Memory 管理程式碼。 如需進一步了解,請參閱 [Gateway 文件](https://gateway.mastra.ai/docs)。 ## 取得 API 金鑰 前往 [gateway.mastra.ai](https://gateway.mastra.ai) 並註冊 Mastra 帳號。在新手引導期間,你會取得用於驗證請求的個人 API 金鑰。 ## 使用方式 將 API 金鑰定義為環境變數: ```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 模型也使用相同的前綴: ```typescript import { ModelRouterEmbeddingModel } from '@mastra/core/llm' const embedder = new ModelRouterEmbeddingModel('mastra/openai/text-embedding-3-small') ``` 產生或串流回應時傳入 `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 參考](https://gateway.mastra.ai/docs/api/overview) - [範例](https://gateway.mastra.ai/docs/examples/)