@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
42 lines (27 loc) • 1.43 kB
Markdown
Dynamically adds a gateway to the Mastra instance. Can be used during or after initialization.
```typescript
import { Mastra } from '@mastra/core'
const mastra = new Mastra()
// Add with explicit key
mastra.addGateway(new MyCustomGateway(), 'myGateway')
// Add using gateway's ID as the key
mastra.addGateway(new MyCustomGateway())
// Stored with key 'my-custom-gateway' (the gateway's id)
```
**gateway** (`MastraModelGateway`): The gateway instance to add
**key** (`string`): Optional registration key. If not provided, uses gateway.getId()
Void. The gateway is added to the internal registry.
- If a gateway with the same key already exists, the addition is skipped
- In development mode (`MASTRA_DEV=true`), automatically triggers type generation for custom gateways
- The gateway becomes available immediately for model resolution
## Related
- [Mastra.getGateway()](https://mastra.ai/reference/core/getGateway): Get gateway by registration key
- [Mastra.getGatewayById()](https://mastra.ai/reference/core/getGatewayById): Get gateway by ID
- [Mastra.listGateways()](https://mastra.ai/reference/core/listGateways): List all gateways
- [MastraModelGateway](https://mastra.ai/reference/core/mastra-model-gateway): Gateway base class
- [Custom Gateways Guide](https://mastra.ai/models/gateways/custom-gateways): Creating custom gateways