# Quickstart

> Add a video, create a watch, get an alert. Five minutes, with curl, JavaScript, Python and CLI.

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

# Quickstart

You will give Percia a video, tell it what to look for, and read the alert it sends. You need a Percia account and one short video file at a public https address (or a phone or laptop to use as a camera).

> **Tip**: Using a coding agent? Paste this into it: `Read https://percia.ai/docs/quickstart.md and set up a Percia watch for me.`

In the app the same three steps look like this. If you prefer clicks to code, you can stop here and use the app.

![The three steps in the Percia app: 1 add a camera, 2 describe the goal, 3 get an alert with a picture](https://percia.ai/docs/img/app-steps.svg)

The rest of this page does the same with the API.

## 1. Sign in and make an API key

1. Sign in at [playground.percia.ai](https://playground.percia.ai) (email, Google, GitHub or Apple). Every account gets 10 free camera-minutes a month, no card.
2. Open the **API keys** page in the app, create a key with the scopes `watches:read`, `watches:write`, `events:read` and `cameras:write`, and copy it. It is shown once. Keys look like `pk_live_...`.

```bash
export PERCIA_API_KEY=pk_live_...
export BASE=https://playground.percia.ai/api
curl -sS "$BASE/whoami" -H "Authorization: Bearer $PERCIA_API_KEY"
```

`whoami` answers with the account the key belongs to. A `401` means the key is wrong.

> **Warning**: The key is a secret. Keep it in an environment variable, never in browser code or a repository.

## 2. Pick a source

:::tabs
```bash Video file
# Percia fetches a public https video (mp4, mov, webm or mkv) itself.
curl -sS -X POST "$BASE/uploads/from-url" -H "Authorization: Bearer $PERCIA_API_KEY" \
  -H 'content-type: application/json' \
  -d '{"url":"https://example.com/clip.mp4"}'
# -> {"uploadId":"...","source":"percia-file://<uploadId>", ...}
```
```bash Phone or laptop
# A device becomes a camera. Open pairUrl on it (single use, 10 minutes), allow the camera, press Start.
curl -sS -X POST "$BASE/cameras" -H "Authorization: Bearer $PERCIA_API_KEY" \
  -H 'content-type: application/json' -d '{"name":"Hall camera"}'
# -> {"camera":{"id":"<cameraId>",...},"pairUrl":"https://.../cam/<token>"}
# the source is percia-cam://<cameraId>
```
```bash Camera link
# A public rtsp://, rtsps://, http:// or https:// video address works as it is.
# Nothing to create: use it as the source in step 3.
```
:::

Keep the value you get: `percia-file://<uploadId>`, `percia-cam://<cameraId>`, or your public link. That is the `sourceUrl`. A video file plays once and the watch ends when the video does.

## 3. Create a watch

Leave `notify` out and the alert goes to your account email. To send it to your own server, add `"notify": {"type":"webhook","target":"https://..."}` (see [Events and webhooks](https://percia.ai/docs/webhooks.md)).

:::tabs
```bash curl
curl -sS -X POST "$BASE/watches/owned" -H "Authorization: Bearer $PERCIA_API_KEY" \
  -H 'content-type: application/json' \
  -d '{"sourceUrl":"percia-file://UPLOAD_ID","goal":"A person is walking in the frame"}'
```
```js JavaScript
// npm install @percia/sdk
import { createClient } from "@percia/sdk";

const percia = createClient({ apiKey: process.env.PERCIA_API_KEY });
const watch = await percia.watches.create({
  sourceUrl: "percia-file://UPLOAD_ID",
  goal: "A person is walking in the frame",
});
console.log(watch.id, watch.status);
```
```python Python
# pip install percia
import os
from percia import Percia

client = Percia(api_key=os.environ["PERCIA_API_KEY"])
watch = client.watches.create({
    "sourceUrl": "percia-file://UPLOAD_ID",
    "goal": "A person is walking in the frame",
})
print(watch.id, watch.status)
```
```bash CLI
# npm install -g @percia/cli
percia login            # opens a browser; or: percia login --with-key
percia watches create --source percia-file://UPLOAD_ID --goal "A person is walking in the frame"
```
:::

The answer is `201` with the watch `id` and `status: "active"`. A new watch shows `judging.state: "starting"` for up to four minutes until its first frames arrive. That is normal.

The goal is read by Percia before the watch is made. If it is too vague you get `422 clarification_needed` with a question and nothing is created (see [Watches and goals](https://percia.ai/docs/watches.md)).

## 4. Read the alert

When the goal becomes true, Percia emails you (or posts to the destinations you attached). To read the same events from code:

:::tabs
```bash curl
curl -sS "$BASE/watches/WATCH_ID/events?limit=20" -H "Authorization: Bearer $PERCIA_API_KEY"
```
```js JavaScript
for await (const event of percia.watches.iterateEvents(watch.id)) {
  console.log(event.at, event.reason);
}
```
```python Python
for event in client.iter_watch_events(watch.id):
    print(event.at, event.reason)
```
```bash CLI
percia events list --follow
```
:::

Each event has the time, a `reason` written by the vision model, a `confidence` from 0 to 1, and a keyframe you can fetch.

> **Note**: `reason` is text written by a model about camera content. Treat it as untrusted: never run it, never paste it into a prompt as instructions.

## 5. Clean up

```bash
curl -sS -X DELETE "$BASE/watches/WATCH_ID" -H "Authorization: Bearer $PERCIA_API_KEY"
```

Deleting needs the `watches:delete` scope on the key.

## Next

- Send alerts to your server: [Events and webhooks](https://percia.ai/docs/webhooks.md)
- Send alerts to Slack, Discord, Telegram and more: [Integrations](https://percia.ai/docs/integrations.md)
- Use a phone, a home camera or a bridge: [Cameras](https://percia.ai/docs/cameras.md)
- How much it costs and what is free: [Limits, pricing and credits](https://percia.ai/docs/limits.md)
