integrations/framework/Mastra

Mastra + AIgateway

Agent framework — point models at the gateway, tools route automatically.

Mastra is a TypeScript agent framework. Use the @ai-sdk/openai provider with the AIgateway base URL and every model in our catalog becomes a Mastra-compatible agent brain.

Mastra homepage →
Setup

Three steps or fewer.

STEP 01

Wire the model

Create an AIgateway-scoped provider with createOpenAI (passing baseURL as the second arg of openai() is model-settings and gets ignored — it would hit real OpenAI). Then hand its model to Mastra's Agent.

import { Agent } from "@mastra/core/agent";
import { createOpenAI } from "@ai-sdk/openai";

const aigateway = createOpenAI({
  baseURL: "https://api.aigateway.sh/v1",
  apiKey: process.env.AIGATEWAY_API_KEY,
});

const agent = new Agent({
  name: "researcher",
  model: aigateway("anthropic/claude-opus-4.7"),
});
More integrations

Same key. Every other tool.