TypeScript SDK
Call your tasks from TypeScript with a generated, type-safe client.
The Rightbrain SDK adds your tasks to a TypeScript or JavaScript app as fully typed functions. The rightbrain CLI generates a client from the tasks in your project, so inputs and outputs are checked at compile time — no manual schema handling.
Use the SDK for TypeScript, Node, and Next.js apps. For other languages, or lightweight backend scripts, call the REST API directly.
Install
The published package is @rightbrain/sdk.
Prerequisites: Node.js 18+, a package manager, and a Rightbrain project.
Generate the typed client
The rightbrain CLI handles credentials and code generation in one flow — no manual setup:
login authenticates you, then init creates an API key for the project, writes your credentials to .env automatically, and generates typed task runners in src/generated/index.ts. Each task in your project becomes a typed method, with an interface for its inputs and its structured output.
The environment variables the CLI populates (and the transport reads):
DirectTransport also accepts a config object for additional fetch options. If you’d rather manage credentials yourself, see Authentication.
Choose a transport
The SDK talks to Rightbrain through a transport:
DirectTransport— server-side (Node, route handlers, scripts). Holds your API key and calls Rightbrain directly.PublicTransport— client-side (browser). Routes calls through your own backend so the API key never reaches the browser.
Never ship an API key to the browser. In client-side code use PublicTransport and proxy the request through a server route that holds the key.
Next.js example
A server route handler uses DirectTransport and the generated Client, then your UI calls that route.
Each task is addressed by its ID on the client, and run({ inputs }) returns the typed result — result.response holds the task’s structured output.
A minimal React hook that calls the route:
This hook is deliberately minimal and tied to one route. For a production-grade generic hook — pass it any task function and get typed data/error/isPending state plus request-abort handling — use use-task.ts from the SDK demo, which works with every task the generated client exposes.
Use it in a component:
Demo app
The Rightbrain SDK demo is a working Next.js app. It shows DirectTransport in a server route, PublicTransport in the browser, and a standalone Node script — each running real tasks that appear in your dashboard’s Runs view.