Migrate from the Vercel AI SDK OpenAI provider to TokenRex
Use TokenRex as an OpenAI-compatible provider in the Vercel AI SDK.
Steps
- Create a TokenRex API key.
- Create an OpenAI provider with a custom baseURL.
- Use any enabled model ID.
What to check after switching
- Run your existing test prompts and compare replies.
- Check the usage field in responses to confirm token counts and costs.
- Short model IDs are used on TokenRex, for example gpt-6-sol rather than openai/gpt-6-sol.
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" });Questions
- Can I switch back?
- Yes. Nothing is locked in: change the base URL and key back and your code keeps working.
Related
- How to use the OpenAI SDK with a custom base URL
- What is a model ID?
- Migrate from the OpenAI API to TokenRex
- Migrate from OpenRouter to TokenRex
- Migrate from the Anthropic API to TokenRex
- Migrate from the Google Gemini API to TokenRex
- Migrate from LangChain's ChatOpenAI default endpoint to TokenRex
- Migrate from several separate provider accounts to TokenRex
- Migrate from USD card billing to TokenRex