OpenAI Node.js SDK
The TypeScript/JavaScript path to HiWay.
bash
npm install openaihiway.ts
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://www.hiway2llm.com/v1",
apiKey: process.env.HIWAY_API_KEY!,
});
const response = await client.chat.completions.create({
model: "auto",
messages: [{ role: "user", content: "Write a limerick about HTTP" }],
});
console.log(response.choices[0].message.content);
console.log("Routed to:", response.model);Streaming
typescript
const stream = await client.chat.completions.create({
model: "auto",
messages: [...],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}Reading HiWay headers
typescript
const response = await client.chat.completions
.create({ model: "auto", messages: [...] })
.withResponse();
console.log(response.response.headers.get("x-hiway-model"));
console.log(response.response.headers.get("x-hiway-cost-usd"));