# 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

```typescript
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()](https://mastra.ai/reference/core/getGateway): Get gateway by registration key
- [Mastra.listGateways()](https://mastra.ai/reference/core/listGateways): List all gateways
- [Mastra.addGateway()](https://mastra.ai/reference/core/addGateway): Add a gateway
- [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