# Camly API: all guides > Camly takes you from cameras to events: connect cameras, say what to watch in plain words, receive signed webhooks when something happens. The building block is one call: a picture and a question in, a structured JSON verdict out. Developer API, open by invitation. API contract: https://api.camly.ai/v1/openapi.json You are integrating the Camly API: from cameras to events. Connect a camera, attach a monitor (a saved agent, a schedule, incident rules), receive signed webhooks. Underneath, one call: send a picture and a question, get a structured answer. Read the contract first, it is public and complete: https://api.camly.ai/v1/openapi.json All the guides, as plain text: https://platform.camly.ai/llms-full.txt Base URL: https://api.camly.ai Rules: - Authenticate with the header Authorization: Bearer . Read the key from the CAMLY_API_KEY environment variable; never write it in code or send it to a browser. - Build and test with a test key (cmly_sk_test_...): free, and the same picture always gives the same answer. Live keys (cmly_sk_live_...) are charged per check. - POST /v1/runs takes a picture and either an inline config or a saved agent id. The answer is in result.flagged. - result.confidence and config.threshold are on the same scale, from 0 to 1. - Points and zones are [x, y] from 0 to 1, from the top-left corner of the picture. - On 429, wait for the seconds in Retry-After. A 502 is not charged: retry with a growing pause. - Send an Idempotency-Key header so a retry after a timeout is charged once. - Do not retry 401, 402, 403, 404 or 422: fix the key, the balance or the request. - POST /v1/cameras/{id}/frames sends a picture to a camera's monitors; next_frame_seconds in the reply says when to send the next one. - GET /v1/runs lists past checks, newest first, with ?monitor=, ?camera=, ?agent=, ?from=, ?to= and ?before=run_...; it needs a Full access key. - Check the Camly-Signature header of every webhook, over the raw body, and deduplicate on the event id: delivery is at least once. - Find (type "find"): items [{item?: library key, description?, count}] (1-5), together, question = extra condition; past only (look-back, pictures requests, POST /v1/runs), never monitors. Result: items[{seen, wanted, found, boxes}], found_all, score 0-1. Library: POST /v1/items {key, name, description}; references per camera from picker circles or POST /v1/items/{key}/references. Look-back results: "best" + top 1-5 returns ranked matches. Proves items were there, not which order. - To let a person choose a past picture: POST /v1/cameras/{id}/pictures with from, to (max 6 h) and max_pictures (1-60, default 30); on pictures.ready show the small_url pictures (fetched with the key, server side), then POST /v1/pictures/{id}/{picture}/keep and, on picture.kept, GET /v1/pictures/{id}/{picture} for the full picture. EUR 0.01 per request, keeping is free. With no screen of your own: POST /v1/cameras/{id}/picker with from, to, title (and reference, from_name, locale en|fr) returns a url (shown once, 24 h, one choice) to send to the person on site; picker.chosen brings chosen.full.url and chosen.boxes. - To find a past picture: POST /v1/cameras/{id}/lookback with config {type: "read", question, expect}, then wait for lookback.finished or GET /v1/lookbacks/{id}. expect is never shown to the model; a ? in text is an unreadable character. - POST /v1/chat talks about a picture or recent incidents. Nothing is stored: send the history each time, up to 40 messages. It streams Server-Sent Events unless stream is false. - Build monitoring with a test key and a simulated camera: an incident opens on tick 4 and closes on tick 8. - Camly looks at places, objects and vehicles. It does not identify people. ## Quick start Camly takes you from cameras to events: connect a camera, say what to watch, and receive a webhook when something happens. Start with Monitoring. The building block underneath is the one-picture API, on this page: a picture and a question in, a verdict out. Create a key in API keys, export it as `CAMLY_API_KEY`, and send a picture with a question. ### Send a picture ``` curl https://api.camly.ai/v1/runs \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -F 'config={"type":"event","question":"Is the marked fire exit blocked?"}' \ -F image=@exit.jpg ``` ### Read the answer ``` { "id": "run_...", "object": "run", "type": "event", "model_tier": "lite", "mode": "live", "result": { "flagged": true, "confidence": 0.86, "description": "Two pallets stand inside the marked exit.", "regions": [ { "label": "pallet", "point": [0.52, 0.7] } ] }, "usage": { "checks": 1, "cost_eur": "0.005" }, "created": "2026-11-01T09:30:12.482913Z" } ``` `result.flagged` is the answer; `usage.cost_eur` is what the run cost. Every field is described in Run a check. ## Monitoring From cameras to events: connect a camera, say what to watch in a saved agent, and receive a signed webhook when something happens and when it ends. Each check is a run of the one-picture API, at the same price. ### Concepts - **Camera:** where pictures come from. Your code pushes them (`push`), a Camly Bridge reads the camera on site (`bridge`), or it makes its own for tests (`simulated`). - **Monitor:** a camera, a saved agent pinned to a version, a schedule and incident rules. A camera can have 5. - **Incident:** something that lasted, with a start, an end and one evidence picture. Single flagged checks are not incidents. - **Event:** what happened, delivered by webhook and readable with `GET /v1/events`. Cameras, monitors, incidents and events belong to one mode: a test key sees only test objects. All of it works in the console too, under Monitor. ### Create a camera ``` curl https://api.camly.ai/v1/cameras \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Loading dock", "source": "push" }' ``` ### Create a monitor Save an agent first, in Agents or with `POST /v1/agents`. The monitor pins its latest version unless you give `agent_version`, and moves only when you update it. ``` curl https://api.camly.ai/v1/monitors \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Dock exit kept clear", "camera": "cam_123", "agent": "agt_123", "schedule": { "min_interval_seconds": 60, "max_interval_seconds": 900, "motion": true, "hours": { "days": [ 1, 2, 3, 4, 5 ], "timezone": "Europe/Paris", "from": "07:00", "to": "19:00" } }, "incident_rules": { "confirm_checks": 2, "clear_checks": 2, "max_open_minutes": 1440 } }' ``` - `min_interval_seconds` (default 60; at least 10 with a live key): pictures closer together are skipped. `max_interval_seconds` (default 900): how often it wants a picture when all is calm. - `motion` (default true): whether a picture sent with `trigger` `motion` counts. - `hours` (optional): `days` are ISO weekdays, 1 for Monday, absent for every day; `from` and `to` are local times, `to` up to `24:00`, and a window can run past midnight. A monitor sends one picture per check, so trackers and calibrated measures answer `422 agent_not_supported`. `GET /v1/monitors/mon_123` gives its `status`, `paused_reason`, `open_incident` and `last_check`. `PATCH` changes its name, schedule, rules, endpoint or `agent_version`, which is how a monitor moves to a new version of its agent. `POST .../pause` and `.../resume` stop and restart it; `DELETE` removes it, and its incidents stay. ### Push a picture The key needs Full access or Push only. Send multipart, or JSON with the picture in base64 in `image`. ``` curl https://api.camly.ai/v1/cameras/cam_123/frames \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -F image=@frame.jpg \ -F trigger=schedule ``` The answer: one line per monitor of the camera: ``` { "object": "frame", "camera": "cam_123", "received": "2026-11-06T09:30:12.482913Z", "checks": [ { "monitor": "mon_123", "run": "run_...", "flagged": true, "confidence": 0.86, "incident": null }, { "monitor": "mon_456", "skipped": "outside_hours" } ], "next_frame_seconds": 60 } ``` `next_frame_seconds` says when to send the next picture: the shortest interval while something is being confirmed or an incident is open, the longest otherwise. It is `null` when the camera has no active monitor: nothing needs a picture, and you can stop sending. ### When a check is skipped A line with `skipped` means no check was made and nothing was charged. A line with `failed: true` means the model gave no usable answer: not charged, and it says nothing about the scene. | skipped | Why | | --- | --- | | `paused` | The monitor is paused. | | `outside_hours` | Outside the hours of its schedule. | | `motion_off` | The picture has trigger motion and the monitor has motion off. | | `min_interval` | Too soon after its last check. | | `rate_limited` | The organisation is past its checks a minute. | | `insufficient_balance` | The balance cannot pay: every live monitor of the organisation pauses. | | `budget_exceeded` | A hard budget would be passed: this monitor pauses. | ### Past checks Incidents tell you what mattered. To see every check, for a graph of a level through the day or to audit a monitor, read them back. This also covers checks made by a bridge, whose replies you never see. Past checks are kept 90 days; copy what you need for longer. The checks of one monitor: ``` curl "https://api.camly.ai/v1/runs?monitor=mon_123&from=2026-11-06T00:00:00Z&limit=200" \ -H "Authorization: Bearer $CAMLY_API_KEY" ``` One line of data: ``` { "id": "run_...", "object": "run", "type": "measure", "mode": "live", "status": "succeeded", "source": "monitor", "model_tier": "lite", "monitor": "mon_123", "lookback": null, "agent": "agt_123", "version": 2, "result": { "flagged": false, "confidence": 0.91, "description": "The silo gauge reads about 64 %. Measured level: 64 %", "regions": [], "measurement": { "variable": "level", "value": 64.0, "unit": "%" }, "condition_met": false }, "error": null, "usage": { "checks": 1, "cost_eur": "0.006" }, "created": "2026-11-06T09:30:12.482913Z" } ``` - Newest first. Filter with `monitor`, `camera` (the checks of its monitors), `agent`, `from` and `to`; page with `?before=run_...` while `has_more` is true. `limit` goes up to 200. - This needs a Full access key: a Run only or Push only key on a device cannot read your history. - A check with `status` `failed` has `result` `null` and was not charged. Skipped pictures made no check, so they are not listed. The picture itself is never kept, and chat messages are not listed. ### Paused monitors `paused_reason` says why a monitor stopped: - `user`: paused by you. It stays paused until you resume it. - `insufficient_balance`: resumes by itself after a top-up. Auto-recharge in Billing avoids this. - `budget_exceeded`: resumes when the month turns or a budget changes. - `idle_test`: a test monitor on the simulated camera, paused after 7 days without a change to it, a console sign-in or a call with one of your keys. Resume it when you need it. ### Incidents An incident opens after `confirm_checks` flagged checks in a row (default 2) and closes after `clear_checks` clear ones (default 2). `started` is the first flagged check, `confirmed` the moment the rules opened it. With `update_every_minutes`, an open incident sends `incident.updated` at that pace. GET /v1/incidents/inc_123: ``` { "id": "inc_123", "object": "incident", "monitor": "mon_123", "camera": "cam_123", "mode": "live", "status": "closed", "started": "2026-11-06T09:30:12Z", "confirmed": "2026-11-06T09:31:14Z", "closed": "2026-11-06T09:48:02Z", "close_reason": "cleared", "description": "Two pallets stand inside the marked exit.", "checks": 7, "peak_confidence": 0.91, "evidence_url": "https://api.camly.ai/v1/incidents/inc_123/evidence", "evidence_expires": "2026-12-06T09:31:14Z" } ``` - `close_reason`: `cleared`, `max_duration` (open longer than `max_open_minutes`, default 1440) or `no_data` (no check for three longest intervals: a silent camera never passes for a calm scene). - `peak_confidence` is the highest confidence seen, from 0 to 1. - List with `GET /v1/incidents?status=open`, newest first; page with `?before=inc_...` while `has_more` is true. - Get the picture from `evidence_url` with your key. It is kept 30 days by default (1 to 90, set in Limits) and `DELETE /v1/incidents/inc_123/evidence` erases it sooner. Then `evidence_url` is `null`. ## Webhooks Camly posts each event to your endpoints as JSON, signed with the endpoint’s own secret. Create endpoints in Webhooks or by API; there are 10 at most per project and mode. ### Create an endpoint ``` curl https://api.camly.ai/v1/webhook-endpoints \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "url": "https://example.com/camly", "event_types": [ "incident.opened", "incident.closed" ] }' ``` The address must be public https. Leave `event_types` empty for every event. The answer carries `secret` (`whsec_...`), once. A monitor created with `webhook_endpoint` sends its own events to that endpoint only; the others go to every endpoint that wants them. ### Events | Type | data | When | | --- | --- | --- | | `incident.opened` | incident | The rules confirmed something. Carries the incident. | | `incident.updated` | incident | Still open, every update_every_minutes, if set. | | `incident.closed` | incident | Closed. close_reason says why. | | `monitor.paused` | monitor, reason | Stopped for money: insufficient_balance or budget_exceeded. | | `monitor.resumed` | monitor | Restarted after a top-up. | | `camera.offline` | camera | Three failed captures in a row, or a pushed camera silent for three longest intervals. | | `camera.online` | camera | Pictures are back. | | `bridge.offline` | bridge | 15 minutes without a heartbeat. | | `bridge.online` | bridge | Heartbeats are back. | | `lookback.finished` | lookback | A search ended: found, not_found, failed or expired. | | `camera.added` | camera, bridge | Someone on site added a camera in the Bridge app. | | `camera.removed` | camera | Someone on site removed a camera they had added. | | `camera.renamed` | camera, bridge, previous_name | Someone on site renamed a camera they had added. | | `bridge.enrolled` | bridge | A bridge connected with an enrolment token, tag included. | | `bridge.discovered` | bridge, cameras | A network scan ended. cameras is what it found, empty if nothing. | | `billing.balance_low` | balance_eur, threshold_eur | The balance fell under €1. Once a month, and again after a top-up. | | `billing.recharge_failed` | error, failures, auto_recharge_off | An automatic top-up failed. After three in a row, auto-recharge goes off. | | `budget.threshold_reached` | budget, threshold, spent_eur | A budget passed one of its thresholds, once a month for each. | | `pictures.ready` | pictures | The small pictures of a window are there, or none came back (reason says why). | | `picture.kept` | pictures, picture | A full picture you kept is there, or could not be sent (full.status failed). | | `picker.chosen` | picker | Someone chose a picture with your link, and its full picture is kept (or failed). chosen has the picture, its boxes and your reference. | The money events warn you before monitoring stops. They concern live spending only, so an endpoint created with a test key never receives them. A budget on a project or a key is reported to that project alone; the balance, auto-recharge and an organisation’s budget are reported to each of its projects. New event types can appear. An endpoint with empty `event_types` receives them too, so ignore the types you do not know. The body of a delivery: ``` { "id": "evt_123", "object": "event", "type": "incident.opened", "mode": "live", "data": { "incident": { "id": "inc_123", "...": "..." } }, "created": "2026-11-06T09:30:12.482913Z" } ``` ### Check the signature Each delivery has the header `Camly-Signature: t=1762421412,v1=5257a8...`: `t` is the Unix time and `v1` the hex HMAC-SHA256, with your secret, of `t`, a dot and the raw body. Use the body exactly as received, before any JSON parsing, and refuse a `t` more than 5 minutes away. Two helpers do it, one file each and no dependency: camly_webhooks.py and camly-webhooks.mjs. Python: ``` from camly_webhooks import verify, WebhookError try: event = verify(request.body, request.headers["Camly-Signature"], ENDPOINT_SECRET) except WebhookError: return 400 ``` JavaScript: ``` import { verify } from './camly-webhooks.mjs'; app.post('/camly', express.raw({ type: 'application/json' }), (req, res) => { try { const event = verify(req.body, req.get('Camly-Signature'), process.env.CAMLY_WEBHOOK_SECRET); res.sendStatus(200); } catch (e) { res.sendStatus(400); } }); ``` Or copy the check itself: Python: ``` import hashlib, hmac, json, time def verify(body: bytes, header: str, secret: str, tolerance: int = 300) -> dict: parts = dict(p.split("=", 1) for p in header.split(",")) signed = f"{parts['t']}.".encode() + body expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest() if not hmac.compare_digest(expected, parts["v1"]): raise ValueError("bad signature") if abs(time.time() - int(parts["t"])) > tolerance: raise ValueError("too old") return json.loads(body) ``` JavaScript: ``` import { createHmac, timingSafeEqual } from 'node:crypto'; export function verify(body, header, secret, tolerance = 300) { const parts = Object.fromEntries(header.split(',').map((p) => p.split('='))); const expected = Buffer.from(createHmac('sha256', secret).update(`${parts.t}.`).update(body).digest('hex')); const given = Buffer.from(parts.v1 ?? ''); if (given.length !== expected.length || !timingSafeEqual(given, expected)) throw new Error('bad signature'); if (Math.abs(Date.now() / 1000 - Number(parts.t)) > tolerance) throw new Error('too old'); return JSON.parse(body); } ``` ### Delivery and retries - Answer with a 2xx within 10 seconds. Anything else counts as a failed attempt, and redirects are not followed. - Failed attempts are retried for about 24 hours (30 seconds, 2, 10 and 30 minutes, then 1, 2, 4, 8 and 8 hours). The console shows each delivery’s attempts and last status. - Delivery is at least once: the same event can arrive twice. Deduplicate on the event `id`, also in the `Camly-Event-Id` header. Events can arrive out of order. ### Catch up after downtime Events are kept whatever happens to the deliveries. Keep the last `id` you handled and ask for what followed, oldest first, repeating while `has_more` is true: ``` curl "https://api.camly.ai/v1/events?after=evt_123" \ -H "Authorization: Bearer $CAMLY_API_KEY" ``` `GET /v1/events/evt_123` adds its `deliveries`; `POST /v1/events/evt_123/redeliver` sends it again to every endpoint that wants it. ## Bridges A Camly Bridge is a small program on the site’s network. One bridge reads many cameras, keeps the schedule on site, and pushes only the pictures that matter through the same endpoint as your own code. No port is opened: it only calls out. A camera belongs to at most one bridge. ### Enrol a bridge An enrolment token ties a bridge to your project and mode. It is shown once. - **Single** (`single`): one bridge, valid 24 hours. - **Fleet** (`fleet`): up to `max_uses` bridges, 30 days by default (`valid_hours`, 90 days at most), for pre-imaged boxes. Revoke it when the roll-out ends. ``` curl https://api.camly.ai/v1/bridges/enrollment-tokens \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "kind": "fleet", "max_uses": 50, "note": "Lyon roll-out" }' ``` **With a client on site:** send them the token. They install the Camly Bridge from camly.ai/download, open it, paste the code and click Connect. No account and no command line: from then on you add the cameras through the API, and their Bridge app only shows what is running. **Unattended:** on the machine, as an administrator (`sudo` on Linux; on Windows the command is `CamlyBridge.exe`), or set `CAMLY_ENROLL_TOKEN` before the service starts: ``` camly-bridge enroll --token cmly_enr_... ``` The bridge makes its own key pair and gets its own credential; the token is not used again. It then appears in `GET /v1/bridges` with its `public_key`. ### Tag your bridges With many sites, a `tag` says which customer or site a bridge belongs to (80 characters at most). Put it in the enrolment token and the bridge arrives labelled: ``` curl https://api.camly.ai/v1/bridges/enrollment-tokens \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "kind": "single", "tag": "Acme Lyon" }' ``` Change it, or the bridge’s name, at any time. `"tag": null` removes it. ``` curl -X PATCH https://api.camly.ai/v1/bridges/br_123 \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"tag": "Acme Lyon"}' ``` List one customer’s bridges with `GET /v1/bridges?tag=Acme%20Lyon`, an exact match. ### Add its cameras `POST /v1/bridges/br_123/discover` asks the bridge to look on its network; with its next heartbeat the cameras it found are in `discovered`, for you to adopt, and `bridge.discovered` tells you the scan ended. Either way, the camera is created by API or in the console: ``` curl https://api.camly.ai/v1/cameras \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Gate", "source": "bridge", "bridge": "br_123", "url": "rtsp://192.168.1.20/stream1", "sealed_credentials": "" }' ``` Motion on a bridge camera comes from `motion_source`: `pixel` (the default) compares pictures on site; `onvif` uses the camera’s own motion events, with its ONVIF address in `onvif_xaddr` (a scan finds it). With `onvif`, a `motion_zone` has no effect, because the camera does not say where it saw motion. ### Cameras added on site The person next to the camera can add it too, in the Bridge app, by scanning the network or typing its address. The login is sealed on the machine and never travels in clear. The camera then has `added_by` `site` (`api` otherwise). - Such a camera sends nothing and costs nothing until a monitor is attached: that step stays yours. The console shows Add a monitor on it. - The `camera.added` webhook carries `camera` and `bridge`, tag included, so your app can react, for example by attaching the monitor for that customer. - The site can remove only cameras it added and nobody uses: as soon as a monitor is attached, the camera is yours and stays. `camera.removed` tells you when one goes. - A scanned camera arrives named after its model or address. The site can rename the cameras it added, even once a monitor is attached, and `camera.renamed` tells you. The camera id does not change. The cameras you set up keep the name you gave them. ### Sealing a camera login A login never travels in clear and never sits in `url`: a URL with `user:password@` is refused. It is encrypted to the bridge’s `public_key`, so only that bridge can open it, and Camly stores what it cannot read. The console seals in your browser. From your own code, format `camly-seal-v1`: Python, with the cryptography package: ``` import base64, json, os from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.ciphers.aead import AESGCM from cryptography.hazmat.primitives.kdf.hkdf import HKDF from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat def seal(public_key: str, username: str, password: str) -> str: bridge = ec.EllipticCurvePublicKey.from_encoded_point(ec.SECP256R1(), base64.b64decode(public_key)) ephemeral = ec.generate_private_key(ec.SECP256R1()) shared = ephemeral.exchange(ec.ECDH(), bridge) key = HKDF(algorithm=hashes.SHA256(), length=32, salt=b"", info=b"camly-seal-v1").derive(shared) nonce = os.urandom(12) login = json.dumps({"username": username, "password": password}).encode() point = ephemeral.public_key().public_bytes(Encoding.X962, PublicFormat.UncompressedPoint) return base64.b64encode(point + nonce + AESGCM(key).encrypt(nonce, login, None)).decode() ``` `public_key` is standard base64 of the uncompressed P-256 point. The AES-256-GCM key comes from ECDH with a fresh key pair and HKDF-SHA256 (empty salt, info `camly-seal-v1`). The result is standard base64 of the fresh public key (65 bytes), the nonce (12) and the ciphertext with its tag. ### The schedule on site Each heartbeat, every 5 minutes, tells the bridge what to do for each camera. With several monitors it applies the tightest: the shortest intervals, motion if any monitor wants it, and any monitor’s hours. A camera with no active monitor sends nothing, so a quiet site costs nothing. ### Offline and revoked - `bridge.offline` goes out after 15 minutes without a heartbeat, `camera.offline` after 3 failed captures in a row. - `DELETE /v1/bridges/br_123` revokes a bridge: its credential stops working at once, and its cameras stay, without pictures, until you delete them. ## From a VMS, without a Bridge The Camly Bridge is one way for pictures to reach Camly, not the only one. If the site already has a video management system (VMS), a recorder or cameras that send by themselves, Camly can work from what is there: nothing to install, or a small service of yours beside the VMS. Saved agents, monitors, incidents and webhooks work the same way. What needs the Bridge is everything that reads the archive it keeps on site. ### Five ways in - **Push from your service:** code beside the VMS takes a camera’s picture and sends it to `POST /v1/cameras/{id}/frames`. See Connect your own gateway. - **Camera upload URL:** anything that can send a JPEG to an HTTPS address, a camera or a VMS rule, feeds a push camera with no key header. See Let the camera send. - **Recorder FTP:** a DVR, an NVR or a VMS that uploads snapshots by FTP. See Connect a recorder. - **Direct check:** `POST /v1/runs` with a picture and a saved agent, and the answer comes back in the same call. No camera, no monitor. See Quick start. - **Camly Bridge:** reads the cameras on site and keeps an archive. See Bridges. ### What each way gives | Way in | Monitors and incidents | Past pictures | On site | | --- | --- | --- | --- | | Camly Bridge | Yes | Look-back, pictures of a window, picker, clips | The Camly Bridge | | Push from your service | Yes | No | Your service and a Push only key | | Camera upload URL | Yes | No | Nothing: an upload URL | | Recorder FTP | Yes | No | Nothing: an FTP login | | Direct check | No, one answer per call | Check pictures of your own recordings | Your code and an API key | A picture sent by any way is checked at the same price, and its incidents keep the picture that was checked as evidence. ### Agent types without a Bridge The agent type does not depend on how pictures arrive. Every type works without a Bridge: | Agent type | Direct check | Monitor on a push camera | | --- | --- | --- | | Event | Yes | Yes | | Detect | Yes | Yes | | Measure | Yes | Yes, except a calibrated measure | | Read | Yes | Yes | | Tracker | Yes, with a reference_image | No | | Find (beta) | Yes | No | The two limits hold for monitors on every camera, Bridge cameras included. A tracker and a calibrated measure compare two pictures, and a monitor sends one picture per check: the API answers `422 agent_not_supported`. Find searches the past, so it is not used on a monitor either. Run them as direct checks from your code: a tracker with the earlier picture as `reference_image`, Find on pictures exported from the VMS. ### Camly in VMS terms For a VMS maker building an integration, or a developer connecting one, here is what each VMS idea becomes in Camly. | In the VMS | In Camly | What to know | | --- | --- | --- | | A camera in the VMS | A push camera | One per VMS camera. Keep the site or customer in its name, and map ids on your side. | | An analytic or a rule on a camera | A monitor | A saved agent, a schedule and incident rules on one camera. Up to 5 per camera. | | A motion event | A picture with trigger motion | Monitors with motion off skip it. | | An alarm | An incident | Opens after confirm_checks flagged checks in a row, closes after clear_checks clear ones. | | The alarm notification | A webhook event | Signed. incident.opened, incident.closed and the others below. | | The alarm snapshot | The evidence picture | evidence_url on the incident: the picture that was checked. | | Acknowledging or closing an alarm | Nothing to call | An incident closes by itself: cleared, max_duration or no_data. Acknowledge it in the VMS. | | The VMS server on a site | A Push only key | It can send pictures and nothing else. | ### Which one for your VMS Most VMS can do at least one of these. Take the first that yours offers: Its rules can send a snapshot to an HTTPS address on an event: give that rule the camera’s upload URL, with ?trigger=motion for motion events. No code.It can upload snapshots by FTP on an event or a timer: create a recorder and give the VMS its login. Camly reads the channel from the path of each file; if unrecognised shows paths, send them to us and we add the format.It has an API or an SDK that gives a camera’s current picture and its events: run a small service beside it that pushes pictures. The most control: you choose the cameras, the moments and the size of the picture.None of these: install the Camly Bridge, which reads the cameras directly over RTSP or ONVIF. ### A service beside the VMS Create one push camera per VMS camera, attach a monitor to each, and give the service a **Push only** key: it can send pictures and nothing else. Send on the VMS’s own motion events with `trigger` `motion`, and between them on a timer that follows `next_frame_seconds`. Send the full picture, not the VMS thumbnail: small details and text need it. Python: ``` import requests API = 'https://api.camly.ai/v1/cameras/{}/frames' KEY = 'cmly_sk_live_...' # a Push only key CAMERAS = {'vms-cam-12': 'cam_123'} # your VMS camera id -> Camly camera id def vms_snapshot(vms_camera): """Return the current JPEG of a camera, from your VMS's own API or SDK.""" ... def send(vms_camera, trigger='schedule'): jpeg = vms_snapshot(vms_camera) r = requests.post(API.format(CAMERAS[vms_camera]), timeout=30, headers={'Authorization': f'Bearer {KEY}'}, files={'image': ('frame.jpg', jpeg, 'image/jpeg')}, data={'trigger': trigger}) return r.json().get('next_frame_seconds') if r.ok else None # Call send(camera, 'motion') from your VMS motion event handler, # and send(camera) on a timer, every next_frame_seconds (60 s by default). ``` The answers, retries and many-site advice of Connect your own gateway apply as they are. ### Events to turn into VMS alarms Create a webhook endpoint on your back end (see Webhooks) and map these events. Incident and camera events carry the camera id, so you know which VMS camera they belong to. | Event | What the VMS should do | | --- | --- | | incident.opened | Raise an alarm on that camera, with description, confidence and the evidence picture. | | incident.updated | Refresh the alarm. Sent only if update_every_minutes is set. | | incident.closed | Clear the alarm. close_reason: cleared, max_duration or no_data. | | camera.offline | No picture for three times the longest interval: show the camera as not analysed. | | camera.online | Pictures are back. | | monitor.paused | Checks stopped for money (insufficient_balance or budget_exceeded): warn an administrator. | | monitor.resumed | Checks restarted after a top-up. | | billing.balance_low | Under €1 left: warn an administrator before monitors pause. | ### Settings that shape the alarms Set on the monitor, with `POST /v1/monitors` or `PATCH /v1/monitors/{id}`. | Setting | Default | Range | What it does | | --- | --- | --- | --- | | schedule.min_interval_seconds | 60 | 0 to 86400 | Shortest time between two checks; pictures sent sooner are skipped and not charged. At least 10 with a live key. | | schedule.max_interval_seconds | 900 | 10 to 86400 | Longest time without a check. Send at least this often, or the camera goes offline. | | schedule.motion | true | true, false | Check pictures sent with trigger motion. | | schedule.hours | none: always | days, from, to, timezone | Only check inside these hours. | | incident_rules.confirm_checks | 2 | 1 to 10 | Flagged checks in a row before an incident opens. 1 alarms on the first. | | incident_rules.clear_checks | 2 | 1 to 10 | Clear checks in a row before it closes. | | incident_rules.max_open_minutes | 1440 | 1 to 43200 | An incident still open after this closes with max_duration. | | incident_rules.update_every_minutes | none | 0 to 1440 | Send incident.updated this often while it stays open. | ### Pictures to send | | What to know | | --- | --- | | Format | JPEG, PNG or WebP. JPEG is best. | | Size | Up to 10 MB a picture; larger is refused with 422 image_too_large. | | Resolution | Each check uses the picture at 1280 px on its longest side. Send at least that: the main stream, not a thumbnail or a sub-stream at 640 px. | | Time | Send the picture of now. A picture that could not be sent is dropped, not sent late: it would be checked as the present. | | Privacy | Pictures are checked in memory and not stored. Only an incident keeps its evidence picture, until evidence_expires or until you delete it. | ### Which key goes where Keep the Full access key on your back end only. What sits on a site should be able to send pictures and nothing else. | Where | Credential | What it can do | | --- | --- | --- | | Your back end | Full access key | Creates cameras, monitors and webhook endpoints; reads incidents. | | A service beside the VMS | Push only key | Sends pictures to cameras, nothing else. | | A VMS rule or a camera | Upload URL | Sends pictures to one camera, with no key header. | | A VMS or recorder that uses FTP | FTP login | Sends pictures to the channels of one recorder. | | Code that runs direct checks | Run only key | Runs checks, nothing else. | ### Questions about the past Look-back, the pictures of a window and the hosted picker search the archive of a Camly Bridge, so they do not work on a push camera: the API answers `409 camera_has_no_archive`. The VMS has its own recordings: export the pictures of the moment you need and check them with a direct check, one picture per call. To find the best one in a window, check several and keep the one with the highest `confidence`. ``` curl https://api.camly.ai/v1/runs \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -F agent=agt_123 \ -F image=@exported-from-the-vms-19-34-12.jpg ``` ### What it costs A check made by a monitor costs €0.006 and a direct check €0.005, whatever way the picture came. From 1 December 2026 a live camera with an active monitor costs €2 a month, a push camera included. Direct checks need no camera, so no monthly fee. See Limits and prices. ## Connect your own gateway Already have a box on site, an NVR or your own video software? You do not need the Camly Bridge (to choose between the ways in, see From a VMS, without a Bridge). Anything that can make an HTTPS call can send pictures to the public API. Your gateway stays in charge of the cameras; Camly does the analysis, the incidents and the webhooks. ### Set it up From your back end, with a Full access key, create one camera per video feed with source push, and put the customer or site in its name.Attach a monitor to each camera: an agent, a schedule, the incident rules.Give each gateway a Push only key. It can send pictures and nothing else, so a stolen box cannot read your data or change anything.Create a webhook endpoint on your back end to receive incidents. ### The loop on your gateway Send a JPEG to `POST /v1/cameras/{id}/frames`, with `trigger` `schedule` or `motion`. If your gateway already detects motion, send those moments with `motion`: you pay only for pictures that matter. Between them, follow `next_frame_seconds` from each answer, which shortens while something is being confirmed. Python: ``` import os, time, requests KEY = os.environ['CAMLY_PUSH_KEY'] # a Push only key CAMERA = 'cam_123' # one Camly camera per video feed URL = f'https://api.camly.ai/v1/cameras/{CAMERA}/frames' wait = 60 while True: jpeg, trigger = next_picture(timeout=wait) # your code: a JPEG, 'schedule' or 'motion' try: r = requests.post(URL, headers={'Authorization': f'Bearer {KEY}'}, files={'image': ('frame.jpg', jpeg, 'image/jpeg')}, data={'trigger': trigger}, timeout=30) except requests.RequestException: time.sleep(30) # no connection: drop this picture, go on continue if r.status_code in (401, 403): raise SystemExit('The key was refused: stop and alert someone.') if r.ok: wait = r.json()['next_frame_seconds'] or 60 else: time.sleep(30) ``` ### Answers and retries - **200:** the picture arrived. Read `checks`: a line with `skipped` was not checked and not charged. That includes `rate_limited`, which arrives inside a 200, so slow down when you see it. - **401 or 403:** the key was refused. Stop and alert someone; retrying will not help. - **404:** no such camera for this key and mode. - **422:** the picture or the request is not valid. Do not resend it as it is. - **No connection or 5xx:** drop the picture and send a fresh one later. An old picture says nothing about now, and it would be charged as a check of the present. The endpoint takes no `Idempotency-Key`. A picture sent twice is not checked twice while it falls inside the monitor’s `min_interval_seconds`. ### Many gateways and customers A project holds at most 10 active keys and 200 cameras. Past 10 gateways, several share a Push only key; the camera id says which feed a picture belongs to. Each customer’s cameras sit in the same project, so keep the customer in the camera name and map camera ids on your side: incidents and events carry the camera id. If you need more, write to support@camly.ai. ### Knowing a feed went silent Camly has no connection to your gateway, only your pictures. A pushed camera goes `offline`, with a `camera.offline` event, after three times its monitor’s longest interval without a picture, checked every 15 minutes. It comes back with the next picture. Set `max_interval_seconds` to what your gateway really sends, or it will look silent. No gateway at all? Most network cameras can send their pictures to Camly themselves: see Let the camera send. ### What needs the Camly Bridge Your gateways do not appear under Bridges: no tags, no `bridge.offline`, no remote scan, no cameras added on site. The Bridge’s own connection is private and may change, so do not build on it. Look-back, the pictures of a window, the hosted picker and video clips also need the Bridge, because they read the archive it keeps on site. If your gateway keeps recordings, you get the same result yourself: take pictures from the right moment and check them. All the ways compared: From a VMS, without a Bridge. A past picture from your own recording: ``` curl https://api.camly.ai/v1/runs \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -F 'config={"type":"read","question":"Read the reference on the label","expect":"ABC123"}' \ -F image=@from-your-recording.jpg ``` Test all of this for free with a test key: a test camera accepts pictures and answers without calling the model. ## Let the camera send Most network cameras (Axis, Hikvision, Dahua, Hanwha and many others) can send a picture over HTTPS when something happens, or on a timer. Give such a camera an **upload URL** and it sends its pictures to Camly itself: no Camly Bridge, no box on site, no code, and no API key to set in a header. Camly does the checks, the incidents and the webhooks as for any push camera. ### Create the upload URL Create a camera with `source` `push` and attach a monitor to it, as in Monitoring. Then create its upload URL, from the console (the camera’s How to send pictures button in Cameras) or with a Full access key: ``` curl -X POST https://api.camly.ai/v1/cameras/cam_123/upload-url \ -H "Authorization: Bearer $CAMLY_API_KEY" ``` The answer: ``` { "object": "upload_url", "camera": "cam_123", "last4": "x9Qz", "created": "2026-11-10T09:00:00Z", "token": "cmly_up_...x9Qz", "url": "https://api.camly.ai/v1/upload/cmly_up_...x9Qz", "basic_auth_url": "https://api.camly.ai/v1/upload" } ``` The `url` and the `token` are shown this once. Afterwards the camera shows only `upload_url.last4` and when it was made. A new URL replaces the old one at once; `DELETE /v1/cameras/{id}/upload-url` stops it. A URL works for its camera only, in the camera’s mode: a test camera’s URL is free and never calls the model. ### Set up the camera In the camera’s own web page, add the upload URL as an HTTPS recipient, then make an event rule (motion, line crossing, a timer...) that sends a picture to it. The names vary with the brand and the firmware: - **Axis:** System, Events, Recipients: add an HTTPS recipient with the upload URL. Then a rule whose action sends images to that recipient. - **Hikvision:** Network, Advanced, Alarm server (or HTTP listening): the upload URL over HTTPS. Then link the event to Notify surveillance center. - **Dahua, Hanwha and others:** the HTTP picture upload or event push setting. In a rule fired by motion or another event, add `?trigger=motion` to the address: monitors with motion off then skip those pictures, as they do for a bridge. A timer rule sends without it. A camera that asks for a user name and a password instead of a full address: give it `/v1/upload` (the `basic_auth_url`), any user name, and the token as the password. This also keeps the token out of the address. ### What the upload URL accepts - A raw JPEG (or PNG, WebP) body, sent with POST or PUT. - A `multipart/form-data` form with the picture under any field name, beside event parts in XML or JSON: the first picture is used. - A `multipart/mixed` body: the first JPEG inside is used. - A message with no picture, such as a camera heartbeat: answered 200 with `ignored` `no_picture`, and not charged. The answer is the same as for `POST /v1/cameras/{id}/frames`; the camera does not read it. Try it from your computer before you set up the camera: ``` # What the camera will do: a raw JPEG to the upload URL, no key header curl -X POST "$UPLOAD_URL?trigger=motion" \ -H "Content-Type: image/jpeg" \ --data-binary @frame.jpg ``` ### How often it sends A camera cannot follow `next_frame_seconds`, so the monitor’s schedule decides. Pictures that arrive within `min_interval_seconds` of the last check are skipped and not charged, so a camera that sends too often does not cost more. Set the camera’s timer to the monitor’s `max_interval_seconds`: a camera that sends nothing for three times that long goes `offline`, with a `camera.offline` event. ### Keep the URL safe - Anyone with the URL can send pictures to that camera, and nothing else: it cannot read your data or change anything. Replace it if it leaks. - The camera must send over HTTPS. Some old firmware cannot; use a gateway or the Camly Bridge for those. - The token is part of the address, so it can appear in logs on the way. Use the user name and password form when the camera offers it. ### What needs the Camly Bridge The camera keeps no archive for Camly, so look-back, the pictures of a window, the hosted picker and video clips do not work, and there are no tags, no remote scan and no `bridge.offline`. Cameras that cannot send pictures by themselves need the Camly Bridge or your own gateway. A recorder (DVR or NVR) sends by FTP instead: see Connect a recorder. ## Connect a recorder A recorder (DVR or NVR) cannot run the Camly Bridge, and most cannot send a picture over HTTPS. Nearly all can upload snapshots by **FTP**, on a timer or on motion. Give the recorder one FTP login and it sends the pictures of its channels to Camly itself: nothing to install on site. Each channel you add is a push camera, with the same checks, incidents and webhooks. ### Create the recorder From the console (Cameras, Recorders, New recorder) or with a Full access key: ``` curl -X POST https://api.camly.ai/v1/recorders \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"name": "Shop NVR"}' ``` The answer: ``` { "id": "rec_019a6f2c41d0Jq7TzkP2", "object": "recorder", "name": "Shop NVR", "mode": "live", "ftp": { "host": "ftp.camly.ai", "port": 21, "user": "r4k2m9x7q1zt", "password": "f3Kp...shown once", "password_last4": "Xy9Q" }, "channels": [], "unrecognised": null, "last_picture": null, "created": "2026-11-21T10:00:00Z", "revoked": null } ``` The password is shown this once. `POST /v1/recorders/{id}/password` makes a new one and stops the old one at once; `DELETE /v1/recorders/{id}` revokes the login. ### Set up the recorder In the recorder’s FTP settings (often under Network or Storage), type the server address, the port, the user name and the password. Leave the remote folder empty.Turn on snapshots for the channels to watch: on a timer, on motion, or both.Tick snapshot upload to FTP for those channels, and use the recorder’s Test button. The names vary with the brand and the firmware. Dahua and Reolink recorders upload on a timer and on motion; on Hikvision recorders the timer upload depends on the model. ### Add the channels The recorder writes each picture under a path that names the channel, and Camly reads it. A channel that sent a picture appears in the recorder’s `channels`; its pictures are ignored, and nothing is charged, until you add it as a camera: ``` curl -X POST https://api.camly.ai/v1/cameras \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"name": "Checkout", "recorder": "rec_019a6f2c41d0Jq7TzkP2", "channel": 3}' ``` Then attach a monitor to that camera, as in Monitoring. You can add a channel before its first picture arrives. If `unrecognised` is set, pictures arrive whose path does not tell the channel: send us the path it shows and we add the format. ### How often it sends The monitor’s schedule decides, as for any camera that sends by itself: pictures that arrive within `min_interval_seconds` of the last check are skipped and not charged, so a burst on motion costs one check. Set the recorder’s timer to the monitor’s `max_interval_seconds`. A picture taken on motion counts as `trigger` `motion`: monitors with motion off skip it. ### What to know - FTP sends the password and the pictures unencrypted. When the recorder offers FTPS (explicit TLS), turn it on: the same address and port take it. - The login can only send pictures to that recorder’s cameras. Nothing can be read or downloaded with it, and the FTP server keeps no picture. - Snapshots of a recorder are often smaller than the camera’s full picture. For small details or text to read, prefer the Camly Bridge. - There is no archive, so no look-back, no pictures of a window and no hosted picker; video clips are not taken. All the ways compared: From a VMS, without a Bridge. ## Testing without cameras You can build the whole flow, webhooks included, before owning a camera. With a test key everything is free, never calls the model, and stays apart from live objects. In the console, choose Test under Mode in the account menu: every page then shows the test side. ### A simulated camera It exists with test keys only and makes its own pictures on a fixed script of 8 ticks: 2 clear, 4 flagged, 2 clear, then again. With the default rules an incident opens on tick 4 and closes on tick 8. ``` curl https://api.camly.ai/v1/cameras \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "Test dock", "source": "simulated" }' ``` Attach a monitor as usual, with a saved agent (see Monitoring), then run ticks yourself, up to 16 a call. `min_interval_seconds` does not hold them back. ``` curl https://api.camly.ai/v1/cameras/cam_123/simulate \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "ticks": 8 }' ``` | Tick | Script | What happens | | --- | --- | --- | | `1, 2` | Clear | Nothing. | | `3` | Flagged | First flagged check: nothing opens yet. | | `4` | Flagged | Second in a row: the incident opens, incident.opened goes out. | | `5, 6` | Flagged | The incident counts its checks. | | `7` | Clear | First clear check. | | `8` | Clear | Second in a row: the incident closes, incident.closed goes out. | One entry per tick: ``` { "object": "list", "data": [ { "tick": 4, "flagged_by_script": true, "object": "frame", "camera": "cam_123", "received": "2026-11-06T09:30:12.482913Z", "checks": [ { "monitor": "mon_123", "run": "run_...", "flagged": true, "confidence": 0.9, "incident": { "id": "inc_123", "status": "open", "...": "..." } } ], "next_frame_seconds": 60 } ] } ``` A simulated camera with an active monitor also ticks by itself, once every 15 minutes, so a test incident opens and closes without you. Pause the monitor to stop it. ### Test your webhooks Create an endpoint with a test key: it receives the events of test objects, signed like live ones. Ticks 4 and 8 give you `incident.opened` and `incident.closed` on demand. Redeliver one to test your deduplication. ### Look-back A simulated camera answers a look-back at once, with no archive to set: it goes through four sample pictures, and the third matches. The answer of the call already says `found`. ### Pushed pictures A `push` camera works with a test key too. The verdict is derived from the picture’s bytes, so the same picture always gives the same answer. ## Find a past picture A camera on a bridge can keep a rolling archive on your site. When a question comes up later, ask for a time window and what to look for: the bridge sends only those pictures, each is checked, and the first that matches ends the search and comes back to you. A typical case is proof of a handover. A claim arrives with a reference and a time. You search the archive for that reference around that time, and you get the picture that shows it. ### Read text The `read` agent type reads a reference, a number or a label. `question` says what to read; `result.text` is what was read. Give `expect` and `result.matched` says whether the text read contains it, ignoring case, spaces and separators. `expect` is never shown to the model: it reads blind and the API compares, so a match is not suggested by the question. In `text`, a `?` stands for a character that could not be read, and it never matches. With `expect`, `flagged` means matched; without it, that something was read with enough confidence. ### 1. Set the archive on the camera Bridge cameras only: a pushed camera has no archive. It is on by default for every new bridge camera, with the defaults below, whether you create it or the site adds it in the Bridge app; send `"archive": null` to turn it off. `burst_per_second` (default 2, 0 to 5, 0 for timer only) takes pictures while something moves; `interval_seconds` (default 30) is the safety net, one picture every so often whatever happens. `days` defaults to 14 (90 at most), `max_gb` to 40, past which the oldest pictures go first; `hours` is optional. Pictures of people are personal data: tell your customer the archive is on, and keep `days` to what you need. The bridge stops adding pictures while its disk has less than 2 GB free, whatever `max_gb` says. ``` curl -X PATCH https://api.camly.ai/v1/cameras/cam_123 \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"archive": {"interval_seconds": 30, "burst_per_second": 2, "days": 14, "max_gb": 40}}' ``` From Bridge 2.9.3 the archive also keeps a **settled** picture each time the motion zone goes still after motion (3 seconds still, at most one every 10 seconds): the result of a movement, such as bags put down or a parcel taken, which burst pictures, taken while things move, rarely show clearly. Look-backs check settled pictures first, and a pictures request always includes them (`settled: true`). It needs bursts on (`burst_per_second` above 0). **Video** (Bridge 2.9.4, opt-in): with `mode: "video"` the bridge also records the camera’s stream in 10-second pieces, copied without re-encoding. Give the sub-stream in `video_url` (the same camera, without a login: the camera’s is used); the bridge never sends the login to another host. Count 5 to 7 GB a day for a sub-stream, so about a week in 40 GB; the main stream is several times that. Searches then also look at moments of the video between the pictures, and a look-back that finds a match gets `clip_url`: the 10 seconds around it (5 before, 5 after), kept like the picture. Video stops while the disk has less than 2 GB free. Continuous video is video surveillance: inform the people filmed and keep it no longer than the rules that apply to you allow. Since Bridge 2.9.0 the archive keeps pictures up to 1920 pixels wide, so a matched look-back picture can serve as evidence; the check itself still looks at it at 1280 pixels, so a look-back costs the same. Count roughly 350 KB per picture: one every 30 seconds is near 1 GB per camera per day. Bursts add to that, depending on activity: 100 events a day of about 7 seconds at 2 per second is near 0.5 GB. Older bridges keep 1280-pixel pictures, about 155 KB each. Sending `"archive": null` turns it off, and the bridge deletes what it kept. `archive_status` on the camera gives `pictures`, `bytes`, `oldest` and `motion_pictures`, as last reported. ### 2. Start the search A window covers 6 hours at most; `from` and `to` need a time zone. Send `config` or a saved `agent`, not both; trackers and calibrated measures are not available. The call answers 202 at once. ``` curl https://api.camly.ai/v1/cameras/cam_123/lookback \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "from": "2026-11-06T09:00:00+01:00", "to": "2026-11-06T11:00:00+01:00", "config": { "type": "read", "question": "The reference printed on the label", "expect": "AB-4471" }, "max_pictures": 120 }' ``` `max_pictures` defaults to 60, 360 at most. Each picture checked is one check, so at most `max_pictures` times the price. Pictures of motion bursts are checked first, then the timer pictures, and the search stops at the first match. ### Get the moment reliably A search can only find what the archive holds, so set the scene up for it: - **A fixed spot.** Pick the place where the thing to read always passes, with the camera close enough to read it. - **A motion zone around it.** Motion elsewhere in the picture then starts nothing. It only decides when the bridge reacts: pictures stay whole. - **Bursts plus a slow timer.** A burst catches the moment; the timer is the safety net if motion is missed. The zone is normally drawn on site, in the Bridge app, where the live picture is. By API, send 3 to 32 points in 0–1 picture units; `null` means the whole picture again. ``` curl -X PATCH https://api.camly.ai/v1/cameras/cam_123 \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{"motion_zone": [[0.2, 0.3], [0.8, 0.3], [0.8, 0.9], [0.2, 0.9]]}' ``` Add `"only_motion": true` to a search to check burst pictures only. It is cheaper when nothing matches, but if motion was missed the timer pictures are not looked at. ### 3. Wait for the answer With a real bridge, the search starts within 30 seconds and checks 5 pictures at a time, so a match near the middle of the window usually comes back in under a minute and a full search of 360 pictures in about 2 to 3 minutes. The bridge’s computer must be on. Look-back pictures do not count against your rate limit. Wait for the `lookback.finished` webhook, or read `GET /v1/lookbacks/lbk_123`. GET /v1/lookbacks/lbk_123: ``` { "id": "lbk_123", "object": "lookback", "camera": "cam_123", "mode": "live", "from": "2026-11-06T08:00:00Z", "to": "2026-11-06T10:00:00Z", "agent": null, "agent_version": null, "status": "found", "reason": null, "pictures_checked": 37, "max_pictures": 120, "only_motion": false, "captured": "2026-11-06T09:12:40Z", "run": "run_...", "result": { "flagged": true, "confidence": 0.94, "description": "A label is visible on the parcel.", "regions": [], "text": "AB-4471", "matched": true }, "picture_url": "https://api.camly.ai/v1/lookbacks/lbk_123/picture", "picture_expires": "2026-12-06T09:30:12Z", "created": "2026-11-06T09:30:02Z", "finished": "2026-11-06T09:30:58Z" } ``` | status | Meaning | | --- | --- | | `pending` | Waiting for the bridge. | | `running` | Pictures are being checked. | | `found` | A picture matched. captured says when it was taken. | | `not_found` | No match. reason max_pictures means the limit stopped the search. | | `failed` | reason says why: insufficient_balance, budget_exceeded or rate_limited. | | `expired` | reason bridge_silent: no answer within an hour. The computer may be off. | ### The best matches, not the first By default the first matching picture ends the search. With `results: "best"` every picture sent is checked (up to `max_pictures`), and the `top` best (1 to 5, default 3) are kept in `matches`, ranked: for a Find how fully the items are there, then confidence, then closeness to the middle of the window. Each match has its own picture; `picture_url` and `result` are the best one’s. It costs every picture checked, so keep the window and `max_pictures` tight. ``` curl https://api.camly.ai/v1/cameras/cam_123/lookback \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "from": "2026-11-30T18:28:00Z", "to": "2026-11-30T18:35:00Z", "results": "best", "top": 3, "max_pictures": 40, "config": { "type": "find", "items": [ { "item": "white_wrap", "count": 2 } ], "question": "a delivery person stands at the counter" } }' ``` ### 4. Get the picture ``` curl https://api.camly.ai/v1/lookbacks/lbk_123/picture \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -o found.jpg ``` The match is kept for the project’s retention period, 30 days by default, and `DELETE /v1/lookbacks/lbk_123/picture` erases it sooner. The other pictures of the window are not kept. ### What a match proves - A match proves what the picture shows, at the time it was taken. It says nothing about what happened outside the picture. - Send low-confidence answers, a `text` with a `?` and a `not_found` to a person. A search that finds nothing does not prove the thing did not happen. - The archive is on your site and under your control. What you film, how long you keep it and how you inform people are your responsibility, under the rules that apply to you. ## Pictures of a window Get the pictures a bridge archived during a time window, small, with no check, and show them to a person who knows what happened. They choose; you keep the picture they chose as evidence. Nothing can be wrong, because nothing is guessed: it is the manual search through a recording, in seconds. A typical case is a delivery dispute: an item reported missing, a courier pickup time from the delivery platform. You ask for the pictures around that time, the restaurant taps the one that shows the items on the counter, and you send that picture to the platform. ### Ask for a window ``` curl https://api.camly.ai/v1/cameras/cam_123/pictures \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "from": "2026-11-30T19:30:00+01:00", "to": "2026-11-30T19:36:00+01:00", "max_pictures": 30 }' ``` - A bridge camera with its archive on (the default for a new one). A window of up to 6 hours; give the time zone. - `max_pictures` 1 to 60, default 30, spread over the window. A motion burst counts as one place; room left goes to the bursts. `only_motion: true` keeps the bursts only. - €0.01 per request, refunded when nothing comes back. Test keys are free. ### Wait for it The bridge picks the request up within a second or two (Bridge 2.9.1 and later; older bridges within 30 seconds) and sends small versions, 480 pixels wide. Wait for the `pictures.ready` webhook, or read `GET /v1/pictures/pic_123`. The pictures come in time order. GET /v1/pictures/pic_123: ``` { "id": "pic_123", "object": "pictures", "camera": "cam_123", "mode": "live", "from": "2026-11-30T18:30:00Z", "to": "2026-11-30T18:36:00Z", "max_pictures": 30, "only_motion": false, "status": "ready", "reason": null, "cost_eur": "0.01", "created": "2026-11-30T20:02:10Z", "finished": "2026-11-30T20:02:13Z", "pictures": [ { "id": "pi_1", "object": "picture", "captured": "2026-11-30T18:33:06Z", "motion": true, "small_url": "https://api.camly.ai/v1/pictures/pic_123/pi_1/small", "small_expires": "2026-12-01T20:02:12Z", "full": { "status": "none", "reason": null, "url": null, "expires": null } } ] } ``` `reason: "no_pictures"` means the archive holds nothing in that window (pruned, or the camera was off). A bridge that stays silent for an hour ends the request as `expired`. Both are refunded. ### Show the small pictures ``` curl https://api.camly.ai/v1/pictures/pic_123/pi_1/small \ -H "Authorization: Bearer $CAMLY_API_KEY" -o pi_1.jpg ``` Fetch them from your server with your key and show them in your app. They are kept 24 hours. Never put your key in a page or a phone app: serve the pictures through your own backend. ### Keep the one chosen ``` curl -X POST https://api.camly.ai/v1/pictures/pic_123/pi_1/keep \ -H "Authorization: Bearer $CAMLY_API_KEY" ``` The bridge sends the full picture as it archived it: up to 1920 pixels wide from Bridge 2.9.0, 1280 before. `picture.kept` tells you when it is there; then `GET /v1/pictures/pic_123/pi_1` returns it. It is kept for the project’s retention period, 30 days by default, and `DELETE /v1/pictures/pic_123/pi_1` erases it sooner. Keeping is free. `full.status: "failed"` with `reason: "pruned"` means the bridge no longer had it: keep pictures soon after asking. ### Best first: rank the window with Find **Beta.** Add a Find to the request, or to a picker link, and every picture of the window is checked as it arrives: the pictures come back with the most likely first, each with `find` (`flagged`, `score`, the items seen and their boxes). On a picker page the likely ones are marked and what was found is circled; the person keeps or redraws the circles. ``` curl https://api.camly.ai/v1/cameras/cam_123/pictures \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "from": "2026-11-30T19:30:00+01:00", "to": "2026-11-30T19:36:00+01:00", "find": { "items": [ { "item": "white_wrap", "count": 2 } ] } }' ``` Each picture checked is a check at the usual price, on top of the request: up to 30 pictures, €0.15 at most. From Bridge 2.9.2 the bridge sends these pictures at 1280 pixels so the check sees them as well as a look-back does; older bridges send 480. When a picker’s Find names exactly one item, the circles drawn on the chosen picture become that item’s references on this camera. ### No screen of your own: send a link If you have no app for the people on site, Camly hosts the page. Create a picker link and send it by SMS, e-mail or chat to the person who knows what happened. They open it on their phone, with no account: the page shows the pictures of the window, they tap one, may circle what proves it, and send it. ``` curl https://api.camly.ai/v1/cameras/cam_123/picker \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "from": "2026-11-30T19:28:00+01:00", "to": "2026-11-30T19:36:00+01:00", "title": "Order 4F2 - 2 x Menu Mega Crunch Steak", "reference": "order-4F2", "locale": "fr" }' ``` - The answer carries `url`, shown once: send it as it is. Anyone with the link can see the pictures of that window for 24 hours and choose one picture, once. - The page says who asks: your organisation’s name, or `from_name`. `locale` is `en` or `fr`. A small “by Camly” sits at the foot. - It opens a pictures request, so it costs €0.01, refunded when nothing comes back. Choosing is free. - Once the full picture is kept, `picker.chosen` brings it: `chosen.full.url`, the time, and `chosen.boxes`, what the person circled, as `[x1, y1, x2, y2]` in 0–1 units of the picture. `reference` comes back as you sent it. Or read `GET /v1/pickers/pk_123`. ### What a picture proves - A picture proves what it shows, at the time it was taken. On a counter with several orders, it shows items that look like those of the order, not that they were that order: say so to whoever reads it. - The archive is on your customer’s site. What it films, how long it is kept and how people are informed are your responsibility, under the rules that apply to you. ## Items for Find A Find counts items. Name the ones your customers’ questions are about once, in a library kept per project, and every Find can use them by key. On each camera, crops of the real item (references) teach the model what it looks like there: same angle, same light. ### Create an item ``` curl https://api.camly.ai/v1/items \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "key": "white_wrap", "name": "White wrap", "description": "a sandwich wrapped in white paper, a ticket stapled on it" }' ``` The key is what a Find names: lower case letters, digits, `-` and `_`. The description is what the model reads with every Find that names it; a Find may add detail with its own `description`. At most 100 items per project, in each mode. A dozen generic ones (a wrapped sandwich, a paper bag, a kids’ box, a foam box, a drink) cover most restaurants; a chain reuses its own across all its sites. ### References, per camera They come by themselves: when a picker link’s Find names exactly one item, the circles the person draws on the chosen picture are saved as that item’s references on that camera. You can also cut one out of a picture of a pictures request: ``` curl https://api.camly.ai/v1/items/white_wrap/references \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "camera": "cam_123", "pictures": "pic_123", "picture": "pi_1", "box": [ 0.6, 0.4, 0.78, 0.67 ] }' ``` A Find naming the item on that camera gets up to three of its most recent references, as one picture beside the camera’s, at no extra cost. Ten are kept per camera, the oldest go first; they stay as long as the item. `GET /v1/items/white_wrap/references` lists them, `DELETE` removes one, and deleting the item removes them all. ## Chat Talk about a picture, or about what your monitors found. `POST /v1/chat` answers in plain words, for a person: a check gives your code a verdict, a chat gives someone an explanation. ### The request - `messages`: the conversation so far, each with `role` (`user` or `assistant`) and `content`, ending with the user. Up to 40 messages; a user message has at most 1000 characters. - `image`: a picture in base64, to talk about. - `incidents`: to talk about what monitors found. `hours` looks back from now (default 24, at most 168); `camera` and `monitor` narrow it down, and the 50 latest are used. Needs the `monitors:read` scope, so a Full access key. - `language` (`en` or `fr`), `model_tier` (`lite` or `pro`) and `stream` (default true). Send `image`, `incidents`, or both. The answer keeps to them: what they do not show, it says it cannot tell. Nothing of the conversation is stored, so send the history each time, with the answers as `assistant` messages. Only the charge is recorded. ### Streaming By default the answer comes as Server-Sent Events, one JSON object per `data:` line: `{"type":"delta","text":"..."}` pieces, then `{"type":"done",...}` with the whole `text`, the `usage` and the `id`, or `{"type":"error","error":{...}}`. Python: ``` import json, os, requests history = [{"role": "user", "content": "What happened at the dock last night?"}] r = requests.post( "https://api.camly.ai/v1/chat", headers={"Authorization": f"Bearer {os.environ['CAMLY_API_KEY']}"}, json={"messages": history, "incidents": {"hours": 24}}, stream=True, timeout=120, ) r.raise_for_status() for line in r.iter_lines(): if not line.startswith(b"data: "): continue event = json.loads(line[6:]) if event["type"] == "delta": print(event["text"], end="", flush=True) elif event["type"] == "done": history.append({"role": "assistant", "content": event["text"]}) elif event["type"] == "error": raise RuntimeError(event["error"]["message"]) ``` JavaScript: ``` const history = [{ role: 'user', content: 'What happened at the dock last night?' }]; const r = await fetch('https://api.camly.ai/v1/chat', { method: 'POST', headers: { Authorization: `Bearer ${process.env.CAMLY_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ messages: history, incidents: { hours: 24 } }), }); if (!r.ok) throw new Error((await r.json()).error.message); const decoder = new TextDecoder(); let buffer = ''; for await (const chunk of r.body) { buffer += decoder.decode(chunk, { stream: true }); const parts = buffer.split('\n\n'); buffer = parts.pop(); for (const part of parts) { if (!part.startsWith('data: ')) continue; const event = JSON.parse(part.slice(6)); if (event.type === 'delta') process.stdout.write(event.text); if (event.type === 'done') history.push({ role: 'assistant', content: event.text }); if (event.type === 'error') throw new Error(event.error.message); } } ``` ### The whole answer at once With `stream` false, the call answers with one JSON object. ``` curl https://api.camly.ai/v1/chat \ -H "Authorization: Bearer $CAMLY_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "messages": [ { "role": "user", "content": "Is the marked exit clear in this picture?" } ], "image": "", "language": "en", "stream": false }' ``` The answer: ``` { "id": "run_...", "object": "chat", "mode": "live", "text": "No. Two pallets stand inside the marked exit.", "usage": { "checks": 2, "cost_eur": "0.02" }, "created": "2026-11-06T09:30:12.482913Z" } ``` ### Rules and price - Every user message is screened against the acceptable-use policy, earlier ones included; a refused one answers `422 policy_refusal`. The assistant does not identify people or judge an individual’s work. - A message costs 2 checks, whatever the length of the history. - A failed answer is not charged: `error` in the stream, or a 502 without it. If you disconnect during a stream, the message is charged once some of the answer has reached you, and not before. - Refusals such as 402 and 429 arrive as normal HTTP errors, before the stream starts. ### Test keys A test key answers a fixed text, free, in the same pieces and with the same events, and never calls the model: it says how many incidents were in scope. Build your streaming and your history on it; the answer does not depend on the picture or the question. ## Keys Send the key as `Authorization: Bearer cmly_sk_...`. Keep it on your server: anyone with it spends your balance. - **Live keys** (`cmly_sk_live_`) are charged to your prepaid balance. - **Test keys** (`cmly_sk_test_`) are free and never call the model. The answer is derived from the picture’s bytes: the same picture always gives the same answer, so your tests are repeatable. - **Full access** keys run checks and manage agents, cameras, monitors and webhooks; **Run only** keys only run, for a key shipped inside a device; **Push only** keys only send pictures to cameras, for a device that does nothing else. ## Agent types An agent configuration says what to look for. Points are `[x, y]` in 0–1 picture units from the top-left corner, so they work at any resolution. ### `event` A yes or no question about the picture. flagged is the answer. Configuration: ``` { "config": { "type": "event", "question": "Is the marked fire exit blocked?" } } ``` The answer, in result: ``` { "flagged": true, "confidence": 0.86, "description": "Two pallets stand inside the marked exit.", "regions": [ { "label": "pallet", "point": [0.52, 0.7] } ] } ``` ### `detect` Find classes of objects, optionally inside a zone. flagged means at least one was found; regions say where. Configuration: ``` { "config": { "type": "detect", "classes": [ "pallet", "forklift" ], "zone": [ [0.1, 0.5], [0.9, 0.5], [0.9, 1], [0.1, 1] ] } } ``` The answer, in result: ``` { "flagged": true, "confidence": 0.91, "description": "Three pallets and one forklift are in the marked zone.", "regions": [ { "label": "pallet", "point": [0.21, 0.64] }, { "label": "pallet", "point": [0.42, 0.655] }, { "label": "pallet", "point": [0.59, 0.61] }, { "label": "forklift", "point": [0.78, 0.72] } ] } ``` ### `measure` Read a value. With a condition, flagged and condition_met say whether it is met. A reference_image with a known reference_value calibrates the reading (2 checks). Configuration: ``` { "config": { "type": "measure", "question": "How full is the silo?", "measure": { "variable": "level", "unit": "%", "condition": { "op": "lt", "value": 20 } } } } ``` The answer, in result: ``` { "flagged": true, "confidence": 0.88, "description": "The silo gauge reads about 14 %. Measured level: 14 %", "regions": [ { "label": "gauge", "point": [0.48, 0.35] } ], "measurement": { "variable": "level", "value": 14.0, "unit": "%" }, "condition_met": true } ``` ### `tracker` Follow one object or vehicle: send its picture as reference_image and a new picture as image (2 checks). track.identity says whether it is the same one (same, different or unknown); track.moved whether it moved. When the subject is not in the picture, flagged is false and identity is unknown. Trackers never follow people. Configuration: ``` { "config": { "type": "tracker", "subject": "the white van" } } ``` The answer, in result: ``` { "flagged": true, "confidence": 0.93, "description": "The same white van is parked two bays further left.", "regions": [ { "label": "the white van", "point": [0.31, 0.56] } ], "track": { "identity": "same", "moved": true } } ``` ### `read` Read a reference, a number or a label. text is what was read, a ? standing for a character that could not be read. With expect, matched says whether the text read contains it, ignoring case, spaces and separators, and flagged follows it. expect is never shown to the model: it reads blind and the API compares. Configuration: ``` { "config": { "type": "read", "question": "The reference printed on the label", "expect": "AB-4471" } } ``` The answer, in result: ``` { "flagged": true, "confidence": 0.94, "description": "A label is visible on the box.", "regions": [ { "label": "label", "point": [0.44, 0.52] } ], "text": "AB-4471", "matched": true } ``` ### `find` Beta: its accuracy has not yet been measured on real pictures; check the pictures it picks before relying on them. Count given items in a picture of the past: in a look-back, or to rank the pictures of a window. Not on monitors. items: 1 to 5, each an item of your library (item, its key) and/or a description, with count, the least wanted. together (default true): every item in the same picture, or one is enough. question: an optional condition on the rest of the scene. The result has items, with seen, wanted, found and boxes ([x1, y1, x2, y2] in 0-1); found_all; and score from 0 to 1, how fully the items are there. flagged needs the counts, checked by the API, not only the model’s word. One check per picture, references included. A Find proves that things looking like the items were there, not which order or parcel they belonged to. Configuration: ``` { "config": { "type": "find", "items": [ { "item": "white_wrap", "count": 2 } ], "question": "a delivery person stands at the counter" } } ``` The answer, in result: ``` { "flagged": true, "confidence": 0.84, "description": "Two white wraps lie on the right of the counter; a courier stands in front.", "regions": [ { "label": "white wrap", "point": [0.69, 0.53] } ], "items": [ { "item": "white_wrap", "description": "a sandwich wrapped in white paper", "wanted": 2, "seen": 2, "found": true, "boxes": [ [0.6, 0.4, 0.69, 0.66], [0.69, 0.42, 0.78, 0.67] ] } ], "found_all": true, "score": 1 } ``` ### Common settings Every type also takes `threshold` (the `confidence` needed to flag, from 0 to 1, default 0.7: `confidence` in the answer is on the same scale), `language` (`en` or `fr`, for the description) and `model_tier` (`lite`, or `pro` when your plan has it). ### Zone and line Any type can take a `zone`, 3 to 32 points: the model is shown it outlined on the picture and judges only what is inside. Write the question about it, such as “Is a pallet inside the marked zone?”. A `line` counts crossings: `{"points": [[0.2, 0.6], [0.8, 0.6]], "direction": "any"}`. With `left` or `right`, only crossings towards that side count, seen going from the first point to the second; the picture then shows an arrow. A crossing is movement, so a line works best with a burst of pictures. The marks are drawn on a copy for the model; your picture is not changed. Draw them on a sample picture in the Agent builder, then copy the configuration. ## Pictures - JPEG, PNG, WebP or BMP, at most 10 MB. Larger sides are scaled down to 1280 pixels; nothing is kept after the answer. - JSON bodies take base64 in `image`; multipart bodies take files in `image` and the configuration as JSON text in `config`. - A burst of 2 to 6 pictures in time order (`images`, or `image` repeated in multipart) lets event and detect see movement. It counts as 3 checks. ## Saved agents Save a configuration once, in the Agents page or with `POST /v1/agents`, and run it by id: `{"agent": "agt_...", "image": "..."}`. Each change is a new version, added with `POST /v1/agents/{id}/versions` and read with `GET /v1/agents/{id}/versions/{n}`. Earlier versions stay runnable with `version`, so a device in the field keeps its behaviour until you move it. An agent cannot be deleted by API: archive it in the console. ## Retries Send an `Idempotency-Key` header (any unique string, such as the picture’s id) to retry safely after a timeout: the same key returns the first answer and is charged once. A 502 is never charged; retry it with a short back-off. ## Send from a device A camera board can call the API itself, with no server in between. The example is an ESP32-CAM, a Wi-Fi camera board programmed in C++ with the Arduino IDE; the same steps hold for any device. A device running Linux (a Raspberry Pi, a gateway) is simpler: use the Python example from Quick start on a timer. A network camera that can send pictures over HTTPS needs no code at all: see Let the camera send. ### Before you start - **A Run only key.** The key is stored on the device, so anyone holding the board can read it. A Run only key can run checks but cannot read or change your agents; revoke it in API keys if a board goes missing. Build with a test key: it is free and answers the same way for the same picture. - **A saved agent.** Save the configuration in Agents and put only its id on the device. You can then change the question from the console without touching the board, and pin a `version` to keep its behaviour fixed. - **The root certificate.** The board checks it is talking to Camly before it sends the key. Get the root certificate with `openssl s_client -showcerts -connect api.camly.ai:443` (the last certificate of the chain) and paste it into `ROOT_CA`. Never turn the check off: the key would travel to whoever answers. ### The sketch It takes an 800 × 600 picture every minute and sends it as multipart, the JPEG bytes as they are: base64 would need a third more memory than the board has to spare. The answer lights the board’s LED while `flagged` is true; replace that with a relay, a buzzer or a message. ``` // ESP32-CAM (AI-Thinker) + Camly: one picture a minute, checked by a saved agent. // Arduino IDE, board "AI Thinker ESP32-CAM", library ArduinoJson 7. #include #include #include #include "esp_camera.h" const char* WIFI_SSID = "your-network"; const char* WIFI_PASS = "your-password"; const char* API_HOST = "api.camly.ai"; const char* API_KEY = "cmly_sk_test_..."; // a Run only key; a test key while you build const char* AGENT_ID = "agt_..."; // the saved agent this camera runs const char* DEVICE_ID = "dock-3"; // names this camera in the Idempotency-Key const char* ROOT_CA = R"(-----BEGIN CERTIFICATE----- ...the root certificate of api.camly.ai, see "Before you start"... -----END CERTIFICATE-----)"; const unsigned long EVERY_MS = 60UL * 1000; const int LED_PIN = 4; // the board's white LED: lit while flagged bool startCamera() { camera_config_t c = {}; c.pin_pwdn = 32; c.pin_reset = -1; c.pin_xclk = 0; c.pin_sccb_sda = 26; c.pin_sccb_scl = 27; c.pin_d7 = 35; c.pin_d6 = 34; c.pin_d5 = 39; c.pin_d4 = 36; c.pin_d3 = 21; c.pin_d2 = 19; c.pin_d1 = 18; c.pin_d0 = 5; c.pin_vsync = 25; c.pin_href = 23; c.pin_pclk = 22; c.xclk_freq_hz = 20000000; c.ledc_timer = LEDC_TIMER_0; c.ledc_channel = LEDC_CHANNEL_0; c.pixel_format = PIXFORMAT_JPEG; c.frame_size = FRAMESIZE_SVGA; // 800 x 600 is plenty: larger sides are scaled to 1280 c.jpeg_quality = 12; c.fb_count = 1; c.fb_location = CAMERA_FB_IN_PSRAM; c.grab_mode = CAMERA_GRAB_LATEST; return esp_camera_init(&c) == ESP_OK; } // Sends one picture. Returns the HTTP status (0 when the connection failed); sets flagged and, // on a 429, retryAfter in seconds. int sendFrame(uint32_t n, bool& flagged, int& retryAfter) { camera_fb_t* fb = esp_camera_fb_get(); if (!fb) return 0; WiFiClientSecure tls; tls.setCACert(ROOT_CA); tls.setTimeout(60); if (!tls.connect(API_HOST, 443)) { esp_camera_fb_return(fb); return 0; } String boundary = "camly" + String(esp_random(), HEX); String head = "--" + boundary + "\r\n" "Content-Disposition: form-data; name=\"agent\"\r\n\r\n" + AGENT_ID + "\r\n" "--" + boundary + "\r\n" "Content-Disposition: form-data; name=\"image\"; filename=\"frame.jpg\"\r\n" "Content-Type: image/jpeg\r\n\r\n"; String tail = "\r\n--" + boundary + "--\r\n"; // HTTP/1.0: the answer comes back in one piece, never chunked. tls.printf("POST /v1/runs HTTP/1.0\r\nHost: %s\r\n", API_HOST); tls.printf("Authorization: Bearer %s\r\n", API_KEY); tls.printf("Idempotency-Key: %s-%lu\r\n", DEVICE_ID, (unsigned long)n); tls.printf("Content-Type: multipart/form-data; boundary=%s\r\n", boundary.c_str()); tls.printf("Content-Length: %u\r\n\r\n", (unsigned)(head.length() + fb->len + tail.length())); tls.print(head); for (size_t i = 0; i < fb->len; i += 1024) tls.write(fb->buf + i, std::min(1024, fb->len - i)); tls.print(tail); esp_camera_fb_return(fb); int status = tls.readStringUntil('\n').substring(9, 12).toInt(); while (tls.connected() || tls.available()) { String line = tls.readStringUntil('\n'); if (line.startsWith("Retry-After:")) retryAfter = line.substring(12).toInt(); if (line == "\r") break; // end of the headers } String body = tls.readString(); tls.stop(); JsonDocument run; if (status == 200 && !deserializeJson(run, body)) flagged = run["result"]["flagged"] | false; else Serial.printf("Camly answered %d: %s\n", status, body.c_str()); return status; } void setup() { Serial.begin(115200); pinMode(LED_PIN, OUTPUT); WiFi.begin(WIFI_SSID, WIFI_PASS); while (WiFi.status() != WL_CONNECTED) delay(500); if (!startCamera()) { Serial.println("Camera failed to start"); ESP.restart(); } } void loop() { static uint32_t n = 0; n++; // one number per picture, kept across retries for (int attempt = 0; attempt < 3; attempt++) { bool flagged = false; int retryAfter = 0; int status = sendFrame(n, flagged, retryAfter); if (status == 200) { digitalWrite(LED_PIN, flagged ? HIGH : LOW); break; } if (status == 429) { delay(1000UL * (retryAfter > 0 ? retryAfter : 10)); continue; } if (status == 0 || status >= 500) { delay(2000UL << attempt); continue; } // never charged: retry Serial.println("Fix the key, the balance or the agent before sending more."); while (true) delay(60000); // 401, 402, 403, 404, 422: retrying will not help } delay(EVERY_MS); } ``` ### Answers and retries - **200:** read `result.flagged`, and `result.description` if the device shows text. - **429:** too many checks this minute. Wait for `Retry-After` seconds, then send again. - **502 or no connection:** nothing was charged. Retry with a growing pause and the same `Idempotency-Key` (the device id and the picture number), so a picture that did go through is never charged twice. - **401, 402, 403, 404, 422:** the key, the balance or the agent needs fixing. Stop sending: retrying only repeats the refusal. ### How often to send Every picture is one check. One a minute is 1,440 checks a day, €7.2 at the lite price of €0.005; one every five minutes is a fifth of that. Send as often as the thing you watch can change, and set a budget on the key in Billing so a board stuck in a loop cannot spend more than you planned. ## Errors Every error has the same shape: `{"error": {"type", "code", "message", "request_id"}}`. Quote the request id when you write to support. | Status | Code | Meaning | | --- | --- | --- | | 401 | `invalid_api_key` | The key is missing, unknown or revoked. | | 402 | `insufficient_balance` | The balance cannot pay for this run. Top up in Billing. | | 402 | `budget_exceeded` | A hard budget on the organisation, project or key would be passed. | | 403 | `missing_scope` | The key’s access does not cover this call: a Run only key cannot manage agents. | | 404 | `not_found` | The object is not in this key’s project and mode. | | 409 | `camera_on_bridge` | This camera is fed by its bridge: your code cannot push to it. | | 409 | `camera_simulated` | A simulated camera makes its own pictures: use its simulate call. | | 409 | `camera_has_no_archive` | A pushed camera has no archive: only a bridge keeps pictures on site. | | 409 | `archive_off` | This camera keeps no archive: set archive on the camera first. | | 422 | `invalid_config` | The configuration is not valid; the message names the field. | | 422 | `policy_refusal` | The configuration asks for a use the policy forbids. | | 422 | `agent_not_supported` | Trackers and calibrated measures are not available on monitors yet. | | 422 | `interval_too_short` | min_interval_seconds is under 10 with a live key. | | 422 | `test_only` | Simulated cameras exist with test keys only. | | 422 | `invalid_request` | A field is missing or has the wrong type; the message names it. | | 422 | `unknown_field` | The body has a field the API does not know. Check its spelling. | | 422 | `invalid_json` | The body is not valid JSON. | | 422 | `unsupported_content_type` | Send application/json or multipart/form-data. | | 422 | `missing_config` | Send config or a saved agent. | | 422 | `missing_image` | Send one picture in image, or 2 to 6 in images. | | 422 | `invalid_image` | The picture is not base64 or not a picture. | | 422 | `image_too_large` | A picture is larger than 10 MB. | | 422 | `too_many_images` | A burst has at most 6 pictures. | | 422 | `burst_not_supported` | Bursts work with event and detect only. | | 422 | `missing_reference` | measure.reference_value needs a reference_image. | | 422 | `reference_not_supported` | reference_image is for a tracker, or a measure with reference_value. | | 422 | `invalid_version` | version is a positive whole number. | | 422 | `tier_unavailable` | This model_tier is not available on your account yet. | | 422 | `invalid_idempotency_key` | An Idempotency-Key has 1 to 255 characters. | | 422 | `idempotency_mismatch` | This Idempotency-Key was used with a different request. | | 409 | `idempotency_in_progress` | A request with this Idempotency-Key is still running. Retry in a moment. | | 409 | `agent_archived` | This agent is archived. Restore it in the console, or use another. | | 409 | `camera_not_simulated` | Only a simulated camera can be ticked. | | 403 | `organisation_suspended` | The organisation is suspended. Write to support@camly.ai. | | 422 | `too_many_agents` | At most 200 agents per project. Archive some in the console. | | 422 | `too_many_versions` | This agent has too many versions. Create a new agent. | | 422 | `too_many_cameras` | At most 200 cameras per project and mode. | | 422 | `too_many_monitors` | At most 5 monitors per camera. | | 422 | `too_many_endpoints` | At most 10 webhook endpoints per project and mode. | | 422 | `invalid_webhook_url` | A webhook address must be public https. | | 429 | `rate_limit_exceeded` | Too many checks this minute. Wait for Retry-After seconds. | | 502 | `vision_unavailable` | No usable answer for this picture. You were not charged; retry. | ## Limits and prices One check (one picture, one question) costs €0.005 on lite; a check made by a monitor costs €0.006, because the monitor also keeps state, opens incidents and keeps their evidence. A tracker or a calibrated measure is 2 checks, a burst 3. A look-back picture is charged as a normal check but does not count against your rate limit. Your rate limit, in checks a minute, is on the Overview page; past it the API answers 429 with `Retry-After`. Budgets in Billing cap what a key, a project or the organisation spends each month. A chat message costs €0.02 and counts as 2 checks against your rate limit. A request for the pictures of a window costs €0.01, refunded when nothing comes back; keeping a picture is free. Monitoring has its own limits: 200 cameras per project and mode, 5 monitors per camera, 10 webhook endpoints, and a shortest interval of 10 seconds on live monitors. From 1 December 2026, each live camera with an active monitor also costs €2 a month; bridges, cameras without a monitor and everything in test mode stay free. The Limits page shows what you use. `GET /v1/balance` gives your balance, so your code can warn you before it runs out. ## Acceptable use Camly looks at places, objects and vehicles. It does not identify people, infer their emotions or sensitive traits, or profile individuals. Configurations are screened when they are saved and when they are sent inline; a refused one answers `422 policy_refusal` with the rule it breaks. Counting people, checking that a zone is empty and safety checks such as a person on the floor are fine.