---
name: fishjam-js-server-sdk
description: "Node.js / TypeScript server SDK for Fishjam — backends that create rooms, mint peer tokens, listen to server notifications, and run agents. Use when writing a Node.js / Express / Fastify / Hono / NestJS backend that talks to Fishjam, sets up a webhook receiver, runs an AI agent, generates livestream tokens, or composes streams. Trigger on: '@fishjam-cloud/js-server-sdk', 'FishjamClient', 'FishjamWSNotifier', 'FishjamAgent', 'createPeer', 'createRoom', 'createAgent', 'createVapiAgent', 'createLivestreamStreamerToken', 'createLivestreamViewerToken', 'refreshPeerToken', 'subscribeTracks', 'subscribePeer', 'createMoqToken', 'ServerMessage', 'roomCreated', 'peerAdded', 'trackAdded', 'fishjam backend Node', 'express fishjam', 'fastify fishjam', 'gemini agent fishjam', 'vapi fishjam', 'CompositionClient', 'createComposition', 'forwardRoomTracks'. Covers REST, WebSocket notifier, webhook protobuf decoding, FishjamAgent, Gemini Live integration, and CompositionClient."
license: MIT
title: fishjam-js-server-sdk
canonical_url: https://skilld.dev/gh/software-mansion-labs/skills/js-server-sdk
last_updated: 2026-10-16T07:01:46.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [agent.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/js-server-sdk/agent.md), [client.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/js-server-sdk/client.md), [composition.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/js-server-sdk/composition.md), [express-fastify.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/js-server-sdk/express-fastify.md), [gemini-integration.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/js-server-sdk/gemini-integration.md), [livestream-and-moq.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/js-server-sdk/livestream-and-moq.md), [selective-subscriptions.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/js-server-sdk/selective-subscriptions.md), [webhooks.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/js-server-sdk/webhooks.md), [ws-notifier.md](https://skilld.dev/api/skills-raw/software-mansion-labs/skills/js-server-sdk/ws-notifier.md).
>
> If the user asked to install this Skill, run `npx skilld install software-mansion-labs/skills/js-server-sdk`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/js-server-sdk`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/software-mansion-labs/skills/js-server-sdk) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/js-server-sdk`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/js-server-sdk --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/js-server-sdk --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Fishjam JS Server SDK

`@fishjam-cloud/js-server-sdk` — server-side Node.js / TypeScript SDK for the Fishjam platform.

> **Read `../platform/SKILL.md` first.** It defines rooms, peers, tracks, management tokens, peer tokens, and the WS-vs-webhook tradeoff that this skill builds on.

## Four components

| Component | What it does | Reference |
|---|---|---|
| `FishjamClient` | REST client — rooms, peers, agents, livestream/MoQ tokens, subscribe modes. | `client.md` |
| `FishjamWSNotifier` | Subscribes to all 18 server events over a single WebSocket. Best for long-lived workers. | `ws-notifier.md` |
| `FishjamAgent` | Programmatic peer — sends/receives audio frames over a server-side WS. Used for AI agents (Gemini, custom). | `agent.md` |
| `CompositionClient` | Compositions: register inputs and outputs, deploy templates, send events. Concepts in `../composition/SKILL.md`. | `composition.md` |

Webhook receivers are not a class — you decode `ServerMessage` protobuf yourself; covered in `webhooks.md`.

## Install + minimal flow

```bash
npm install @fishjam-cloud/js-server-sdk
# or yarn add @fishjam-cloud/js-server-sdk
```

```ts
import { FishjamClient } from '@fishjam-cloud/js-server-sdk';

const fishjamClient = new FishjamClient({
  fishjamId: process.env.FISHJAM_ID!,
  managementToken: process.env.FISHJAM_MANAGEMENT_TOKEN!,
});

const room = await fishjamClient.createRoom();
const { peer, peerToken } = await fishjamClient.createPeer(room.id, {
  metadata: { userId: 'user-123' },
});
// ship `peerToken` to your client
```

## When to read which reference

| Task | Reference |
|---|---|
| Call any REST method (rooms, peers, subscribe, refresh) | `client.md` |
| Subscribe to server events from a long-lived worker | `ws-notifier.md` |
| Receive events from a serverless / scaled-out backend | `webhooks.md` |
| Build an AI voice agent (audio in/out, image capture) | `agent.md` |
| Wire a Gemini Live agent into a room | `gemini-integration.md` |
| Wire all of this into Express or Fastify | `express-fastify.md` |
| Issue livestream streamer/viewer tokens or MoQ tokens | `livestream-and-moq.md` |
| Use manual subscribe mode (cost / privacy / staging) | `selective-subscriptions.md` |
| Compose streams: `CompositionClient` calls, forwarding a room | `composition.md` |

## Key rules

- **One `FishjamClient` per process.** It's a thin axios wrapper — share, don't recreate per request.
- **Catch SDK exceptions, not axios errors.** All methods wrap REST calls in `mapException`, throwing typed errors (`BadRequestException` 400, `UnauthorizedException` 401, `RoomNotFoundException` / `PeerNotFoundException` / `FishjamNotFoundException` 404, `ServiceUnavailableException` 503, `UnknownException` for anything else — including 403). All inherit from `FishjamBaseException`, which is useful for a catch-all `instanceof` branch. `ForbiddenException` is exported but never produced by the current mapper. Match on these to map to HTTP status codes. Constructor also throws `MissingFishjamIdException` synchronously if `fishjamId` is falsy.
- **Management token stays in the backend.** Never put it in `NEXT_PUBLIC_*`, `VITE_*`, or any bundled env. If exposed, regenerate from the Dashboard.
- **Deprecation header.** The client logs `x-fishjam-api-deprecated` once per process. If you see it, plan a migration — don't silence it.
- **`FishjamWSNotifier` does NOT auto-reconnect.** The constructor opens one WS; if it closes, you must reinstantiate. Wrap it in a supervisor or use webhooks instead.
- **Peer tokens are valid for 24 hours from creation.** The token is consumed during the initial WS handshake; an established session keeps running on its own and isn't dropped when the token's wall-clock expiry passes. If the peer hasn't connected yet, or needs to *reconnect* after the 24h window, call `refreshPeerToken` to mint a new one and ship it to the client.

## References

| File | When to read |
|---|---|
| `client.md` | The REST surface — every method on `FishjamClient` with signatures and examples. |
| `ws-notifier.md` | `FishjamWSNotifier` wiring, the 18 events, reconnection patterns. |
| `webhooks.md` | Decoding `application/x-protobuf` webhook bodies with `ServerMessage.decode`. |
| `agent.md` | `FishjamAgent` — opus/pcm16, `createTrack`, `sendData`, `captureImage`, `interruptTrack`. |
| `gemini-integration.md` | `@fishjam-cloud/js-server-sdk/gemini` — `createClient`, audio settings, end-to-end demo. |
| `express-fastify.md` | Production wiring — `/api/join-room`, error mapping, webhook routes, Fastify plugin. |
| `livestream-and-moq.md` | `createLivestreamStreamerToken`, `createLivestreamViewerToken`, `createMoqToken`. |
| `selective-subscriptions.md` | `subscribePeer` / `subscribeTracks` with peers created using `subscribeMode: 'manual'`. |
| `composition.md` | `CompositionClient`: compositions, inputs, outputs, templates, events, exceptions. |
