メインコンテンツへ移動

Mastra.getGatewayById()

一意の ID(Gateway インスタンスの id プロパティ)で Gateway を取得します。登録キーではなく Gateway 固有の識別子で検索する必要がある場合に便利です。

使用例
使用例への直接リンク

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'

ユースケース
ユースケースへの直接リンク

  • Gateway のバージョン管理: バージョンごとに一意の ID('gateway-v1''gateway-v2')を使用
  • 登録キーが不明な場合の Gateway 検索
  • 異なる Mastra インスタンス間での Gateway の識別

パラメーター
パラメーターへの直接リンク

id:

string
Gateway の一意の ID(gateway.id プロパティ)

戻り値
戻り値への直接リンク

gateway:

MastraModelGateway | undefined
Gateway インスタンス。見つからない場合は undefined