BroadRouter
Get started

Use the OpenAI Node.js SDK with BroadNet Inference

Updated

Install the openai npm package and create the client with baseURL set to https://inference.broadnet.ai/v1 and apiKey set to your BroadNet key. Your existing chat.completions code keeps working; change only the model ID, for example broadnet/deepseek-v4.1-flash. BroadNet serves chat completions, not the Responses API, so keep using client.chat.completions.create.

You need an inference key from your BroadNet Inference account. New accounts start with $5 of credit and no card. If you use Python instead, see the Python SDK guide.

1. Install and set the key

The current openai package (7.x) needs Node.js 22 or newer.

npm install openai
export BROADNET_API_KEY='paste-the-key-once'

2. First request

Save as first-request.mjs and run node first-request.mjs:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://inference.broadnet.ai/v1",
  apiKey: process.env.BROADNET_API_KEY,
});

const response = await client.chat.completions.create({
  model: "broadnet/gemma-4-26b-a4b",
  messages: [{ role: "user", content: "Reply with one short sentence." }],
});
console.log(response.choices[0].message.content);

broadnet/gemma-4-26b-a4b works on the free credit. For the unlimited-plan model use broadnet/deepseek-v4.1-flash and set max_tokens to 1,000 or more, because its reasoning counts toward the limit. Why answers come back empty.

3. Stream tokens

const stream = await client.chat.completions.create({
  model: "broadnet/deepseek-v4.1-flash",
  stream: true,
  stream_options: { include_usage: true },
  messages: [{ role: "user", content: "Count from one to three." }],
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
  if (chunk.usage) console.log("\n", chunk.usage);
}

4. Log the request ID

const { data, request_id } = await client.chat.completions
  .create({ model: "broadnet/gemma-4-26b-a4b", messages: [{ role: "user", content: "Hi" }] })
  .withResponse();
console.log(request_id, data.choices[0].message.content);

The SDK reads request_id from the x-request-id header. Parsed responses also carry it as data._request_id.

Keep that ID with the UTC time, route and status: BroadNet support asks for them. Error codes and when to retry.

Troubleshooting

  • 401. The key is wrong, expired, or out of pay-as-you-go allowance. If BROADNET_API_KEY is unset, apiKey is undefined and the SDK falls back to OPENAI_API_KEY, or throws if that’s missing too.
  • 404. Check that baseURL ends in /v1 and that you call chat.completions, not responses. Then check the model ID, with the broadnet/ prefix.
  • Paid model fails on a new account. The $5 starting credit covers BroadNet Gemma 4 VL 26B (broadnet/gemma-4-26b-a4b) and the two BroadNet Transcribe models. Top up to use the other chat models: DeepSeek V4.1 Flash, GLM 5.3 and Qwen3.8 27B.
  • Empty content. Reasoning counts toward max_tokens. Raise it or leave it unset. Why answers come back empty.
  • 429. A pay-as-you-go key allows 30 requests a minute and 4 at once. The SDK retries twice by default; tune maxRetries on the client. See streaming chat completions for dropped streams.

Questions

Can I set the BroadNet base URL with an environment variable in Node?

Yes. The SDK reads OPENAI_BASE_URL when you don't pass baseURL, and OPENAI_API_KEY when you don't pass apiKey. Passing both explicitly avoids sending a BroadNet key to OpenAI, or the reverse, by mistake.

Does client.responses.create work with BroadNet?

No. BroadNet's docs list chat completions and audio transcriptions only. Use client.chat.completions.create for chat.

Which Node.js version does the openai package need?

The current 7.x release declares Node.js 22 or newer. Deno, Bun, Cloudflare Workers and Vercel Edge are also supported.

Can I call BroadNet from the browser with the Node SDK?

Don't. The SDK blocks browser use unless you set dangerouslyAllowBrowser, because the key would ship to every visitor. Call BroadNet from your server instead.

Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity