Mastra.getGatewayById()
通过网关的唯一 ID(网关实例的 id 属性)来检索网关。当你需要通过其固有标识符而不是注册密钥来查找网关时,这非常有用。
🌐 Retrieves a gateway by its unique ID (the id property of the gateway instance). This is useful when you need to find a gateway by its intrinsic identifier rather than its registration key.
使用示例Direct link to 使用示例
🌐 Usage example
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'
用例Direct link to 用例
🌐 Use Cases
- 网关版本控制:具有唯一ID(
'gateway-v1'、'gateway-v2')的不同版本 - 在注册密钥未知的情况下查找网关
- 识别不同 Mastra 实例中的网关
参数Direct link to 参数
🌐 Parameters
id:
string
The unique ID of the gateway (gateway.id property)
返回Direct link to 返回
🌐 Returns
gateway:
MastraModelGateway | undefined
The gateway instance, or undefined if not found
相关Direct link to 相关
🌐 Related
- Mastra.getGateway() - 通过注册密钥获取网关
- Mastra.listGateways() - 列出所有网关
- Mastra.addGateway() - 添加网关
- MastraModelGateway - 网关基类
- 自定义网关指南 - 创建自定义网关