Installation & Configuration

Zero dependencies. Native fetch. ESM-only. Full TypeScript types.

Install

$npm install @recursiv/sdk

Requirements:

  • Node.js >= 18 (uses native fetch)
  • ESM only ("type": "module" in your package.json)
  • Zero dependencies

Quick start

1import { Recursiv } from '@recursiv/sdk';
2
3const r = new Recursiv();
4
5const { data: projects } = await r.projects.list();
6console.log(projects);

The zero-argument constructor reads your API key from the RECURSIV_API_KEY environment variable. No configuration file needed.

Configuration options

OptionTypeDefaultDescription
apiKeystringprocess.env.RECURSIV_API_KEYYour API key. Falls back to SOCIAL_DEV_API_KEY for backwards compatibility.
baseUrlstringhttps://api.recursiv.io/api/v1API base URL. Change this for self-hosted instances.
timeoutnumber30000Request timeout in milliseconds.
maxRetriesnumber2Number of retries on 429 and 5xx errors. Set to 0 to disable.
anonymousbooleanfalseEnable anonymous mode (no API key required, limited to sandbox).

Explicit configuration

1import { Recursiv } from '@recursiv/sdk';
2
3const r = new Recursiv({
4 apiKey: 'sk_live_...',
5 baseUrl: 'https://api.recursiv.io/api/v1',
6 timeout: 30000,
7 maxRetries: 2,
8});

Anonymous mode

For the anonymous sandbox (code execution without an account), pass anonymous: true. No API key is needed. Rate limited to 10 executions per day per IP.

1import { Recursiv } from '@recursiv/sdk';
2
3const r = new Recursiv({ anonymous: true });
4
5const { data, meta } = await r.sandbox.execute({
6 code: 'console.log(1 + 1)',
7 language: 'typescript',
8});
9console.log(data.output); // "2\n"
10console.log(`${meta.remaining_executions} executions remaining today`);

Self-hosted mode

Point the SDK at your own Recursiv instance:

1const r = new Recursiv({
2 apiKey: 'sk_live_...',
3 baseUrl: 'https://my-instance.example.com/api/v1',
4});

Environment matrix

The SDK uses the standard fetch API and works in any JavaScript runtime that supports it.

EnvironmentStatusNotes
Node.js >= 18Fully supportedNative fetch, no polyfills needed.
Next.jsFully supportedWorks in API routes, server components, middleware, and client components.
ReactFully supportedUse in useEffect or data-fetching libraries.
React Native / ExpoSupported with caveatsCore SDK works. chatStream() does not work due to missing ReadableStream. See the React Native guide for the workaround.
DenoFully supportedImport via npm:@recursiv/sdk.
BunFully supportedNative ESM and fetch support.
BrowserFully supportedBundle with Vite, esbuild, or webpack. API key should come from a backend proxy in production.

Node.js

1// Set your API key in the environment
2// RECURSIV_API_KEY=sk_live_... node index.mjs
3
4import { Recursiv } from '@recursiv/sdk';
5const r = new Recursiv();

Next.js (Server Component)

1import { Recursiv } from '@recursiv/sdk';
2
3export default async function Page() {
4 const r = new Recursiv();
5 const { data: projects } = await r.projects.list();
6
7 return (
8 <ul>
9 {projects.map((p) => (
10 <li key={p.id}>{p.name}</li>
11 ))}
12 </ul>
13 );
14}

Next.js (API Route)

1import { Recursiv } from '@recursiv/sdk';
2import { NextResponse } from 'next/server';
3
4export async function GET() {
5 const r = new Recursiv();
6 const { data: projects } = await r.projects.list();
7 return NextResponse.json(projects);
8}

Deno

1import { Recursiv } from 'npm:@recursiv/sdk';
2
3const r = new Recursiv();
4const { data: me } = await r.users.me();
5console.log(me);

Bun

1import { Recursiv } from '@recursiv/sdk';
2
3const r = new Recursiv();
4const { data: me } = await r.users.me();
5console.log(me);

API key security

Never expose your API key in client-side code shipped to browsers. For browser-based apps, proxy requests through your backend:

1// Backend (Node.js / Next.js API route)
2import { Recursiv } from '@recursiv/sdk';
3
4const r = new Recursiv(); // reads RECURSIV_API_KEY from server env
5
6export async function GET(req: Request) {
7 const { data } = await r.posts.list({ limit: 20 });
8 return Response.json(data);
9}

Auto-retry behavior

The SDK automatically retries failed requests when it receives:

  • 429 Too Many Requests — respects the Retry-After header if present
  • 5xx Server Errors — transient server failures

Retries use exponential backoff: 1s, 2s, 4s, … capped at 10s. The maxRetries option controls how many retries are attempted (default: 2).

1// Disable retries entirely
2const r = new Recursiv({ maxRetries: 0 });
3
4// More aggressive retries
5const r = new Recursiv({ maxRetries: 5 });