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.
- Base URL
- https://api.magmarouter.com/v1
- API key
- Get one, starts sk-mr-
- Example model
- glm-5.3-xploded
createOpenAICompatible
TypeScript
// 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://api.magmarouter.com/v1", apiKey: process.env.MAGMAROUTER_API_KEY, includeUsage: true, }); const { text } = await generateText({ model: magmarouter("glm-5.3-xploded"), 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.