npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rec0ai/rec0

v1.0.0

Published

JavaScript/TypeScript SDK for rec0 memory API

Readme

rec0

Give any AI memory. In one line.

A production-grade JavaScript and TypeScript SDK for rec0. Store durable user memories, recall relevant context, and inject it into any model prompt.

Installation

npm:

npm install rec0

yarn:

yarn add rec0

pnpm:

pnpm add rec0

Quick Start

import { Memory } from 'rec0';

const mem = new Memory({
  userId: 'user_123',
  apiKey: 'r0_live_sk_...',
});

await mem.store('I prefer TypeScript over JavaScript');

const memories = await mem.recall('what are my coding preferences?');
// -> [{ content: 'I prefer TypeScript over JavaScript', relevance_score: 0.94 }]

const context = await mem.context('coding preferences');
// -> "- I prefer TypeScript over JavaScript"

Use with any LLM

import OpenAI from 'openai';
import { Memory } from 'rec0';

const mem = new Memory({
  userId: 'user_123',
  apiKey: process.env.REC0_API_KEY,
});

const openai = new OpenAI();

async function chat(userMessage: string) {
  const context = await mem.context(userMessage);

  const response = await openai.chat.completions.create({
    model: 'gpt-4o-mini',
    messages: [
      {
        role: 'system',
        content: context
          ? `Here is relevant context about the user:\n${context}`
          : 'You are a helpful assistant.',
      },
      { role: 'user', content: userMessage },
    ],
  });

  await mem.store(userMessage);

  return response.choices[0]?.message?.content ?? '';
}

API Reference

Constructor

new Memory(options: MemoryClientOptions)

| Option | Type | Default | Description | |--------|------|---------|-------------| | userId | string | required | Unique user identifier | | apiKey | string | REC0_API_KEY env | Your rec0 API key | | appId | string | "default" | Namespace for memory isolation | | baseUrl | string | https://memorylayer-production.up.railway.app | API base URL | | timeout | number | 10000 | Request timeout in milliseconds | | retry | RetryOptions | defaults below | Retry and backoff strategy | | headers | Record<string, string> | undefined | Extra headers for each request |

RetryOptions

| Field | Type | Default | |-------|------|---------| | maxRetries | number | 3 | | initialDelay | number | 500 | | maxDelay | number | 60000 | | exponentialBase | number | 2 | | jitter | boolean | true |

Methods

1) store

store(content: string): Promise<MemoryObject>

Stores a new memory.

const created = await mem.store('User likes concise answers');
console.log(created.id);

2) recall

recall(query: string, options?: RecallOptions): Promise<MemoryObject[]>

Returns relevant memories sorted by semantic relevance.

const memories = await mem.recall('communication style', {
  limit: 10,
  recallLimit: 40,
  offset: 0,
});

3) context

context(
  query: string,
  options?: Pick<RecallOptions, 'limit' | 'appId'>
): Promise<string>

Returns a bullet-list string ready to inject into prompts.

const context = await mem.context('project goals', { limit: 5 });

4) list

list(options?: ListOptions): Promise<MemoryObject[]>

Lists active memories for the current user.

const allMemories = await mem.list({ limit: 50, offset: 0 });

5) delete

delete(memoryId: string): Promise<void>

Soft-deletes one memory.

await mem.delete('7f9b3f7f-50f6-4f65-bb1c-8c5f40f5c2f0');

6) deleteUser

deleteUser(): Promise<UserDeleteResult>

Deletes all memories for the current user via GDPR erasure endpoint.

const result = await mem.deleteUser();
console.log(result.memories_removed);

7) export

export(): Promise<ExportResult>

Exports all active memories for the current user.

const data = await mem.export();
console.log(data.total_memories);

8) ping

ping(): Promise<boolean>

Checks API health.

if (!(await mem.ping())) {
  console.error('rec0 API unavailable');
}

9) whoami

whoami(): Promise<WhoAmIResult>

Returns account metadata for the API key.

const account = await mem.whoami();
console.log(account.plan, account.ops_limit);

Error Handling

import {
  Memory,
  AuthError,
  RateLimitError,
  NotFoundError,
  ValidationError,
  Rec0Error,
} from 'rec0';

const mem = new Memory({
  userId: 'user_123',
  apiKey: process.env.REC0_API_KEY,
});

try {
  await mem.store('User likes dark mode');
} catch (err) {
  if (err instanceof ValidationError) {
    console.error('Invalid input:', err.message);
  } else if (err instanceof AuthError) {
    console.error('Invalid API key');
  } else if (err instanceof RateLimitError) {
    console.error(`Rate limited. Retry after ${err.retryAfter}s`);
  } else if (err instanceof NotFoundError) {
    console.error('Memory not found');
  } else if (err instanceof Rec0Error) {
    console.error(`rec0 API error (${err.status}):`, err.message);
  } else {
    console.error('Unexpected error:', err);
  }
}

Environment Variables

  • REC0_API_KEY: API key (alternative to passing apiKey in constructor)

Framework Examples

Express.js middleware

import express from 'express';
import { Memory } from 'rec0';

const app = express();
app.use(express.json());

app.post('/chat', async (req, res) => {
  const userId = req.body.userId;
  const message = req.body.message;

  const mem = new Memory({
    userId,
    apiKey: process.env.REC0_API_KEY,
    appId: 'my-express-app',
  });

  const context = await mem.context(message);
  await mem.store(message);

  res.json({ context });
});

Next.js API route

import type { NextApiRequest, NextApiResponse } from 'next';
import { Memory } from 'rec0';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  if (req.method !== 'POST') {
    return res.status(405).json({ error: 'Method not allowed' });
  }

  const { userId, message } = req.body;

  const mem = new Memory({
    userId,
    apiKey: process.env.REC0_API_KEY,
    appId: 'next-api',
  });

  const context = await mem.context(message);
  await mem.store(message);

  return res.status(200).json({ context });
}

LangChain memory adapter

import { Memory } from 'rec0';

export class Rec0LangChainMemory {
  constructor(private readonly mem: Memory) {}

  async loadMemoryVariables(input: { input: string }) {
    const context = await this.mem.context(input.input);
    return { history: context };
  }

  async saveContext(input: { input: string }) {
    await this.mem.store(input.input);
  }
}

Vercel AI SDK

import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { Memory } from 'rec0';

export async function POST(req: Request) {
  const { userId, message } = await req.json();

  const mem = new Memory({
    userId,
    apiKey: process.env.REC0_API_KEY,
    appId: 'vercel-ai',
  });

  const context = await mem.context(message);

  const result = await streamText({
    model: openai('gpt-4o-mini'),
    system: context
      ? `Relevant user context:\n${context}`
      : 'You are a helpful assistant.',
    prompt: message,
  });

  void mem.store(message);

  return result.toDataStreamResponse();
}

Notes

  • Runtime requirement: Node.js 18+ (native fetch required).
  • Authentication uses X-API-Key by default.
  • For browser usage, never expose secret keys to untrusted clients.