Use Inference APIs with OpenAI Node.js SDK
Set baseURL on the official openai npm package. Works in Node, Bun, Deno and edge runtimes.
Settings
| Setting | Value |
|---|---|
| Base URL | https://api.inferenceapis.com/v1 (also /openai/v1) |
| API key | From API Keys; send as Authorization: Bearer … |
| Chat model ids | openai/gpt-oss-120b, deepseek-ai/DeepSeek-V4-Flash, zai-org/GLM-5.3-Flash, meta-llama/Llama-3.3-70B-Instruct-Turbo — all models |
| Audio model ids | openai/whisper-large-v3 (transcription), hexgrad/Kokoro-82M (speech) |
Configuration
Install
npm install openaiChat with streaming
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.inferenceapis.com/v1", apiKey: process.env.INFERENCE_API_KEY });
const stream = await client.chat.completions.create({
model: "openai/gpt-oss-120b",
messages: [{ role: "user", content: "Hello" }],
max_tokens: 400,
stream: true,
});
for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? "");Speech
import fs from "node:fs";
const audio = await client.audio.speech.create({ model: "hexgrad/Kokoro-82M", voice: "af_heart", input: "Hello there" });
fs.writeFileSync("hello.mp3", Buffer.from(await audio.arrayBuffer()));Transcription
const result = await client.audio.transcriptions.create({ model: "openai/whisper-large-v3", file: fs.createReadStream("hello.mp3") });
console.log(result.text);Verify
Smoke test
node -e "import('openai').then(async ({default: OpenAI}) => console.log((await new OpenAI({baseURL:'https://api.inferenceapis.com/v1', apiKey: process.env.INFERENCE_API_KEY}).models.list()).data.length + ' models'))"Gotchas
- In browsers, never ship your key; call through your own backend.
If something fails
401 — key missing or wrong · 402 insufficient_balance — add credits on Billing · 404 model_not_found — check the id against the model list (aliases such as gpt-oss-120b work too) · 503 model_unavailable — the model is being enabled. Full details in the API docs.
