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 OpenAIDirect 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 AnthropicDirect 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 GatewayDirect 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 GatewayDirect link to From Mastra Memory Gateway
The previous product, Memory Gateway, combined model routing with Observational Memory. Gateway now handles model access only.
Memory Gateway shuts down on December 31, 2026. After that date, requests with msk_ keys fail. Create msk-gateway- keys and migrate before then.
| Before | Now |
|---|---|
msk_ keys | msk-gateway- keys. Create a new key in projects.mastra.ai. |
x-thread-id and x-resource-id headers | Gateway ignores these headers and doesn't store conversations. |
/v1/memory/threads | Removed. Use Mastra Memory in your agent. |
memory.thread and memory.resource on a Mastra agent routed through Gateway | Configure Memory on the agent instead. |
The base URL, https://gateway-api.mastra.ai/v1, is unchanged.