# The SDK

> @sypnia/app: the App API from TypeScript, with streaming sessions.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://app.docs.sypnia.com/tools/sdk/

For agents: @sypnia/app (MIT, Node 20+, browsers, Deno/Bun): createApp({ token?, baseUrl? }) — token from SYPNIA_APP_TOKEN or the shared CLI session. Namespaces: me, orgs (list, members, invite), projects (list, create, get, board), sessions (list, create, get, send → async iterator of events: text, question, approval, panel, task, done), credits (balance, ledger({ group, from, to, project }), topUp({ amount } USD, at least 5) → { approvalUrl } for a person to pay), limits (get, set), notifications (list, read). Errors: AppError with code, status, message. Never put a token in a browser bundle: in the browser the SDK uses the person's Sypnia session cookie.

```bash
npm install @sypnia/app
```

`board.ts`

```ts
import { createApp } from '@sypnia/app';

const app = createApp({ token: process.env.SYPNIA_APP_TOKEN });

const board = await app.projects.board('laespiga');
console.log(board.health.state);      // 'healthy'
console.log(board.domain.renewsOn);   // '2027-11-18'
```

## A session, streamed

`ask.ts`

```ts
const session = await app.sessions.create({ project: 'laespiga', title: 'Morning check' });

for await (const event of app.sessions.send(session.id, 'How is it going?')) {
  if (event.type === 'text') process.stdout.write(event.text);
  if (event.type === 'question') console.log('\n', event.question, event.options);
}
```

Events: `text`, `question`, `approval`, `panel` (what the side panel would open), `task` (a task started, progressed or ended) and `done`. An approval can be read, but only a person can answer it, in App.

## Credits

```ts
const { balance, held } = await app.credits.balance();
const rows = await app.credits.ledger({ project: 'laespiga', group: 'case', from: '2026-11-01' });
const { approvalUrl } = await app.credits.topUp({ amount: 20 }); // USD, at least 5; a person opens it and pays with PayPal
```

## Errors

Every error is an `AppError` with `code`, `status` and `message`, the same codes as the [API](https://app.docs.sypnia.com/api).

## In the browser

In a browser, the SDK uses the person's Sypnia session and never needs a token. Never put a token in code that reaches a browser.
