---
title: JavaScript
description: Publish and manage content from Node or the browser
---

> **For AI agents:** the complete documentation index is at [llms.txt](/llms.txt). Append `.md` to any page URL for its markdown version.

The JavaScript SDK works in Node 18+ and modern browsers. It ships with TypeScript types out of the box.

## Install

<CodeGroup>
```bash npm
npm install @firmreader/sdk
```

```bash yarn
yarn add @firmreader/sdk
```

```bash pnpm
pnpm add @firmreader/sdk
```
</CodeGroup>

## Initialize the client

```javascript
import { Firmreader } from "@firmreader/sdk";

const client = new Firmreader({
  apiKey: process.env.FIRMREADER_API_KEY, // fr_live_...
});
```

## Create a post

```javascript
const post = await client.posts.create({
  channelId: "ch_company_news",
  title: "Welcome to Firmreader",
  body: "We're excited to announce our new internal communications platform.",
  priority: "normal",
});

console.log(`Published post ${post.id}`);
```

## List posts

```javascript
const { data: posts } = await client.posts.list({
  channelId: "ch_company_news",
  limit: 20,
});

for (const post of posts) {
  console.log(post.title);
}
```

## Handle errors

The client throws `FirmreaderError` for non-2xx responses. Inspect `status` and `code` to branch on the failure.

```javascript
import { FirmreaderError } from "@firmreader/sdk";

try {
  await client.posts.create({ channelId: "ch_invalid", title: "Hi", body: "..." });
} catch (err) {
  if (err instanceof FirmreaderError) {
    console.error(`${err.status}: ${err.code}`);
  }
}
```

<Note>
All write methods are idempotent when you pass an `idempotencyKey` option, so retries won't create duplicate posts.
</Note>
