> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # Mastra.getGatewayById() 按唯一 ID(gateway 实例的 `id` 属性)获取 gateway。需要按固有标识符而非注册键查找 gateway 时,此方法非常有用。 ## 使用示例 ```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' ``` ## 使用场景 - Gateway 版本控制:不同版本使用不同的唯一 ID (`'gateway-v1'`, `'gateway-v2'`) - 在注册键未知时查找 gateway - 跨不同 Mastra 实例识别 gateway ## 参数 **id** (`string`): gateway 的唯一 ID(gateway.id 属性) ## 返回值 **gateway** (`MastraModelGateway | undefined`): gateway 实例;如果未找到,则为 undefined ## 相关内容 - [Mastra.getGateway()](https://mastra.zisheng.pro/reference/core/getGateway): 按注册键获取 gateway - [Mastra.listGateways()](https://mastra.zisheng.pro/reference/core/listGateways): 列出所有 gateway - [Mastra.addGateway()](https://mastra.zisheng.pro/reference/core/addGateway): 添加 gateway - [MastraModelGateway](https://mastra.zisheng.pro/reference/core/mastra-model-gateway): Gateway 基类 - [自定义 Gateway 指南](https://mastra.zisheng.pro/models/gateways/custom-gateways): 创建自定义 gateway