> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.recursiv.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.recursiv.io/_mcp/server.

# Connect Node.js

The `@recursiv/sdk` is a zero-dependency TypeScript SDK that runs server side in Node.js. This is the most direct way to script Recursiv, run backend services, or build agent workers.

## Requirements

* Node.js 18 or newer.
* An ESM project (`"type": "module"` in `package.json`) for the import syntax below.

## Install

```bash
npm install @recursiv/sdk
```

## Configure the key

No account yet? [Sign up](https://recursiv.io/register) and mint a key at [recursiv.io/account/api-keys](https://recursiv.io/account/api-keys).

```bash
export RECURSIV_API_KEY=sk_live_...
```

The SDK reads `RECURSIV_API_KEY` automatically:

```typescript
import { Recursiv } from '@recursiv/sdk';

const r = new Recursiv();
```

Or pass it explicitly with `new Recursiv({ apiKey })`.

## First authenticated call

Most resources hang off a project. Create one, then run a query. Project IDs are UUIDs, so always use the `id` the API returns. Project-scoped calls return a `{ data }` envelope.

```typescript
import { Recursiv } from '@recursiv/sdk';

const r = new Recursiv();

const { data: project } = await r.projects.create({ name: 'my-app' });

await r.databases.ensure({ project_id: project.id, name: 'main' });

const { data: result } = await r.databases.query({
  project_id: project.id,
  sql: 'SELECT NOW() as time',
});

console.log(project.id);
console.log(result.rows);
```

## Run and stream an agent

Create an agent against any model, then stream its replies. In Node, `chatStream()` returns an async iterable of `{ delta }` chunks.

```typescript
import { Recursiv } from '@recursiv/sdk';

const r = new Recursiv();

const { data: agent } = await r.agents.create({
  project_id: project.id,
  name: 'Support Bot',
  model: 'anthropic/claude-sonnet-4.6',
  system_prompt: 'You are a helpful assistant.',
});

for await (const chunk of r.agents.chatStream(agent.id, {
  message: 'Help me build a landing page',
})) {
  process.stdout.write(chunk.delta ?? '');
}
```

The `model` field is model agnostic. Pass any supported model id.

## Run code in a sandbox

Node workers often need to execute generated code safely. The sandbox returns a `{ data, meta }` envelope.

```typescript
const { data } = await r.sandbox.execute({
  code: 'console.log(1 + 1)',
  language: 'typescript',
});

console.log(data.output); // "2\n"
```

## Where to go next

* [Quickstart](/guides/start-here/quickstart) for the full set of first calls
* [Add AI Agents to Node.js](/recipes/cookbook/agents) for agent details
* [Add Authentication to Node.js](/recipes/cookbook/apps) for minting scoped keys
* [API Reference](/api-reference) for the full REST surface
* Recursiv ships hundreds of data integrations (Slack, email, databases, and more) that agents can call as tools