SDKs & frameworksGuide reviewed 2026-09-13

OpenAI SDKs

Python and JavaScript/TypeScript official SDKs.

Follow updates
On this page

Use the official Python or JavaScript SDK with RouterPlex's base URL and your RouterPlex key. These server-side examples work on macOS, Linux, and Windows.

Before you start #

Set ROUTERPLEX_API_KEY and create a Python environment. Use Python 3.12+ or a supported Node.js LTS release. Each example makes a chat request; model-specific tool, image, and reasoning features still vary.

Python #

Install in your virtual environment.

macOS/Linux:

bash
.venv/bin/python -m pip install --upgrade openai

Windows PowerShell:

powershell
.\.venv\Scripts\python.exe -m pip install --upgrade openai

Save as routerplex.py:

python
import os
from openai import OpenAI
 
client = OpenAI(
base_url="https://api.routerplex.com/v1",
api_key=os.environ["ROUTERPLEX_API_KEY"],
)
response = client.chat.completions.create(
model="claude-sonnet-4-6",
max_tokens=256,
messages=[{"role": "user", "content": "Reply with exactly: RouterPlex connected."}],
)
print(response.choices[0].message.content)

Run .venv/bin/python routerplex.py on macOS/Linux or .\.venv\Scripts\python.exe routerplex.py in PowerShell.

JavaScript / TypeScript #

Install with npm install openai on macOS/Linux or npm.cmd install openai in PowerShell. Save as routerplex.mjs (the same API is available in TypeScript):

javascript
import OpenAI from "openai";
 
const client = new OpenAI({
baseURL: "https://api.routerplex.com/v1",
apiKey: process.env.ROUTERPLEX_API_KEY,
});
const response = await client.chat.completions.create({
model: "claude-sonnet-4-6",
max_tokens: 256,
messages: [{ role: "user", content: "Reply with exactly: RouterPlex connected." }],
});
console.log(response.choices[0].message.content);

Run node routerplex.mjs in the terminal where the key is set. Look for the reply and the matching entry in Usage.

Environment-only configuration #

Both SDKs also support OPENAI_BASE_URL and OPENAI_API_KEY when you construct OpenAI() without explicit overrides. Existing explicit settings take precedence.

macOS/Linux:

bash
export OPENAI_BASE_URL="https://api.routerplex.com/v1"
export OPENAI_API_KEY="$ROUTERPLEX_API_KEY"

Windows PowerShell:

powershell
$env:OPENAI_BASE_URL = 'https://api.routerplex.com/v1'
$env:OPENAI_API_KEY = $env:ROUTERPLEX_API_KEY

Keep SDK calls on your backend. A frontend bundle exposes its API key. For the other wire format, use Anthropic Messages.

Official references: OpenAI Python SDK, OpenAI JavaScript SDK.

OpenAI SDKs — Docs