createRouterBrainFromEnv
Exported only from @routerbrain/sdk/node. Handy for local scripts, samples, and CI: read API root, key, and common trace headers from process.env, return RouterBrain.
import { createRouterBrainFromEnv } from "@routerbrain/sdk/node";
const client = createRouterBrainFromEnv(process.env);
Missing GATEWAY_BASE_URL throws ContentBuildError (per README).
Environment variables
| Variable | Required by factory | Description |
|---|---|---|
GATEWAY_BASE_URL | Yes | OpenAI-compatible API root (pathname rules in Quickstart). |
GATEWAY_API_KEY | No | Bearer auth; equivalent to constructor apiKey when set. |
| Variable | Default | Description |
|---|---|---|
ROUTERBRAIN_X_TRACE_ID | unset | Default header x-trace-id (truncated if too long—README). |
ROUTERBRAIN_X_USER_ID | unset | x-user-id. |
ROUTERBRAIN_X_AGENT_NAME | router-sdk | x-agent-name. |
Often used in examples (not required by the factory)
Repo packages/sdk/examples and pnpm example:call-env may also read:
| Variable | Description |
|---|---|
GATEWAY_MODEL | Model id for the sample (required by script). |
GATEWAY_PLUGINS | JSON string parsed to RouterBrainChatPlugins for client.chat.messages({ plugins }). |
GATEWAY_TEST_PDF | Local PDF path for multimodal samples. |
GATEWAY_PROMPT | Override sample user text. |
Full table: packages/sdk/README.md “Environment variables”.
See also
- SDK quickstart
-
chat.messagesandGATEWAY_PLUGINS packages/sdk/README.md