---
title: "OpenAI Node.js SDK with a custom baseURL (BroadNet) | BroadRouter"
description: "Point the official OpenAI Node.js and TypeScript SDK at BroadNet Inference by setting baseURL. Install it, make a first request, stream tokens and log request IDs."
url: https://broadrouter.com/guides/openai-node-sdk/
lang: en
updated: 2026-11-16
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# Use the OpenAI Node.js SDK with BroadNet Inference

Updated 2026-11-16

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](https://inference.broadnet.ai/?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-openai-node-sdk&utm_content=body). New accounts start with $5 of credit and no card. If you use Python instead, see [the Python SDK guide](https://broadrouter.com/guides/openai-python-sdk/).

## 1\. Install and set the key

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

```bash
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`:

```js
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](https://broadrouter.com/guides/reasoning-tokens-empty-response/).

## 3\. Stream tokens

```js
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

```js
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](https://broadrouter.com/guides/errors-and-retries/).

## 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](https://broadrouter.com/guides/reasoning-tokens-empty-response/).
-   **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](https://broadrouter.com/guides/streaming-chat-completions/) for dropped streams.

## Terms in this guide

[Pay-as-you-go](https://broadrouter.com/glossary/pay-as-you-go/)

Pay-as-you-go is a pricing model in which you pay only for what you use, metered per unit such as tokens, requests or audio minutes, with no subscription or minimum commitment. Most LLM APIs bill this way, from a prepaid balance or a periodic invoice.

[Token](https://broadrouter.com/glossary/token/)

A token is the unit of text a language model reads and writes: a word, part of a word, a punctuation mark or a byte sequence produced by the model's tokenizer. LLM APIs count, limit and usually bill usage in tokens.

[API key](https://broadrouter.com/glossary/api-key/)

An API key is a secret string that identifies and authorizes a client calling an API. LLM APIs usually expect it in an Authorization: Bearer header, and anyone who holds the key can make requests that are billed to the account that owns it.

[Chat Completions API](https://broadrouter.com/glossary/chat-completions-api/)

The Chat Completions API is OpenAI's HTTP endpoint, POST /v1/chat/completions, that takes a model name and a list of role-tagged messages and returns the model's next message. Its request and response shape became the common format that OpenAI-compatible providers and SDKs reuse.

[Concurrency](https://broadrouter.com/glossary/concurrency/)

Concurrency is the number of requests a client has in flight at the same time. LLM APIs often cap it per key or plan, separately from requests per minute, because each open request holds GPU capacity until its response has finished.

[Prepaid credit](https://broadrouter.com/glossary/prepaid-credit/)

Prepaid credit is money added to an API account before use. Each request deducts its cost from the balance, and when the balance runs out, metered requests stop until you top up. It caps spend at what you have paid in.

[Rate limit](https://broadrouter.com/glossary/rate-limit/)

A rate limit is a cap an API places on how much a client can use it in a time window, such as requests per minute or tokens per minute. Requests over the limit are refused, usually with HTTP 429 Too Many Requests, until usage falls back under it.

[Streaming](https://broadrouter.com/glossary/streaming/)

Streaming is a way of returning a language model response in small chunks while it is still being generated, instead of as one reply at the end. OpenAI-compatible APIs stream over server-sent events when the request sets stream to true.

## 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.

## Related guides

-   [Use the OpenAI Python SDK with BroadNet Inference](https://broadrouter.com/guides/openai-python-sdk/)
-   [Stream chat completions and handle dropped connections](https://broadrouter.com/guides/streaming-chat-completions/)
-   [BroadNet Inference error codes and when to retry](https://broadrouter.com/guides/errors-and-retries/)

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-openai-node-sdk&utm_content=page-cta) ·

**Sources**

-   [BroadNet Inference API reference](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=guides-openai-node-sdk&utm_content=sources)
-   [OpenAI Node.js library on npm (7.x, Node.js 22+, checked 2026-11-14)](https://www.npmjs.com/package/openai)
-   [openai-node README, request IDs and requirements (checked 2026-11-14)](https://github.com/openai/openai-node)
