Skip to main content

Migrate to Gateway

Gateway is wire-compatible with the OpenAI and Anthropic APIs. Most migrations change two values: the base URL and the API key.

From OpenAI
Direct link to From OpenAI

Point the client at Gateway and prefix model IDs with openai/:

const client = new OpenAI({
- apiKey: process.env.OPENAI_API_KEY,
+ apiKey: process.env.MASTRA_GATEWAY_API_KEY,
+ baseURL: 'https://gateway-api.mastra.ai/v1',
})

- model: 'gpt-5.6-sol',
+ model: 'openai/gpt-5.6-sol',

To keep billing on your OpenAI account, add an OpenAI BYOK connection.

From Anthropic
Direct link to From Anthropic

The Anthropic SDK appends /v1/messages to its base URL, so set the base URL without /v1. Gateway model IDs use dots in version numbers, so claude-sonnet-5-5 becomes anthropic/claude-sonnet-5.5. Check IDs against GET /v1/models:

const client = new Anthropic({
- apiKey: process.env.ANTHROPIC_API_KEY,
+ apiKey: process.env.MASTRA_GATEWAY_API_KEY,
+ baseURL: 'https://gateway-api.mastra.ai',
})

- model: 'claude-sonnet-5-5',
+ model: 'anthropic/claude-sonnet-5.5',

From OpenRouter or Vercel AI Gateway
Direct link to From OpenRouter or Vercel AI Gateway

Both use provider/model IDs, so most model IDs carry over. Change the base URL to https://gateway-api.mastra.ai/v1 and use a Gateway key. Check each model ID against GET /v1/models, because provider naming can differ.

Gateway accepts OpenRouter's openrouter:web_search tool without options. See Web search.

From Mastra Memory Gateway
Direct link to From Mastra Memory Gateway

The previous product, Memory Gateway, combined model routing with Observational Memory. Gateway now handles model access only.

warning

Memory Gateway shuts down on December 31, 2026. After that date, requests with msk_ keys fail. Create msk-gateway- keys and migrate before then.

BeforeNow
msk_ keysmsk-gateway- keys. Create a new key in projects.mastra.ai.
x-thread-id and x-resource-id headersGateway ignores these headers and doesn't store conversations.
/v1/memory/threadsRemoved. Use Mastra Memory in your agent.
memory.thread and memory.resource on a Mastra agent routed through GatewayConfigure Memory on the agent instead.

The base URL, https://gateway-api.mastra.ai/v1, is unchanged.

On this page