Migrate from the Vercel AI SDK OpenAI provider to TokenRex

Use TokenRex as an OpenAI-compatible provider in the Vercel AI SDK.

Steps

What to check after switching

Example

import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";

const tokenrex = createOpenAI({ apiKey: process.env.TOKENREX_API_KEY, baseURL: "https://tokenrex.ai/api/public" });
const { text } = await generateText({ model: tokenrex.chat("gpt-6-astra"), prompt: "Hello" });
Get API keyCost calculatorDocs

Questions

Can I switch back?
Yes. Nothing is locked in: change the base URL and key back and your code keeps working.

Related