跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

Mastra.getGatewayById()

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.

Usage example
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'

Use cases
Use cases的直接链接

  • Gateway versioning: Different versions with unique IDs ('gateway-v1', 'gateway-v2')
  • Finding gateways when registration keys are unknown
  • Identifying gateways across different Mastra instances

Parameters
Parameters的直接链接

id:

string
The unique ID of the gateway (gateway.id property)

Returns
Returns的直接链接

gateway:

MastraModelGateway | undefined
The gateway instance, or undefined if not found
On this page