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

Use the official OpenAI client with the TheRouter base URL and a model ID from the catalog. Model and parameter support can vary.

Installation

Install the required SDKs and keep your TheRouter.ai key in environment variables.

install.sh
npm install openai && pip install openai

Configuration

Set the TheRouter base URL and pass your TheRouter API key through an environment variable.

TypeScript
import OpenAI from "openai";

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.

Help & contact