> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # Mastra.addGateway() 動態向 Mastra 執行個體新增 gateway。可在初始化期間或之後使用。 ## 使用範例 ```typescript import { Mastra } from '@mastra/core' const mastra = new Mastra() // Add with explicit key mastra.addGateway(new MyCustomGateway(), 'myGateway') // Add using gateway's ID as the key mastra.addGateway(new MyCustomGateway()) // Stored with key 'my-custom-gateway' (the gateway's id) ``` ## 參數 **gateway** (`MastraModelGateway`): 要新增的 gateway 執行個體 **key** (`string`): 選用的註冊鍵。如果未提供,則使用 gateway.getId() ## 傳回值 無傳回值。gateway 會新增到內部 registry。 ## 行為 - 如果已存在具有相同鍵的 gateway,則跳過新增 - 在開發模式(`MASTRA_DEV=true`)下,會自動觸發自訂 gateway 的類型產生 - gateway 會立即可用於模型解析 ## 相關內容 - [Mastra.getGateway()](https://mastra.zisheng.pro/zh-TW/reference/core/getGateway): 依註冊鍵取得 gateway - [Mastra.getGatewayById()](https://mastra.zisheng.pro/zh-TW/reference/core/getGatewayById): 依 ID 取得 gateway - [Mastra.listGateways()](https://mastra.zisheng.pro/zh-TW/reference/core/listGateways): 列出所有 gateway - [MastraModelGateway](https://mastra.zisheng.pro/zh-TW/reference/core/mastra-model-gateway): Gateway 基類 - [自訂 Gateway 指南](https://mastra.zisheng.pro/zh-TW/models/gateways/custom-gateways): 建立自訂 gateway