npm
npm install orbitrageLicense
Apache-2.0 · Node >= 18
Install
openai (>=4) is the only peer you need:
Initialize
Callinit() once, at the very top of your program, before importing your LLM
client. It returns a promise — await it.
What init() does
- Generates a stable trace id and adds it to every request as
x-orbitrage-run-id. - Installs a global
fetchinterceptor that injects trace + user headers on any request to an Orbitrage host. This is the primary mechanism and works even in frozen-ESM environments like Next.js. - Best-effort patches the
OpenAIconstructor and setsOPENAI_BASE_URLso no-arg clients point at the gateway. Your explicitbaseURLorapiKeyalways wins.
OrbitrageConfig
Your
orb_ key. Falls back to ORBITRAGE_API_KEY.End-user id to attribute calls to (sets
x-orbitrage-end-user-id).Override the gateway URL. Defaults to
https://api.orbitrage.ai/v1 (or
ORBITRAGE_BASE_URL).Set
false to make init() a no-op.Suppress the startup log line.
init() is idempotent. Legacy v0.4 options (disableBatch, captureContent,
instruments, …) are accepted and ignored.Per-end-user attribution
Forcing a model
API surface
| Symbol | Purpose |
|---|---|
init(config) | Set up the SDK (async). |
setUser(userId | null) | Bind/unbind the end-user id for subsequent clients. |
withAssociationProperties(props, fn) | Scoped user binding around an async block. |
flush(timeoutMs?) / shutdown() | No-ops — the gateway persists synchronously. |
workflow, task, tool, agent | No-op decorators kept for v0.4 compatibility. |
Using a framework?
LangChain, the Vercel AI SDK, Mastra, and others use the OpenAI client (orfetch) under the hood, so they’re captured transparently. See
Integrations.