Docs Guides
Live (Beta)
Talk to a live agent about a camera in real time, in the app or from code (REST API and MCP). What Live is, how to start, the six API operations, limits and errors.
Live lets you talk to an agent about what a camera sees, as it happens. You ask a question in words, you get an answer, and you can keep asking. You can also add an alert, such as "Alert me when the oven light turns off", and Percia tells you when it happens.
Two ways to use Live#
| Ask about a watch | Live session | |
|---|---|---|
| What it is | One question to a watch that is already running | A real-time conversation about a camera |
| You get | One answer and a picture | Answers as you talk, and alerts as things happen |
| Camera | The watch's own camera | This device's camera, or one of your cameras |
| Cost | 1 camera-minute | Free during the beta |
| Shown | Only to accounts that have a Live-capable watch | In the Live tab |
When a Live session has an alert, the Make this a watch button turns it into a normal watch, which keeps running after the session ends.
Start a Live session#
- Open the Live tab in the app.
- Choose Connect, then This device's camera or one of your cameras.
- Optional: write an alert, for example "Alert me when the gate is open".
- Choose Start a live session and talk, or type.
- Choose Stop when you are done. A session also ends by itself (see the limits).
If the app says Live is busy, the number of sessions open at the same time across all users has reached a shared cap. Try again in a minute.
Limits#
These caps apply to every account, in the app and through the API. Live is free during the beta: billedMinutes is always 0.
| Limit | Value |
|---|---|
| Length of one session | 600 seconds (10 minutes) |
| Spend per session | USD 10. The engine currently ends a session at USD 5.00, so read endedReason and spendUsd |
| Spend per account per day | USD 50 |
| Idle time before a session ends | 120 seconds (2 minutes) without a question or a poll of the events |
| Open sessions per account | 5 |
| Open sessions across all users | 20 (more answers live_busy, try again in a minute) |
Use Live from code#
You can start and drive a Live session from the REST API or from an AI agent over MCP. A session on a camera is one conversation: start it, ask questions, read answers and alerts, stop it. The session is time-boxed (see the limits) and nothing keeps running after it ends.
What you need#
- A key or a login. An API key with the scopes
watches:write(start, ask, stop) andwatches:read(read sessions and events), or the MCP login. A key with onlycameras:readcannot call these operations. - A camera of yours that is online. These work: a paired phone or laptop, a push camera (for example one the bridge pushes), and a link camera. The camera must be sending video, or the start answers
camera_offline. See Cameras for how to create one. You need the camera's id (GET /cameras). - Not available through the API: "This device's camera" (browser frames) and the "Ask about a watch" source stay in the app. A start on anything but a camera answers
invalid_request.
Walk-through with curl#
The flow is: start, ask until you get an answer, read the events, stop.
export PERCIA_API_KEY=pk_live_...
export BASE=https://playground.percia.ai/api
AUTH="Authorization: Bearer $PERCIA_API_KEY"
# 1. Find your camera id
curl -sS "$BASE/cameras" -H "$AUTH"
# 2. Start a session. alertWhen is optional: "tell me when ..."
curl -sS -X POST "$BASE/live/sessions" -H "$AUTH" -H 'content-type: application/json' \
-d '{"source":{"cameraId":"<cameraId>"},"alertWhen":"a person is at the front door"}'
# -> 201 {"sessionId":"ls_...","status":"open","caps":{...},"capabilities":[...],"alertClips":true,"startedAt":"..."}
export SID=ls_... # the sessionId
# 3. Ask until you get a 200. The session needs 10 to 15 seconds to start: until then the ask
# answers 503 live_starting or 503 live_unavailable (no frame yet). Wait 4 seconds and ask again.
for i in $(seq 1 15); do
CODE=$(curl -sS -o ask.json -w '%{http_code}' -X POST "$BASE/live/sessions/$SID/ask" \
-H "$AUTH" -H 'content-type: application/json' -d '{"question":"What is on the table?"}')
[ "$CODE" = 200 ] && break
echo "ask answered $CODE, retrying in 4 s"; sleep 4
done
cat ask.json
# -> {"answer":"...","keyframeId":"...","keyframeUrl":"https://...","costUsd":0.001}
# 4. Read what happened: answers, alerts, the end. Pass the last seq you saw as after.
curl -sS "$BASE/live/sessions/$SID/events?after=0" -H "$AUTH"
# -> {"events":[{"seq":1,"type":"live.answer","at":"...","text":"..."}, ...]}
curl -sS "$BASE/live/sessions/$SID/events?after=1" -H "$AUTH"
# 5. Stop it. Safe to repeat. Always stop a session you are done with: it frees an open-session slot.
curl -sS -X POST "$BASE/live/sessions/$SID/stop" -H "$AUTH"
# -> {"ended":true,"billedMinutes":0,"spendUsd":0.002}The response bodies above show the field names from the API; the values are examples.
Do not wait for the session to be "running". GET /live/sessions/{id} reports status: "open" for the whole life of a session and never changes to running, so polling it tells you nothing about readiness. Call ask and retry on 503 instead. In real runs the first try answered 503 live_starting after 1 second, then 503 live_unavailable (no frame yet) at about 7 seconds, and the first 200 came 12 to 15 seconds after the start, with 3 to 4 seconds of latency per answer. An ask costs about USD 0.001, and stop returns the session's spendUsd and billedMinutes (0 during the beta).
Keep the session alive. A session with no ask and no poll of the events ends after about 120 seconds with endedReason: "idle". GET /live/sessions/{id} does not count as activity. An ask does, and so does polling GET /live/sessions/{id}/events, so a client that keeps polling the events keeps the session open until the duration or spend cap.
A small loop in JavaScript (Node 18 or later) that starts, retries the ask, reads the events and stops:
const base = "https://playground.percia.ai/api";
const h = { authorization: `Bearer ${process.env.PERCIA_API_KEY}`, "content-type": "application/json" };
const sleep = ms => new Promise(r => setTimeout(r, ms));
const start = await fetch(`${base}/live/sessions`, {
method: "POST", headers: h,
body: JSON.stringify({ source: { cameraId: process.env.CAMERA_ID }, alertWhen: "a person is at the door" }),
}).then(r => r.json());
const id = start.sessionId;
// Ask until it answers 200 (503 live_starting / live_unavailable while it starts)
let answer;
for (let i = 0; i < 15 && !answer; i++) {
const r = await fetch(`${base}/live/sessions/${id}/ask`, { method: "POST", headers: h, body: JSON.stringify({ question: "What is on the table?" }) });
if (r.status === 200) answer = await r.json();
else if (r.status === 503) await sleep(4000);
else throw new Error(`ask failed: ${r.status} ${await r.text()}`);
}
console.log(answer?.answer, answer?.keyframeUrl);
// Read the events (this also keeps the session open), then stop
let after = 0;
for (let i = 0; i < 10; i++) {
const { events } = await fetch(`${base}/live/sessions/${id}/events?after=${after}`, { headers: h }).then(r => r.json());
for (const e of events) { after = e.seq; console.log(e.type, e.text ?? ""); }
await sleep(2000);
}
await fetch(`${base}/live/sessions/${id}/stop`, { method: "POST", headers: h });Troubleshooting#
| You see | What it means | What to do |
|---|---|---|
409 camera_offline on start | The camera is not online. A phone or laptop camera must have its page open and sending. A push camera must also send a heartbeat (see below) | Bring the camera online, check GET /cameras shows online, start again |
503 live_starting on ask | The session is still starting ("Live is still starting") | Ask again in 4 to 5 seconds. Normal for the first 12 to 15 seconds |
503 live_unavailable on ask, "no frame yet" | The session is up but has not received a frame from the camera yet | Ask again in 4 to 5 seconds. If it lasts more than a minute, check the camera is sending video |
429 live_busy | Every Live slot across all users is taken | Wait for Retry-After (about a minute) and start again |
Session ended with endedReason: "idle" | 120 seconds without an ask or a poll of the events | Start a new session. Poll GET /live/sessions/{id}/events, or ask; do not rely on GET /live/sessions/{id} |
409 session_ended on ask | The session is over | Read endedReason from GET /live/sessions/{id}, then start a new one |
Push cameras need a heartbeat#
A push camera (a connector or your own software that publishes video to a camera you created with kind: "push", see Cameras) shows offline about 60 seconds after it connects, even while it keeps publishing. A start on an offline camera answers 409 camera_offline. A connector must call this roughly every 20 seconds with the camera's own token (pc_..., the token returned when the camera was created):
curl -fsS -X POST "https://playground.percia.ai/api/cam/heartbeat" \
-H "Authorization: Bearer $PERCIA_CAMERA_TOKEN"
# -> 204 No Content (no body to send). 401 means the token is wrong.The CLI's percia cameras push run sends it every 20 seconds for you, and paired phone and laptop cameras in the app send it automatically. If you wrote your own connector, add it (see Build your own connector).
With the SDKs#
SDK and CLI 0.5.0 and later have the six Live operations. Install them:
npm i @percia/sdk # JavaScript and TypeScript (CLI: npm i -g @percia/cli)
pip install percia # Python 3.9+The operations are startLiveSession, getLiveSession, listLiveSessions, listLiveSessionEvents, askLiveSession and stopLiveSession. In JavaScript they are on percia.api and return { data, error, response } without throwing; in Python they are in percia._generated.api.live and are called through the client, which raises a typed error on a non-2xx answer.
import { createClient } from "@percia/sdk";
const percia = createClient({ apiKey: process.env.PERCIA_API_KEY });
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
const started = await percia.api.startLiveSession({
body: { source: { cameraId: process.env.CAMERA_ID! }, alertWhen: "a person is at the door" },
});
if (!started.data) throw new Error(`start failed: ${started.response.status}`);
const id = started.data.sessionId!;
try {
// 503 live_starting / live_unavailable while it starts: retry every 4 s
for (let i = 0; i < 15; i++) {
const r = await percia.api.askLiveSession({ path: { id }, body: { question: "What is on the table?" } });
if (r.data) { console.log(r.data.answer, r.data.keyframeUrl); break; }
if (r.response.status !== 503) throw new Error(`ask failed: ${r.response.status}`);
await sleep(4000);
}
} finally {
const stopped = await percia.api.stopLiveSession({ path: { id } });
console.log(stopped.data); // example: { ended: true, billedMinutes: 0, spendUsd: 0.002 }
}import os, time
from percia import Percia, APIError
from percia._generated.api.live import start_live_session, ask_live_session, stop_live_session
from percia._generated.models.start_live_session_body import StartLiveSessionBody
from percia._generated.models.start_live_session_body_source import StartLiveSessionBodySource
from percia._generated.models.ask_live_session_body import AskLiveSessionBody
client = Percia(api_key=os.environ["PERCIA_API_KEY"])
body = StartLiveSessionBody(
source=StartLiveSessionBodySource(camera_id=os.environ["CAMERA_ID"]),
alert_when="a person is at the door",
)
session = client._call(start_live_session, body=body)
sid = session.session_id
try:
for _ in range(15):
try:
r = client._call(ask_live_session, id=sid, body=AskLiveSessionBody(question="What is on the table?"))
print(r.answer, r.keyframe_url)
break
except APIError as e:
if e.status != 503: # 503 live_starting / live_unavailable: wait and ask again
raise
time.sleep(4)
finally:
stopped = client._call(stop_live_session, id=sid)
print(stopped.spend_usd, stopped.billed_minutes) # example: 0.002 0The response values in the comments are examples. The Python call goes through the generated module, so it uses the client's private _call; client.request("POST", f"/live/sessions/{sid}/ask", json={...}) is the public escape hatch for the same route.
The six operations#
| Method and path | operationId | Scope | What it does |
|---|---|---|---|
POST /live/sessions | startLiveSession | watches:write | Start a session on one of your cameras. Body {source: {cameraId}, alertWhen?}. Answers 201 with sessionId, status, caps, capabilities, alertClips, startedAt |
GET /live/sessions | listLiveSessions | watches:read | Your recent sessions, newest first: {sessions: [...]} |
GET /live/sessions/{id} | getLiveSession | watches:read | One session: status (open or ended; never running; not counted as activity), endedReason, secondsOpen, spendUsd, billedMinutes, caps, alerts |
GET /live/sessions/{id}/events | listLiveSessionEvents | watches:read | Events after after (0 or absent = from the start): live.answer, live.item, live.alert, live.budget_warning, live.ended. Poll every 2 seconds; counts as activity |
POST /live/sessions/{id}/ask | askLiveSession | watches:write | Ask a question (question, 1 to 500 characters). Answers {answer, keyframeId, keyframeUrl, costUsd} |
POST /live/sessions/{id}/stop | stopLiveSession | watches:write | Stop now. Answers {ended, billedMinutes, spendUsd} |
Event fields: seq (pass the last one as after), type, at, text (the answer, the alert text, or why it ended), conditionId, keyframeUrl (a picture, JPEG) and clipUrl (a 4 second MP4 clip on an alert). Both links are signed, valid for ten minutes, and need no credential. A session ends with endedReason max_duration, max_spend, idle, user, start_failed or unavailable. After the end, the events answer one live.ended. A session of another account answers 404 not_found. Reads still work while Live is switched off.
Errors#
Every error has the usual body (error.code, error.message; see Errors).
| Status | Code | When |
|---|---|---|
| 400 | invalid_request | No source.cameraId, a source other than a camera, or a question that is not 1 to 500 characters |
| 401 | No key, or a key that is not valid | |
| 403 | insufficient_scope | The key lacks watches:write or watches:read |
| 404 | not_found | No such session of yours |
| 404 | camera_not_found | The camera is not one of yours |
| 409 | camera_offline | The camera is not online. A push camera shows offline about 60 s after it connects unless it sends heartbeats every 20 s |
| 409 | session_ended | You asked in a session that is over (endedReason says why). Start a new one |
| 429 | live_limit | which: open_sessions (5 open), daily_spend (USD 50 a day) or, on an ask, session_spend |
| 429 | live_busy | Every Live slot across all users is taken. Try again in a minute (Retry-After) |
| 503 | live_starting | The session is still starting ("Live is still starting"). Ask again every 4 to 5 seconds; the first answer comes after 12 to 15 s |
| 503 | live_disabled | Live is switched off for now: start and ask are refused. Reads and stop still work |
| 503 | live_unavailable | No frame from the camera yet (ask again in 4 to 5 s), not available on your engine line, or the engine did not start |
How Live differs from a watch#
A watch runs continuously, on its own, and alerts you (email, webhook, Slack, ...) when its goal is met. It is billed by the camera-minute. A Live session is an interactive, time-boxed conversation: you ask, it answers from what the camera sees now, and it can alert you while the session is open. It ends by itself after at most 10 minutes. To keep an alert running after the session, make it a watch (Make this a watch in the app, or POST /watches/owned).
Inside Live, Ask about a watch is one question to a watch that is already running (one answer and a picture, app only), and a Live session is the real-time conversation on a camera that the API starts.
Use Live from an AI agent (MCP)#
In the full MCP, https://playground.percia.ai/mcp, the agent finds the Live operations by searching the API with its search tool (try "live session") and calls them with execute. You do not need to reconnect. If an agent that was already connected does not see them, start a new chat. Live is not in the Claude directory edition (/mcp/directory) or the ChatGPT edition (/mcp/chatgpt) yet. See AI agents for setup.
A prompt that works: "Start a Live session on my front-door camera, ask what is by the door, tell me when a person arrives, and stop the session when I say so."
Privacy#
During a session, frames and clips from the camera go to Google's Gemini API to be understood. They are kept like the images of other alerts. The authoritative statement is the privacy notice. Tell the people your camera can see that they are recorded.
Status#
Live is a beta. Answers can be wrong, so do not use it for anything where a wrong answer could hurt someone.
The Live API and MCP operations are in the beta too: the caps, the fields and the error codes can change.
Stuck? Ask in the Percia Discord or email support@percia.ai. This page as Markdown: live.md.