Mastra
The Mastra Memory Gateway is an OpenAI-compatible API proxy with built-in Observational Memory. Point any HTTP client, SDK, or framework at the gateway and every conversation is automatically remembered without any memory management code.
Learn more in the Memory Gateway documentation.
Get an API keyDirect link to Get an API key
Go to gateway.mastra.ai and sign up for a Mastra account. During the onboarding you'll get your personal API key to authenticate requests.
UsageDirect link to Usage
Define your API key as an environment variable:
.env
MASTRA_GATEWAY_API_KEY=your-gateway-key
Set your gateway model ID:
src/mastra/agents/my-agent.ts
import { Agent } from "@mastra/core/agent";
const agent = new Agent({
id: "my-agent",
name: "My Agent",
instructions: "You are a helpful assistant",
model: "mastra/openai/gpt-5-mini"
});
Pass memory.thread and memory.resource when you generate/stream responses to enable Observational Memory:
src/mastra/run.ts
import { weatherAgent } from "./agents/weather-agent";
const memory = {
thread: "assistant-thread-1",
resource: "user-42",
};
const result = await weatherAgent.stream("My name is Alex and I prefer concise answers.", {
memory,
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
ConfigurationDirect link to Configuration
# Use gateway API key
MASTRA_GATEWAY_API_KEY=your-gateway-key