Skip to content

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:

PathsWho calls themHow the caller is identified
/api/...The dashboard, your scripts, agentsAn API key or the dashboard session, when the API is locked
/ingest, /ingest/announce, /api/integrations/:token/webhook, /ota/...Devices and services that send dataThe 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/:tokenAnyoneNothing. 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.

bash
curl http://localhost:8090/api/openapi.json

Each 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 /api is 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 the Authorization header.
  • The API is locked. The API is locked when a dashboard password is set (SENSORA_DASHBOARD_PASSWORD), when keys are listed in API_KEYS, or when at least one key exists under Settings › API keys. Every request to /api then needs a key or the dashboard session.

Send the key as a bearer token:

http
GET /api/devices HTTP/1.1
Host: localhost:8090
Authorization: Bearer sk-api-...

The examples below read the key from a shell variable:

bash
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 screenValue in the APIWhat a key with this scope can do
ReadreadEvery 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
AgentproposeEverything in Read, plus the MCP endpoint POST /api/mcp. It makes no other change over HTTP. See Connect an agent
WritewriteEverything in Read, plus every other POST, PUT, PATCH and DELETE request, except the admin paths. A Write key can also use the MCP endpoint
AdminadminEverything, 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-codes and /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 pathWhat it does
GET /api/sessionReturns {"required": true, "signed_in": false}. required is false when no password is set
POST /api/sessionBody {"password": "..."}. Answers 204 and sets the cookie, or 401 wrong_password. Without a password on the server it answers 409 no_password
DELETE /api/sessionSigns 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.

json
{ "error": "not_found" }
json
{
  "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 list issues. Each issue has node_id, field and message.

  • 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"
      }
    }
StatusMeaning
400The request is not valid
401A key is needed, or the key is unknown or revoked. On /ingest: the device id or secret is wrong
403The key's scope is too low. detail names the scope that is needed
404No such device, rule or other object
409The request conflicts with the current state, for example rule_changed, first_key_must_be_admin or last_admin_key
413The body is too large
422On /ingest: the reading could not be decoded with the device's template (decode_failed)
429A rate limit was passed
500internal_error
503The 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:

EndpointLimitVariable
POST /ingest, POST /ingest/announceFor 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 secondDEVICE_RATE_LIMIT_RPS, DEVICE_RATE_LIMIT_BURST, RATE_LIMIT_RPS, RATE_LIMIT_BURST
POST /api/integrations/:token/webhookFor each token: 100 at once, then 50 a secondRATE_LIMIT_RPS, RATE_LIMIT_BURST
POST /api/mcpFor each key: 60 calls at once, then 5 a secondFixed
POST /api/sessionFor each client address: 5 tries, then one every 12 secondsFixed
GET /api/public/dashboards/:tokenFor each client address: 30 at once, then one every 2 seconds. For each link: 120 at once, then 2 a secondFixed
POST /api/rules/:id/health/checkOne check a minute for each ruleFixed

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 ​

bash
curl http://localhost:8090/health
json
{"status":"ok","time":"2026-11-19T19:30:00.000Z"}

List devices ​

bash
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.

bash
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.

json
{"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.

bash
curl -X POST http://localhost:8090/ingest \
  -u "dev_e77cd028:sec_..." \
  -H "Content-Type: application/json" \
  -d '{"temperature": 18.4, "humidity": 61}'
json
{"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 ​

bash
curl -H "Authorization: Bearer $SENSORA_KEY" \
  http://localhost:8090/api/devices/dev_e77cd028/metrics/latest
json
[
  {"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.

bash
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\"}"
json
{"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 ​

bash
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.

bash
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.

bash
curl -H "Authorization: Bearer $SENSORA_KEY" http://localhost:8090/api/stream-ticket
json
{"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.

GroupMethod and pathWhat it does
HealthGET /healthAnswers 200 when the database is reachable, 503 when it is not
DevicesGET /api/devicesLists devices
POST /api/devicesCreates a device and returns its secret once
GET /api/devices/:uidReturns one device
PATCH /api/devices/:uidEdits name, site, template, integration, external id and location
DELETE /api/devices/:uidDeletes a device
GET /api/devices/:uid/metrics/latestLatest value of each metric
GET /api/devices/:uid/baselineUsual reporting interval and range of each metric
GET /api/devices/:uid/sensor-healthSensor health of one device
POST /api/devices/:uid/simulateStores one simulated reading
SitesGET /api/device-groups, GET /api/device-groups/:nameLists sites and returns one site
IngestPOST /ingestA device sends a reading
POST /ingest/announceA device describes its firmware and sensors
POST /api/integrations/:token/webhookA service sends a payload to a webhook integration
ReadingsPOST /api/data/queryRuns one read-only SQL query
GET /api/data/schemaLists the tables you can query
GET /api/data/saved-queries, POST, PUT /:id, DELETE /:idSaved queries of the Data explorer
RulesGET /api/rules, POST /api/rulesLists rules, creates a rule
GET /api/rules/:id, PUT, DELETEReads, saves or deletes a rule
POST /api/rules/:id/enable, POST /api/rules/:id/disableTurns 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/draftTurns a sentence into a draft graph. Saves nothing
POST /api/rules/:id/test, POST /api/rules/:id/replayTest 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/logsRun history and log lines of a rule
GET /api/rules/:id/versions, POST /api/rules/:id/versions/:n/restoreVersions with created_by, backtest, approved_by and approved_at, and restore one
GET /api/rules/:id/proposalAn agent's proposed change, with its id, graph, backtest and diff
POST /api/rules/:id/proposal/approve, POST /api/rules/:id/proposal/discardApproves 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
DashboardsGET /api/dashboards, POST /api/dashboardsLists dashboards, creates one
GET /api/dashboards/:id, PUT, DELETEReads a dashboard with its widgets resolved, saves or deletes it
GET /api/dashboards/:id/shares, POST, DELETE /:shareIdPublic links to a dashboard
GET /api/public/dashboards/:tokenThe public view of a shared dashboard. No key
IntegrationsGET /api/integrations, POST /api/integrationsLists integrations, creates one
GET /api/integrations/:name, PATCH, DELETEReads, edits or deletes an integration
GET /api/integrations/:name/inboxWhat the integration received
POST /api/integrations/:name/inbox/:item/replayProcesses a held entry again
TemplatesGET /api/templates, POST /api/templatesLists templates, creates one
GET /api/templates/:id, PUT, DELETEReads, saves or deletes a template
POST /api/templates/detectProposes a template from a sample payload. Saves nothing
GET /api/template-library, POST /api/template-library/:id/importThe built-in library, and import from it
Logs and eventsGET /api/eventsRecent events
GET /api/fleet, GET /api/ingestion/stats, GET /api/insightsDevice counts, ingestion numbers and the "Needs attention" items
Live streamGET /api/streamServer-Sent Events
GET /api/stream-ticketA 5-minute ticket for the stream
NotificationsGET /api/notifications, PUT /api/notificationsChannels and recipients
Firmware updatesGET /api/firmware/releases, GET /api/firmware/rollouts and moreSee Firmware updates
SettingsGET /api/instance, PATCH /api/instanceProject name and settings
GET /api/usage, GET /api/usage/retention, PATCH /api/usage/retentionStorage, usage and the retention policy
GET /api/api-keys, POST /api/api-keys, DELETE /api/api-keys/:idAPI keys. Admin only
Assistant and agentsGET /api/assistant/status, GET /api/ai/usageWhether a model is connected, and token usage
POST /api/mcp, GET /api/mcp/statusThe 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.

Sensora is open source under the Apache 2.0 license.