openai-oxide
v0.11.2
Published
Native Node.js bindings for openai-oxide powered by napi-rs.
Maintainers
Readme
openai-oxide for Node.js
Native Node.js bindings for openai-oxide, built with napi-rs. Also available on crates.io (Rust) and PyPI (Python).
The package exposes the Rust client to Node.js with native streaming and WebSocket support, while keeping release artifacts out of git. Prebuilt binaries are published to npm for the supported targets listed below.
Features
- Native bindings for chat, responses, streaming, and WebSocket sessions
- Shared Rust core with the main
openai-oxidecrate - Prebuilt npm artifacts for the main desktop and server targets
- Fast-path APIs for hot loops that return only
textorresponse id - Local development and release flow driven by
pnpm
Why choose openai-oxide on Node?
| Feature | openai-oxide | official openai SDK |
| :--- | :--- | :--- |
| WebSocket Responses | Persistent wss:// session, reuses TLS for every step | REST-only |
| Streaming parser | Zero-copy SSE parser + early function-call parse | HTTP/2 response buffering |
| Typed Rust core | Full Response struct, hedged requests, parallel fan-outs | Generic JS objects |
| Hot REST paths | createText, createStoredResponseId, createTextFollowup avoid JSON bridge | Always serializes Record<string, any> |
| Platform binaries | Prebuilt .node for darwin/linux/windows in npm | Pure JS package |
The official SDK is great for HTTP/REST but does not expose WebSocket streaming or Rust-level hedged/parallel tooling out of the box. If your workload issues quick successive tool calls, streams tokens, or runs inside a WebSocket session, the native bindings keep latency and contention lower while still letting you call the same OpenAI APIs.
Supported Targets
- macOS
x64 - macOS
arm64 - Linux
x64GNU - Linux
x64musl - Linux
arm64GNU - Linux
arm64musl - Windows
x64MSVC
Install
npm install openai-oxide
# or
pnpm add openai-oxide
# or
yarn add openai-oxideFrom the repository for local development:
cd openai-oxide-node
pnpm install
pnpm build
pnpm testClient reads credentials from the same environment variables as the Rust crate, for example OPENAI_API_KEY.
Quick Start
const { Client } = require('openai-oxide')
async function main() {
const client = new Client()
const response = await client.createResponse({
model: 'gpt-4o-mini',
input: 'Say hello to Node.js from Rust via napi-rs.'
})
console.log(response.output?.[0]?.content?.[0]?.text)
}
main().catch((error) => {
console.error(error)
process.exitCode = 1
})Examples live in examples/:
examples/01_basic_request.jsexamples/02_streaming.jsexamples/03_websocket.jsexamples/bench_node.js
Benchmarks
Benchmarks were run locally against the live OpenAI API with:
BENCH_ITERATIONS=5 pnpm benchSetup:
- Model:
gpt-5.4 - Iterations:
5 - Reported value: median latency
- Comparison target: official
openainpm SDK
Node.js Ecosystem (openai-oxide vs openai)
openai-oxide wins 8/8 tests. Native napi-rs bindings vs official openai npm.
| Test | openai-oxide | openai | Winner |
| :--- | :--- | :--- | :--- |
| Plain text | 1075ms | 1311ms | OXIDE (+18%) |
| Structured output | 1370ms | 1765ms | OXIDE (+22%) |
| Function calling | 1725ms | 1832ms | OXIDE (+6%) |
| Multi-turn (2 reqs) | 2283ms | 2859ms | OXIDE (+20%) |
| Rapid-fire (5 calls) | 6246ms | 6936ms | OXIDE (+10%) |
| Streaming TTFT | 534ms | 580ms | OXIDE (+8%) |
| Parallel 3x | 1937ms | 1991ms | OXIDE (+3%) |
| WebSocket hot pair | 2181ms | N/A | OXIDE |
median of medians, 3×5 iterations. Model: gpt-5.4.
Reproduce: cd openai-oxide-node && BENCH_ITERATIONS=5 node examples/bench_node.js
Summary: openai-oxide wins 8/8 tests.
For the lowest-overhead REST paths in Node, prefer the fast-path methods:
client.createText(model, input, maxOutputTokens?)client.createStoredResponseId(model, input, maxOutputTokens?)client.createTextFollowup(model, input, previousResponseId, maxOutputTokens?)
Development
Useful commands:
pnpm install
pnpm build
pnpm test
pnpm bench
pnpm pack:previewpnpm build writes the local .node binary next to index.js for development only. Those generated binaries are ignored by git and are not committed.
pnpm pack:preview writes a tarball preview into .preview/, which is also ignored by git.
Release Flow
The repository keeps the Node release separate from the Rust and Python releases.
For the Node package:
- Keep the Node package version aligned with the Rust crate and Python package version.
- Push a tag like
node-v0.9.6. - GitHub Actions builds the native addon for each supported target.
- The Node release workflow assembles platform packages with
napi-rsand publishes to npm withpnpm publish.
Required secrets for npm publishing:
NPM_TOKEN
The workflow uses pnpm throughout, publishes with provenance enabled, and keeps platform-specific binaries out of the repository history.
