Use MagmaRouter with the Vercel AI SDK.
The Vercel AI SDK reaches a custom endpoint through @ai-sdk/openai-compatible. Use it rather than the plain openai provider, whose default path is the Responses API that MagmaRouter does not serve.
createOpenAICompatible
// npm install ai @ai-sdk/openai-compatible
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
const magmarouter = createOpenAICompatible({
name: "magmarouter",
baseURL: "https://magmarouter.com/v1",
apiKey: process.env.MAGMAROUTER_API_KEY,
includeUsage: true,
});
const { text } = await generateText({
model: magmarouter("deepseek/deepseek-chat-v3.1"),
prompt: "Hello",
});
console.log(text);
Why not @ai-sdk/openai The plain openai provider defaults to the Responses API, which 404s on MagmaRouter. If you must use it, call magmarouter.chat("id") to force chat completions. The openai-compatible provider is the one to reach for.