> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # Mastra.getGatewayById() 按閘道的唯一 ID(閘道實例的 `id` 屬性)擷取閘道。當你需要使用閘道的內在識別碼,而非登錄鍵來尋找閘道時,這十分實用。 ## 使用範例 ```typescript import { Mastra } from '@mastra/core' const mastra = new Mastra({ gateways: { customKey: new MyCustomGateway(), // id = 'my-custom-gateway' }, }) // Retrieve by ID (not registration key) const gateway = mastra.getGatewayById('my-custom-gateway') console.log(gateway.name) // 'My Custom Gateway' ``` ## 使用情境 - 閘道版本管理:不同版本使用不同的唯一 ID(`'gateway-v1'`、`'gateway-v2'`) - 在登錄鍵未知時尋找閘道 - 跨不同 Mastra 實例識別閘道 ## 參數 **id** (`string`): 閘道的唯一 ID(gateway.id 屬性) ## 傳回值 **gateway** (`MastraModelGateway | undefined`): 閘道實例;如找不到則為 undefined ## 相關內容 - [Mastra.getGateway()](https://mastra.zisheng.pro/zh-HK/reference/core/getGateway):按登錄鍵取得閘道 - [Mastra.listGateways()](https://mastra.zisheng.pro/zh-HK/reference/core/listGateways):列出所有閘道 - [Mastra.addGateway()](https://mastra.zisheng.pro/zh-HK/reference/core/addGateway):加入閘道 - [MastraModelGateway](https://mastra.zisheng.pro/zh-HK/reference/core/mastra-model-gateway):閘道基礎類別 - [自訂閘道指南](https://mastra.zisheng.pro/zh-HK/models/gateways/custom-gateways):建立自訂閘道