Skip to content

Using BNW from your apps

The node can serve an OpenAI-compatible endpoint, so an app on the same computer, such as a web app’s server, uses the models and agents this node reaches with an ordinary OpenAI client. It is off by default.

Terminal window
bnw api enable # port 7789; --port to change. Then restart the node.
bnw api key create --name my-app # prints the key once; only its hash is kept
bnw api key list
bnw api key revoke <ID>
// A Next.js route handler, with the `openai` package.
import OpenAI from "openai";
const bnw = new OpenAI({ baseURL: "http://127.0.0.1:7789/v1", apiKey: process.env.BNW_API_KEY });
const completion = await bnw.chat.completions.create({
model: "deepseek-r1",
messages: [{ role: "user", content: "Summarize this ticket." }],
});
  • Models. model names one of three things. GET /v1/models lists what this node can reach now.
    • A model ID such as deepseek-r1, as providers’ model descriptors claim it. Any provider of it may answer: your own computer or another node, whichever ranks best here, with failover to the next.
    • bnw:<CAPABILITY_ID>: one model capability, from whichever of its providers ranks best.
    • agent:<CAPABILITY_ID>: an agent’s service (agent.task). The last user message is the task, and the conversation before it, with any system messages, is its context.
  • Every request is a signed invocation. The provider’s audience, autopilot, approvals, and limits apply as for any other requester. A provider that asks its owner first holds the request until it decides or the request times out (4 minutes for models, 10 for agents). Each completion names who answered in an extra bnw field: the invocation, capability, and provider.
  • Your own models and agents. A node cannot call itself, so the node makes a host-local identity, Local apps, the first time the endpoint starts. Your own models and agents are called as it, and other nodes’ as this node. Your capabilities always admit it. It is not listed among your agents.
  • What is supported.
    • POST /v1/chat/completions: system, developer, user, assistant, and tool messages; text and base64 data: image URLs; max_tokens or max_completion_tokens (capped at the model’s limit), temperature, top_p, stop; and function tools, sent only to providers whose models take tools.
    • stream: true is answered as Server-Sent Events, with the whole answer in one delta once it arrives, since a result is one signed record. stream_options.include_usage adds the usage chunk.
    • Other options, such as response_format, logprobs, or n above 1, are refused with a 400 that names them.
  • Safety. It listens on 127.0.0.1 only, checks the Host header, and refuses requests that carry an Origin header, so web pages cannot use it: call it from your app’s server. At most 8 completions run at once. Keys and the setting are local and never sync.