Integrations
Any client that supports a custom OpenAI or Anthropic base URL works with Gateway. Set the base URL and your msk-gateway- key, then use a provider/model ID from /v1/models. Each example reads the key from MASTRA_GATEWAY_API_KEY.
Mastra frameworkDirect link to Mastra framework
Set MASTRA_GATEWAY_API_KEY and use a model ID with the mastra/ prefix. No base URL is needed.
src/mastra/agents/weather-agent.ts
import { Agent } from '@mastra/core/agent'
export const weatherAgent = new Agent({
id: 'weather-agent',
name: 'Weather Agent',
instructions: 'You are a helpful weather assistant.',
model: 'mastra/openai/gpt-6.1-sol',
})
To give the agent conversation memory, see Memory.
AI SDKDirect link to AI SDK
Use @ai-sdk/openai-compatible with any chat model in the catalog.
src/gateway.ts
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
import { generateText } from 'ai'
export const gateway = createOpenAICompatible({
name: 'mastra-gateway',
baseURL: 'https://gateway-api.mastra.ai/v1',
apiKey: process.env.MASTRA_GATEWAY_API_KEY,
})
const { text } = await generateText({
model: gateway.chatModel('google/gemini-3.8-flash'),
prompt: 'What is 2+2?',
})
OpenAI SDKDirect link to OpenAI SDK
src/gateway.ts
import OpenAI from 'openai'
const client = new OpenAI({
baseURL: 'https://gateway-api.mastra.ai/v1',
apiKey: process.env.MASTRA_GATEWAY_API_KEY,
})
const completion = await client.chat.completions.create({
model: 'openai/gpt-6.1-sol',
messages: [{ role: 'user', content: 'What is 2+2?' }],
})
The same client works for Responses, Embeddings, and Images.
OpenAI Python SDKDirect link to OpenAI Python SDK
gateway.py
import os
from openai import OpenAI
client = OpenAI(
base_url="https://gateway-api.mastra.ai/v1",
api_key=os.environ["MASTRA_GATEWAY_API_KEY"],
)
completion = client.chat.completions.create(
model="google/gemini-3.8-flash",
messages=[{"role": "user", "content": "What is 2+2?"}],
)
Anthropic SDKDirect link to Anthropic SDK
The Anthropic SDK appends /v1/messages, so omit /v1 from the base URL.
src/gateway.ts
import Anthropic from '@anthropic-ai/sdk'
const client = new Anthropic({
baseURL: 'https://gateway-api.mastra.ai',
apiKey: process.env.MASTRA_GATEWAY_API_KEY,
})
const message = await client.messages.create({
model: 'anthropic/claude-sonnet-5.5',
max_tokens: 256,
messages: [{ role: 'user', content: 'What is 2+2?' }],
})
LangGraph and Deep Agents (TypeScript)Direct link to LangGraph and Deep Agents (TypeScript)
Use ChatOpenAI from @langchain/openai, then pass the model to a LangGraph graph or createDeepAgent.
src/agent.ts
import { ChatOpenAI } from '@langchain/openai'
export const model = new ChatOpenAI({
model: 'google/gemini-3.8-flash',
configuration: {
baseURL: 'https://gateway-api.mastra.ai/v1',
apiKey: process.env.MASTRA_GATEWAY_API_KEY,
},
})
LangChain and Deep Agents (Python)Direct link to LangChain and Deep Agents (Python)
agent.py
import os
from langchain_openai import ChatOpenAI
model = ChatOpenAI(
model="google/gemini-3.8-flash",
base_url="https://gateway-api.mastra.ai/v1",
api_key=os.environ["MASTRA_GATEWAY_API_KEY"],
)
Pass model to create_deep_agent or any LangGraph node.
Pydantic AIDirect link to Pydantic AI
agent.py
import os
from openai import AsyncOpenAI
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider
client = AsyncOpenAI(
base_url="https://gateway-api.mastra.ai/v1",
api_key=os.environ["MASTRA_GATEWAY_API_KEY"],
)
model = OpenAIChatModel(
"google/gemini-3.8-flash",
provider=OpenAIProvider(openai_client=client),
)
agent = Agent(model, system_prompt="Keep answers concise.")