You can repoint Mastra through Butter using its createOpenAI function, which accepts the necessary base URL and headers.
See it in the example below.
If you are using version 1.0.0 or later of Vercel’s AI SDK, you may have to downgrade to pre-1.0 in order to force the use of Chat Completions.npm install @ai-sdk/openai@0.0.x
import 'dotenv/config';
import { createOpenAI } from '@ai-sdk/openai';
import { Agent } from '@mastra/core/agent';
const openai = createOpenAI({
baseURL: "https://proxy.butter.dev/v1",
headers: {"Butter-Auth": `Bearer ${process.env.BUTTER_API_KEY}`},
apiKey: process.env.OPENAI_API_KEY
});
export const agent = new Agent({
name: "Agent + Butter",
instructions: "You are a helpful translation assistant.",
model: openai("gpt-4"),
});
const response = await agent.generateLegacy("What is the English word for mantequilla?");
console.log(response.text);