HTTP API
This page shows you how to call Sensora from a script: which address to use, when you need a key, and the calls that scripts need most often. The complete list of endpoints is the OpenAPI document that every instance serves.
Base address
The examples use http://localhost:8090, the default address of an instance on your own computer. Replace it with the address of your instance.
The bundled stack serves plain HTTP. For access from outside your own network, put it behind HTTPS first. See Security.
There are three kinds of paths:
| Paths | Who calls them | How the caller is identified |
|---|---|---|
/api/... | The dashboard, your scripts, agents | An API key or the dashboard session, when the API is locked |
/ingest, /ingest/announce, /api/integrations/:token/webhook, /ota/... | Devices and services that send data | The device id and secret, or the webhook token. Never an API key |
/health, /llms.txt, /api/llms.txt, /api/openapi.json, /firmware/..., /api/public/dashboards/:token | Anyone | Nothing. These are public |
The customer app has its own API under /api/portal/v1/ with its own tokens. See The customer app.
The OpenAPI document
Every instance serves its API as an OpenAPI 3.1 document. It needs no key.
curl http://localhost:8090/api/openapi.jsonEach operation that needs a key has an x-sensora-scope field with the scope it needs. You can load the document into any OpenAPI tool to browse it or to generate a client.
When you need a key
- The API is open. A new instance has no dashboard password and no API keys. Every request to
/apiis accepted and treated like the dashboard. Anyone who can reach the instance can read, change and delete everything, and can approve a rule that an agent wrote. The examples on this page then work without theAuthorizationheader. - The API is locked. The API is locked when a dashboard password is set (
SENSORA_DASHBOARD_PASSWORD), when keys are listed inAPI_KEYS, or when at least one key exists under Settings › API keys. Every request to/apithen needs a key or the dashboard session.
Send the key as a bearer token:
GET /api/devices HTTP/1.1
Host: localhost:8090
Authorization: Bearer sk-api-...The examples below read the key from a shell variable:
export SENSORA_KEY="sk-api-..."API keys and scopes
You create keys under Settings › API keys. Type a name, choose a scope and select Create key. A key starts with sk-api-. The full key is shown once, and Sensora stores only a hash of it. The list shows the name, the last 4 characters, the scope, and when the key was created and last used. Revoke stops a key at once.
The first key locks the API
On an open instance, creating the first key locks the API for every browser, script and agent. The first key must be an Admin key. The server refuses any other scope with status 409 and the error first_key_must_be_admin. Revoking the last key opens the API again.
While other keys exist and no dashboard password or API_KEYS is set, the server refuses to revoke the only Admin key (last_admin_key). Nobody could manage keys afterwards.
| Scope on screen | Value in the API | What a key with this scope can do |
|---|---|---|
| Read | read | Every GET request, except the admin paths below. Also three POST requests that change nothing: /api/data/query, /api/templates/detect and /api/dashboards/preview-widget |
| Agent | propose | Everything in Read, plus the MCP endpoint POST /api/mcp. It makes no other change over HTTP. See Connect an agent |
| Write | write | Everything in Read, plus every other POST, PUT, PATCH and DELETE request, except the admin paths. A Write key can also use the MCP endpoint |
| Admin | admin | Everything, including the admin paths |
The scopes are ordered: Read, Agent, Write, Admin. Each scope includes the ones before it.
The admin paths are:
/api/api-keys: list, create and revoke keys./api/customers,/api/claim-codesand/api/customer-app: all requests, reads included./api/firmware/keys: adding and removing the keys that firmware uploads must be signed with. Listing them needs Read.
One more thing needs an Admin key or the dashboard: approving a rule or a rule change that an agent wrote. A Write key gets status 403 with the error needs_a_person, and a lower key gets 403 forbidden. See Approvals.
You can also define keys in the environment with API_KEYS. Those keys always have the Admin scope. See Configuration.
The dashboard session
When a dashboard password is set (SENSORA_DASHBOARD_PASSWORD), the dashboard signs in with POST /api/session and gets a cookie named sensora_session. The cookie is valid for 30 days and counts as Admin. It is meant for browsers. For a script, use a key.
| Method and path | What it does |
|---|---|
GET /api/session | Returns {"required": true, "signed_in": false}. required is false when no password is set |
POST /api/session | Body {"password": "..."}. Answers 204 and sets the cookie, or 401 wrong_password. Without a password on the server it answers 409 no_password |
DELETE /api/session | Signs out |
Sensora has no user accounts. There is one shared password and any number of keys.
Errors
Errors are JSON. error is a short code. detail, when present, is a sentence that says what to change.
{ "error": "not_found" }{
"error": "unauthorized",
"detail": "This server needs a key. Send an API key as the header \"Authorization: Bearer <key>\". A person creates one under Settings → API keys in the dashboard."
}Two kinds of error have a different shape:
A rule graph that fails validation answers 400 with
"error": "graph validation failed"and a listissues. Each issue hasnode_id,fieldandmessage.On many endpoints, a request body with a missing or wrong field answers 400 with this shape:
json{ "success": false, "error": { "issues": [ { "code": "invalid_type", "expected": "string", "received": "undefined", "path": ["name"], "message": "Required" } ], "name": "ZodError" } }
| Status | Meaning |
|---|---|
| 400 | The request is not valid |
| 401 | A key is needed, or the key is unknown or revoked. On /ingest: the device id or secret is wrong |
| 403 | The key's scope is too low. detail names the scope that is needed |
| 404 | No such device, rule or other object |
| 409 | The request conflicts with the current state, for example rule_changed, first_key_must_be_admin or last_admin_key |
| 413 | The body is too large |
| 422 | On /ingest: the reading could not be decoded with the device's template (decode_failed) |
| 429 | A rate limit was passed |
| 500 | internal_error |
| 503 | The database did not answer. Try again after a few seconds. /health also answers 503 then |
Rate limits
Most /api endpoints have no rate limit. These endpoints do:
| Endpoint | Limit | Variable |
|---|---|---|
POST /ingest, POST /ingest/announce | For each device: 60 requests at once, then 1 a second. Requests with a wrong secret or a bad body count for each client address instead: 100 at once, then 50 a second | DEVICE_RATE_LIMIT_RPS, DEVICE_RATE_LIMIT_BURST, RATE_LIMIT_RPS, RATE_LIMIT_BURST |
POST /api/integrations/:token/webhook | For each token: 100 at once, then 50 a second | RATE_LIMIT_RPS, RATE_LIMIT_BURST |
POST /api/mcp | For each key: 60 calls at once, then 5 a second | Fixed |
POST /api/session | For each client address: 5 tries, then one every 12 seconds | Fixed |
GET /api/public/dashboards/:token | For each client address: 30 at once, then one every 2 seconds. For each link: 120 at once, then 2 a second | Fixed |
POST /api/rules/:id/health/check | One check a minute for each rule | Fixed |
A request over the limit answers 429 with {"error": "rate_limited"}. Two endpoints answer differently: /api/mcp with a JSON-RPC error and the header Retry-After: 1, and the health check with checked_just_now and Retry-After: 60. The device endpoints under /ota and the customer app API have their own limits.
The body of a request to /ingest or to a webhook can be at most 10 MB (INGEST_MAX_BODY_BYTES). A larger body answers 413 payload_too_large. A request to /api/mcp can be at most 1 MB and can hold at most 20 JSON-RPC messages.
Calls that scripts need most
On an open instance the Authorization header is not needed. If you send it, it is ignored.
Check that the server is up
curl http://localhost:8090/health{"status":"ok","time":"2026-11-19T19:30:00.000Z"}List devices
curl -H "Authorization: Bearer $SENSORA_KEY" \
"http://localhost:8090/api/devices?status=offline"The answer is a JSON array. You can filter with status (online, offline, provisioned or alerts), zone (the name of the site), template, low_battery=true and q (text in the name or id).
Create a device
This needs a Write key.
curl -X POST http://localhost:8090/api/devices \
-H "Authorization: Bearer $SENSORA_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Shed sensor"}'The answer has status 201. The secret is shown once.
{"device_uid":"dev_e77cd028","secret":"sec_..."}Optional fields are template, integration, zone, external_id and firmware.
Send a reading
A device identifies itself with its own id and secret, not with an API key.
curl -X POST http://localhost:8090/ingest \
-u "dev_e77cd028:sec_..." \
-H "Content-Type: application/json" \
-d '{"temperature": 18.4, "humidity": 61}'{"ok":true,"device_uid":"dev_e77cd028","stored":2}You can also put the id and secret in the body as uid and secret. See Send data over HTTP.
Read the latest values of a device
curl -H "Authorization: Bearer $SENSORA_KEY" \
http://localhost:8090/api/devices/dev_e77cd028/metrics/latest[
{"metric":"humidity","value":61,"unit":"","recorded_at":"2026-11-19T18:01:45.368Z","sim":false},
{"metric":"temperature","value":18.4,"unit":"","recorded_at":"2026-11-19T18:01:45.368Z","sim":false}
]Query the history with SQL
There is no separate endpoint for the history of a metric. You read history with one read-only SQL query. A Read key is enough.
curl -X POST http://localhost:8090/api/data/query \
-H "Authorization: Bearer $SENSORA_KEY" \
-H "Content-Type: application/json" \
-d "{\"sql\": \"SELECT date_trunc('hour', recorded_at) AS hour, round(avg(value)::numeric, 2) AS avg_temperature FROM metrics WHERE device_uid = 'dev_e77cd028' AND metric = 'temperature' AND recorded_at > now() - interval '24 hours' GROUP BY 1 ORDER BY 1\"}"{"cols":[["hour","timestamptz"],["avg_temperature","numeric"]],"rows":[["2026-11-19T18:00:00.000Z",18.4]],"ms":"2"}The query runs in a read-only transaction. It stops after 5 seconds and returns at most 1,000 rows. The answer does not say when rows were cut, so treat exactly 1,000 rows as a cut result. The SQL can be at most 20,000 characters. GET /api/data/schema lists the tables and columns. See Explore data.
Read recent events
curl -H "Authorization: Bearer $SENSORA_KEY" \
"http://localhost:8090/api/events?limit=20"limit is at most 200. See Logs.
Follow live events
GET /api/stream is a Server-Sent Events stream. Choose what to receive with topics: fleet, ingestion, logs, and device:<uid> for one device.
curl -N -H "Authorization: Bearer $SENSORA_KEY" \
"http://localhost:8090/api/stream?topics=logs,device:dev_e77cd028"The stream sends an event named ready when it is open, and an event named ping every 15 seconds. Each data event has an id. After a disconnect, send the last id in the Last-Event-ID header. The server then first sends the events that you missed, as far as it still has them. It keeps the last 256 events in memory, and none after a restart.
A browser cannot set the Authorization header on an event stream. For a browser page on an instance that is locked with keys only, first get a ticket and then open the stream with it. A ticket is valid for 5 minutes and opens nothing but the stream.
curl -H "Authorization: Bearer $SENSORA_KEY" http://localhost:8090/api/stream-ticket{"ticket":"st1....","expires_in":300}Then open http://localhost:8090/api/stream?topics=logs&ticket=<ticket>.
Main endpoint groups
All paths start at the base address. The OpenAPI document has every endpoint with its request and response.
| Group | Method and path | What it does |
|---|---|---|
| Health | GET /health | Answers 200 when the database is reachable, 503 when it is not |
| Devices | GET /api/devices | Lists devices |
POST /api/devices | Creates a device and returns its secret once | |
GET /api/devices/:uid | Returns one device | |
PATCH /api/devices/:uid | Edits name, site, template, integration, external id and location | |
DELETE /api/devices/:uid | Deletes a device | |
GET /api/devices/:uid/metrics/latest | Latest value of each metric | |
GET /api/devices/:uid/baseline | Usual reporting interval and range of each metric | |
GET /api/devices/:uid/sensor-health | Sensor health of one device | |
POST /api/devices/:uid/simulate | Stores one simulated reading | |
| Sites | GET /api/device-groups, GET /api/device-groups/:name | Lists sites and returns one site |
| Ingest | POST /ingest | A device sends a reading |
POST /ingest/announce | A device describes its firmware and sensors | |
POST /api/integrations/:token/webhook | A service sends a payload to a webhook integration | |
| Readings | POST /api/data/query | Runs one read-only SQL query |
GET /api/data/schema | Lists the tables you can query | |
GET /api/data/saved-queries, POST, PUT /:id, DELETE /:id | Saved queries of the Data explorer | |
| Rules | GET /api/rules, POST /api/rules | Lists rules, creates a rule |
GET /api/rules/:id, PUT, DELETE | Reads, saves or deletes a rule | |
POST /api/rules/:id/enable, POST /api/rules/:id/disable | Turns a rule on or off. For a rule that waits for approval, enable is the approval. Send {"version": 3} to turn it on only if the rule is still at the version you read | |
POST /api/rules/draft | Turns a sentence into a draft graph. Saves nothing | |
POST /api/rules/:id/test, POST /api/rules/:id/replay | Test run, and replay over stored readings. A test sends real notifications and calls real webhooks unless the body has "dry_run": true. See Test a rule on real data | |
GET /api/rules/:id/executions, GET /api/rules/:id/logs | Run history and log lines of a rule | |
GET /api/rules/:id/versions, POST /api/rules/:id/versions/:n/restore | Versions with created_by, backtest, approved_by and approved_at, and restore one | |
GET /api/rules/:id/proposal | An agent's proposed change, with its id, graph, backtest and diff | |
POST /api/rules/:id/proposal/approve, POST /api/rules/:id/proposal/discard | Approves or discards the proposal. approve must name it in the body: {"proposal_id": "<id>"}. If the rule or the proposal changed since you read it, the answer is 409 with rule_changed, proposal_changed or proposal_out_of_date | |
| Dashboards | GET /api/dashboards, POST /api/dashboards | Lists dashboards, creates one |
GET /api/dashboards/:id, PUT, DELETE | Reads a dashboard with its widgets resolved, saves or deletes it | |
GET /api/dashboards/:id/shares, POST, DELETE /:shareId | Public links to a dashboard | |
GET /api/public/dashboards/:token | The public view of a shared dashboard. No key | |
| Integrations | GET /api/integrations, POST /api/integrations | Lists integrations, creates one |
GET /api/integrations/:name, PATCH, DELETE | Reads, edits or deletes an integration | |
GET /api/integrations/:name/inbox | What the integration received | |
POST /api/integrations/:name/inbox/:item/replay | Processes a held entry again | |
| Templates | GET /api/templates, POST /api/templates | Lists templates, creates one |
GET /api/templates/:id, PUT, DELETE | Reads, saves or deletes a template | |
POST /api/templates/detect | Proposes a template from a sample payload. Saves nothing | |
GET /api/template-library, POST /api/template-library/:id/import | The built-in library, and import from it | |
| Logs and events | GET /api/events | Recent events |
GET /api/fleet, GET /api/ingestion/stats, GET /api/insights | Device counts, ingestion numbers and the "Needs attention" items | |
| Live stream | GET /api/stream | Server-Sent Events |
GET /api/stream-ticket | A 5-minute ticket for the stream | |
| Notifications | GET /api/notifications, PUT /api/notifications | Channels and recipients |
| Firmware updates | GET /api/firmware/releases, GET /api/firmware/rollouts and more | See Firmware updates |
| Settings | GET /api/instance, PATCH /api/instance | Project name and settings |
GET /api/usage, GET /api/usage/retention, PATCH /api/usage/retention | Storage, usage and the retention policy | |
GET /api/api-keys, POST /api/api-keys, DELETE /api/api-keys/:id | API keys. Admin only | |
| Assistant and agents | GET /api/assistant/status, GET /api/ai/usage | Whether a model is connected, and token usage |
POST /api/mcp, GET /api/mcp/status | The MCP endpoint and its status |
Calls from a browser on another site
By default a browser only lets the dashboard's own pages call the API. To call it from a web page on another address, list that address in CORS_ALLOWED_ORIGINS. See Configuration.
