Mastra
Mastra is a TypeScript agent and workflow framework built on top of the Vercel AI SDK. Because Mastra inherits the AI SDK's LanguageModel abstraction, the same drop-in pattern from the Vercel AI SDK page applies โ point @ai-sdk/openai at your Ferro gateway and Mastra picks it up automatically.
Installโ
pnpm add @mastra/core @ai-sdk/openai
Configureโ
import { createOpenAI } from "@ai-sdk/openai";
import { Agent } from "@mastra/core";
const ferro = createOpenAI({
baseURL: process.env.FERRO_BASE_URL,
apiKey: process.env.FERRO_API_KEY,
});
const writer = new Agent({
name: "writer",
instructions: "You write concise blog post drafts.",
model: ferro("claude-3-5-sonnet-20241022"), // โ Anthropic via Ferro
});
const result = await writer.generate("Draft an intro about AI gateways.");
console.log(result.text);
For multi-provider workflows, build one createOpenAI instance and select different models per agent / step.
Verifyโ
curl http://localhost:8080/v1/chat/completions \
-H "Authorization: Bearer $FERRO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","messages":[{"role":"user","content":"hi"}]}'
Runnable exampleโ
ai-gateway-cookbook/typescript/03-mastra-workflow is planned.
See alsoโ
- Vercel AI SDK โ the underlying provider surface
- LangGraph โ Python equivalent for multi-provider agents