Skip to main content

Mastra.getGateway()

通过注册密钥(添加网关到Mastra时使用的密钥)检索网关。

🌐 Retrieves a gateway by its registration key (the key used when adding the gateway to Mastra).

使用示例
Direct link to 使用示例

🌐 Usage example

import { Mastra } from '@mastra/core';

const mastra = new Mastra({
gateways: {
myGateway: new MyCustomGateway(),
},
});

const gateway = mastra.getGateway('myGateway');
console.log(gateway.name); // 'My Custom Gateway'

参数
Direct link to 参数

🌐 Parameters

key:

string
The registration key of the gateway

返回
Direct link to 返回

🌐 Returns

gateway:

MastraModelGateway
The gateway instance

投掷
Direct link to 投掷

🌐 Throws

如果未找到具有指定密钥的网关,则会抛出错误。

🌐 Throws an error if no gateway is found with the specified key.

🌐 Related