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
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
- 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
id:
string
The unique ID of the gateway (gateway.id property)
Returns
gateway:
MastraModelGateway | undefined
The gateway instance, or undefined if not found
Related
- Mastra.getGateway() - Get gateway by registration key
- Mastra.listGateways() - List all gateways
- Mastra.addGateway() - Add a gateway
- MastraModelGateway - Gateway base class
- Custom Gateways Guide - Creating custom gateways