Mastra
Mastra Gateway is one OpenAI- and Anthropic-compatible API for models from many providers, with routing, failover, bring-your-own-key, and per-request cost tracking.
Learn more in the Gateway documentation.
Get an API keyDirect link to Get an API key
Add credits in Billing at projects.mastra.ai, then create a key in Gateway > API keys. Keys start with msk-gateway-. See the Quickstart.
UsageDirect link to Usage
Define your API key as an environment variable:
.env
MASTRA_GATEWAY_API_KEY=msk-gateway-...
Set a model ID with the mastra/ prefix:
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-6.1-sol"
});
Use the same prefix for embedding models:
src/mastra/rag/embed.ts
import { ModelRouterEmbeddingModel } from "@mastra/core/llm";
const embedder = new ModelRouterEmbeddingModel("mastra/openai/text-embedding-3-small");
For conversation memory, see Memory.