> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sublay.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Node.js SDK

> Server-side SDK for Sublay — use in backend APIs, server actions, webhooks, and scheduled jobs

The `@sublay/node` SDK gives you full programmatic access to the Sublay API from any Node.js environment. It is designed for **server-side use only** — backend endpoints, Next.js server actions, webhook handlers, cron jobs, and scripts.

> [!NOTE]
>
> This SDK requires a **secret API key** and must never be used in client-side
> code or shipped to the browser.

## Installation

```bash theme={null}
npm install @sublay/node
```

## Initialization

Create a single `SublayClient` instance at startup and reuse it throughout your application.

```typescript theme={null}
import { SublayClient } from "@sublay/node";

const sublay = await SublayClient.init({
  projectId: process.env.SUBLAY_PROJECT_ID!,
  apiKey: process.env.SUBLAY_API_KEY!,
});
```

### Configuration

**projectId** `string` *required*

Your Sublay project ID, found in the dashboard under **Settings → General**.

**apiKey** `string` *required*

Your secret API key from the dashboard. Keep this in an environment variable —
never commit it to source control.

## Modules

Once initialized, all functionality is accessed through module namespaces on the client:

```typescript theme={null}
sublay.auth              // Authentication — sign up, sign in, tokens, passwords
sublay.users             // User profiles, follow/connection actions
sublay.entities          // Content entities — CRUD, reactions, drafts
sublay.comments          // Comments — CRUD, reactions
sublay.collections       // Saved-content collections
sublay.follows           // Follow graph — followers, following, counts
sublay.connections       // Mutual connections and requests
sublay.spaces            // Spaces — management, members, moderation, rules
sublay.events            // Events — RSVPs, hosts, invites, guest list
sublay.chat              // Conversations, messages, members, reactions, read state
sublay.search            // Search and AI Q&A
sublay.reports           // Content reports and the moderation queue
sublay.appNotifications  // In-app notification feed
sublay.storage           // File and image uploads, read, delete
```

## Acting on behalf of a user

Your service key authenticates as the project, not as any single end user. So functions that operate **on a user's behalf** take an explicit `userId` — the named user the action is performed as (saving to a collection, reading a notification feed, filing a report, listing connections).

A few routes — on the `users` module (following someone, requesting a connection) and on `chat` (`createDirectConversation`, `addMember`, `removeMember`, `changeMemberRole`) — act on one user toward another. There the **target** is `userId` and the **actor** is passed separately as `actingUserId`.

> [!NOTE]
>
> `oauth` is intentionally not exposed by this SDK (it's a browser redirect flow).

> [card] [Auth](https://docs.sublay.io/v7/node-sdk/auth.md)
>
> Sign up, sign in, token management, password reset

> [card] [Users](https://docs.sublay.io/v7/node-sdk/users.md)
>
> Fetch, update and delete profiles, follow and connection actions

> [card] [Entities](https://docs.sublay.io/v7/node-sdk/entities.md)
>
> Create and manage content, reactions, drafts

> [card] [Comments](https://docs.sublay.io/v7/node-sdk/comments.md)
>
> Create and manage comments, reactions

> [card] [Collections](https://docs.sublay.io/v7/node-sdk/collections.md)
>
> Organize a user's saved entities into collections

> [card] [Follows](https://docs.sublay.io/v7/node-sdk/follows.md)
>
> Read a user's follow graph and counts

> [card] [Connections](https://docs.sublay.io/v7/node-sdk/connections.md)
>
> Mutual connections, pending requests, accept/decline

> [card] [Spaces](https://docs.sublay.io/v7/node-sdk/spaces.md)
>
> Space CRUD, navigation, slug management

> [card] [Space Members](https://docs.sublay.io/v7/node-sdk/spaces-members.md)
>
> Membership, roles, approvals, bans

> [card] [Space Moderation](https://docs.sublay.io/v7/node-sdk/spaces-moderation.md)
>
> Reports, content moderation, rules

> [card] [Chat](https://docs.sublay.io/v7/node-sdk/chat.md)
>
> Conversations, messages, members, reactions, read state

> [card] [Search](https://docs.sublay.io/v7/node-sdk/search.md)
>
> Full-text search and AI-powered Q\&A

> [card] [Reports](https://docs.sublay.io/v7/node-sdk/reports.md)
>
> File content reports and read the moderation queue

> [card] [App Notifications](https://docs.sublay.io/v7/node-sdk/app-notifications.md)
>
> Read and mark a user's in-app notifications

> [card] [Storage](https://docs.sublay.io/v7/node-sdk/storage.md)
>
> Upload, fetch, and delete files and images

## Paginated Responses

Functions that return lists use a shared `PaginatedResponse<T>` shape:

```typescript theme={null}
{
  data: T[];
  pagination: {
    page: number;
    pageSize: number;
    totalPages: number;
    totalItems: number;
    hasMore: boolean;
  };
}
```

Pass `page` and `limit` to any list function to control pagination.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.