# SDKs and CLI

> Install the JavaScript and Python SDKs and the percia command line, sign in, and see what each one covers.

Page: https://percia.ai/docs/sdks. Index of all docs pages: https://percia.ai/docs/llms.txt

# SDKs and CLI

All three are open source (MIT), generated from the same OpenAPI document as the [API reference](https://percia.ai/docs/api.md), and live in [github.com/percia-ai/percia-sdks](https://github.com/percia-ai/percia-sdks).

| | Install | Package |
|---|---|---|
| JavaScript and TypeScript | `npm install @percia/sdk` | [@percia/sdk](https://www.npmjs.com/package/@percia/sdk) (latest) |
| Python 3.9+ | `pip install percia` | [percia](https://pypi.org/project/percia/) (latest) |
| Command line | `npm install -g @percia/cli` | [@percia/cli](https://www.npmjs.com/package/@percia/cli) (latest) |

## Sign in

:::tabs
```js JavaScript
import { createClient } from "@percia/sdk";

const percia = createClient({ apiKey: process.env.PERCIA_API_KEY }); // pk_live_...
// or an OAuth token: createClient({ oauthToken })
console.log(await percia.account.whoami());   // connection test
```
```python Python
import os
from percia import Percia

client = Percia(api_key=os.environ["PERCIA_API_KEY"])   # or set PERCIA_API_KEY
print(client.account.whoami())                           # connection test
# AsyncPercia is the async version with the same methods
```
```bash CLI
percia login              # browser sign-in (OAuth with PKCE)
percia login --with-key   # or paste an API key at a hidden prompt
PERCIA_API_KEY=pk_live_... percia whoami   # CI: the environment wins
percia doctor             # checks your setup
```
:::

The default API address is `https://playground.percia.ai`. Override it with `baseUrl` (JavaScript), `base_url` or `PERCIA_BASE_URL` (Python).

## Common jobs

:::tabs
```js JavaScript
// create, test, read, pause, delete
const watch = await percia.watches.create({
  sourceUrl: "rtsp://cam.example.com/stream",
  goal: "A person is standing at the front door",
  notify: { type: "webhook", target: "https://example.com/hooks/percia" },
});
await percia.watches.testDelivery(watch.id);
for await (const e of percia.events.iterate({ type: "goal.met" })) console.log(e.at, e.reason);
await percia.watches.pause(watch.id);
await percia.watches.delete(watch.id);

// plan and free minutes
console.log(await percia.account.billing());
```
```python Python
watch = client.watches.create({
    "sourceUrl": "rtsp://cam.example.com/stream",
    "goal": "A person is standing at the front door",
    "notify": {"type": "webhook", "target": "https://example.com/hooks/percia"},
})
client.watches.test_delivery(watch.id)
for e in client.iter_events(type="goal.met"):
    print(e.at, e.reason)
client.watches.pause(watch.id)
client.watches.delete(watch.id)
```
```bash CLI
percia plan                                  # free minutes left, credits, how you are charged
percia watches list
percia watches create --source rtsp://cam.example.com/stream --goal "A person is at the door" --email me@example.com
percia events list --follow                  # new events as they arrive
percia cameras add "Hall phone"              # link and QR; then --source percia-cam://<id>
percia destinations connect slack            # prints a link a person approves
percia listen --forward-to http://localhost:3000/hook
percia cameras push run --rtsp rtsp://user:pass@192.168.1.20/stream1   # needs ffmpeg 7.1+
percia mcp setup claude-code
```
:::

The CLI prints JSON with `--json`, exits with a code per kind of failure (3 not signed in or missing scope, 4 not found, 5 rate or plan limit, 6 network, 7 server), and shows each secret once.

## What they cover

The SDKs include retries, typed errors, pagination, webhook signature checking and an event stream. The latest SDK and CLI releases (0.5.0 and later) cover all 171 operations in the API, including the six [Live](https://percia.ai/docs/live.md#with-the-sdks) operations, generated from the same OpenAPI document. If a call from the [API reference](https://percia.ai/docs/api.md) is missing in the version you installed, update the package or call the HTTP API directly.

In JavaScript every covered operation is also available by its `operationId` as `percia.api.<operationId>(options)`, which returns `{ data, error, response }` without throwing. `percia.raw` is the generated client.

## Postman and examples

- A Postman collection, environment and an Insomnia export are in the repository's `postman/` folder.
- `examples/` has webhook receivers (Express, Cloudflare Workers, FastAPI, Go, Ruby), a Slack script, a voice alert and a GitHub Actions example.
