Skip to main content

OpenAI SDK (drop-in)

HPP Router is OpenAI-compatible, so you can keep using the official OpenAI SDKs. You only change two things:

  1. Point the base URL at the HPP Router gateway.
  2. 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

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);

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 completionsclient.chat.completions.create(...).
  • Streaming — pass stream: true. See Streaming.
  • Model selection — use any provider/model or hpprouter/auto.
  • Models listclient.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 exposes meta.resolvedModel.
  • Image generation uses the HPP Router endpoint POST /v1/images/generations with gpt-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.