OpenAI SDK Integration
Point the official OpenAI SDK (Python / Node.js) at KOPRouter — just swap the Base URL and API key.
- The OpenAI SDK for your language installed
- A KOPRouter API key (prefixed with
sk-)
Python
from openai import OpenAI
client = OpenAI(
base_url="https://koprouter.kopglobal.com/v1",
api_key="sk-...",
)
resp = client.chat.completions.create(
model="MODEL_ID",
messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)
Node.js
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://koprouter.kopglobal.com/v1",
apiKey: "sk-...",
});
const resp = await client.chat.completions.create({
model: "MODEL_ID",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(resp.choices[0].message.content);
If your network cannot reach KOPRouter directly (e.g. mainland China), configure a VPN or proxy first. The Python SDK reads the HTTPS_PROXY / HTTP_PROXY environment variables and also accepts an http_client in code (e.g. httpx.Client(proxy=...)); the Node.js SDK is best used with a system proxy or TUN mode. See Network & Proxy for how to set the environment variables.