> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # Mastra.addGateway() 將閘道動態加入 Mastra 實例。可在初始化期間或之後使用。 ## 使用範例 ```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`): 要加入的閘道實例 **key** (`string`): 可選的登錄鍵。如未提供,則使用 gateway.getId() ## 傳回值 無。閘道會加入內部登錄。 ## 行為 - 如果已有使用相同鍵的閘道,則會略過加入操作 - 在開發模式(`MASTRA_DEV=true`)下,會自動觸發自訂閘道的類型產生程序 - 閘道會立即可用於模型解析 ## 相關內容 - [Mastra.getGateway()](https://mastra.zisheng.pro/zh-HK/reference/core/getGateway):按登錄鍵取得閘道 - [Mastra.getGatewayById()](https://mastra.zisheng.pro/zh-HK/reference/core/getGatewayById):按 ID 取得閘道 - [Mastra.listGateways()](https://mastra.zisheng.pro/zh-HK/reference/core/listGateways):列出所有閘道 - [MastraModelGateway](https://mastra.zisheng.pro/zh-HK/reference/core/mastra-model-gateway):閘道基礎類別 - [自訂閘道指南](https://mastra.zisheng.pro/zh-HK/models/gateways/custom-gateways):建立自訂閘道