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_KEYis unset,apiKeyisundefinedand the SDK falls back toOPENAI_API_KEY, or throws if that’s missing too. - 404. Check that
baseURLends in/v1and that you callchat.completions, notresponses. Then check the model ID, with thebroadnet/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 towardmax_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
maxRetrieson the client. See streaming chat completions for dropped streams.
