OpenAI SDK (drop-in)
HPP Router is OpenAI-compatible, so you can keep using the official OpenAI SDKs. You only change two things:
- Point the base URL at the HPP Router gateway.
- Use your HPP Router API key instead of an OpenAI key.
The HPP Router chat endpoint lives under /llm/v1, so the OpenAI SDK base URL is:
https://router.hpp.io/llm/v1
Examples
- Node.js / TypeScript
- Python
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.HPPROUTER_API_KEY!,
baseURL: 'https://router.hpp.io/llm/v1',
});
const completion = await client.chat.completions.create({
model: 'hpprouter/auto',
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(completion.choices[0].message);
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["HPPROUTER_API_KEY"],
base_url="https://router.hpp.io/llm/v1",
)
completion = client.chat.completions.create(
model="hpprouter/auto",
messages=[{"role": "user", "content": "Hello!"}],
)
print(completion.choices[0].message)
How authentication maps
OpenAI SDKs send the key as Authorization: Bearer <key>, which HPP Router accepts as its Bearer scheme. See Authentication for both supported schemes.
What works as-is
- Chat completions —
client.chat.completions.create(...). - Streaming — pass
stream: true. See Streaming. - Model selection — use any
provider/modelorhpprouter/auto. - Models list —
client.models.list().
What's different
- Smart-routing metadata (
X-HPP-Router-*) is returned as response headers, which most OpenAI SDK helpers don't surface directly. Read the raw response headers, or use the TypeScript SDK, which exposesmeta.resolvedModel. - Image generation uses the HPP Router endpoint
POST /v1/images/generationswithgpt-image-1. See Image Generation.
When to prefer @hpprouter/sdk
The dedicated TypeScript SDK returns smart-routing metadata (resolved model, basket, tier) alongside the response, and provides typed helpers for usage, quota, and images. Use it when you want first-class access to HPP Router-specific features; use the OpenAI SDK when you want a minimal-change drop-in.