@roadie/sdk.
Every snippet below is executed in CI against a live gateway; the runnable sources are in
documentation/docs/snippets/node/.
Prefer to keep your existing OpenAI code? Point the official OpenAI SDK at Roadie instead — see
the OpenAI drop-in quickstart.
1. Prerequisites
In the dashboard:- Create a project (its
developmentandproductionenvironments are created for you). - Add and validate a provider credential (your OpenAI or Anthropic key — BYOK). See Providers & BYOK.
- Create a secret key (
rd_sk_…) for the environment you want to call.
2. Install
3. Construct the client
Create the client once and reuse it. ProvidebaseUrl only if you target a specific gateway
host (self-hosted or regional); otherwise the default hosted gateway
() is used.
snippets/node/client.ts
4. Send a chat completion
roadie.chat.create returns the normalized response: the assistant message, finish_reason,
token usage, an estimated cost, and the gateway requestId.
snippets/node/chat.ts
5. Stream the response
Iterate the async-iterable stream withfor await. content_delta events carry incremental
text; the terminal message_end event carries the final usage and cost.
snippets/node/stream.ts
AbortSignal to cancel a stream (or any call); NDJSON framing is available via
{ framing: 'ndjson' }. See Streaming.
6. Create embeddings
snippets/node/embeddings.ts
7. Handle typed errors
Every failure is aRoadieError subclass with a stable code, the requestId, the HTTP
status, and (for rate limits) retryAfter. Branch on the class.
snippets/node/errors.ts
429, 5xx) before they reach
you, honoring Retry-After. See Errors & retries and the
full error reference.
Next steps
Next.js quickstart
Wrap the SDK in a server-side route.
OpenAI drop-in
Keep the OpenAI SDK — change only the base URL and key.
Rate limits, quotas & budgets
Cap spend and usage before it happens.
curl / REST quickstart
The raw HTTP contract, SSE streaming included.