OpenAI SDK
Drop-in client migration with base URL override
TheRouter.ai is OpenAI-compatible, so existing OpenAI SDK code usually needs only a base URL and model ID update.
Overview
This page mirrors the OpenRouter workflow and adapts it for TheRouter.ai. Use TheRouter.ai as your OpenAI-compatible endpoint and keep model IDs in `provider/model` format.
Installation
Install the required SDKs and keep your TheRouter.ai key in environment variables.
install.sh
npm install openai && pip install openaiConfiguration
Set TheRouter.ai base URL overrides and pass your API key. Add attribution headers when your app should appear in rankings.
TypeScript
const client = new OpenAI({
baseURL: "https://api.therouter.ai/v1",
apiKey: process.env.THEROUTER_API_KEY,
});Caveats
Integration note
Some OpenAI-only beta params may not map 1:1 for every provider. Keep compatibility tests for advanced features.
For production rollouts, pin SDK versions and validate model compatibility in staging before broad rollout.