Skip to main content

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

🌐 Related