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.
相关Direct link to 相关
🌐 Related
- Mastra.getGatewayById() - 通过ID获取网关
- Mastra.listGateways() - 列出所有网关
- Mastra.addGateway() - 添加网关
- MastraModelGateway - 网关基类
- 自定义网关指南 - 创建自定义网关