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

Mastra.addGateway()

Dynamically adds a gateway to the Mastra instance. Can be used during or after initialization.

Usage example
Usage example的直接链接

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)

Parameters
Parameters的直接链接

gateway:

MastraModelGateway
The gateway instance to add

key?:

string
Optional registration key. If not provided, uses gateway.getId()

Returns
Returns的直接链接

Void. The gateway is added to the internal registry.

Behavior
Behavior的直接链接

  • 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
On this page