Authentication
Apps and people use API keys. Sensors sign each request with their own secret. Ochio signs everything it sends you.
Three kinds of credentials
| Who | Credential | How it's sent |
|---|---|---|
| Apps, connected systems, people, the Claude MCP server | API key ochio_… | Authorization: Bearer <key> |
| Sensors | Sensor secret ssk_…, one per sensor | Ochio-Timestamp and Ochio-Signature headers |
| Your webhook receiver | Webhook secret whsec_…, one per subscription | Ochio signs each delivery; you check it |
Ochio shows each key and secret once, when it's created. Keep them in your own secret store.
API keys
Send the key in the Authorization header of every request. A key carries scopes, and each endpoint names the scope it needs. A request whose key lacks it gets 403 missing_scope.
Scopes don't include each other, so give a key every scope it needs: even admin doesn't include read. Ochio creates two keys the first time it starts: operator, with every scope, and partner, for connected systems. An admin makes more with Create an API key.
| Scope | Lets the key | operator | partner |
|---|---|---|---|
read | Read everything but the API keys: every other GET, the live stream and the export | yes | yes |
alerts:write | Send alerts and check-ins for registered sensors | yes | yes |
sensors:write | Register, remove and re-key sensors | yes | no |
missions:request | Request missions; without missions:launch they wait for approval | yes | yes |
missions:launch | Launch missions without waiting for approval | yes | no |
missions:approve | Approve, deny and cancel missions; dismiss alerts | yes | no |
webhooks:write | Manage webhook subscriptions | yes | yes |
admin | Manage API keys, see every key's webhooks, and use the sandbox controls | yes | no |
Calling the API with a key
Any endpoint works the same way. Here, the site's status.
curl "$OCHIO_URL/v1/status" \
-H "Authorization: Bearer $OCHIO_API_KEY"import os
import requests
r = requests.get(
f"{os.environ['OCHIO_URL']}/v1/status",
headers={"Authorization": f"Bearer {os.environ['OCHIO_API_KEY']}"},
)
print(r.status_code, r.json())const res = await fetch(`${process.env.OCHIO_URL}/v1/status`, {
headers: { Authorization: `Bearer ${process.env.OCHIO_API_KEY}` },
});
console.log(res.status, await res.json());{
"site": {
"name": "Demo Depot",
"center": {
"lat": 38.5005,
"lon": -98.0005
},
"operating_area_id": "depot"
},
"time": "2026-10-19T21:33:02.753Z",
"version": "1.0.0",
"counts": {
"alerts_open": 0,
"alerts_responding": 0,
"missions_active": 0,
"missions_pending_approval": 0,
"sensors_online": 3,
"sensors_silent": 0,
"sensors_pending": 0,
"vehicles_ready": 2,
"vehicles_flying": 0
}
}{
"error": {
"code": "invalid_key",
"message": "That API key is not valid."
}
}{
"error": {
"code": "missing_scope",
"message": "This key does not have the admin scope.",
"details": {
"required_scope": "admin"
}
}
}Signing sensor requests
Sensors don't use API keys. Each sensor gets its own secret when it's registered, and signs every request it sends with it:
- Take the current Unix time in whole seconds as the
timestamp. - Compute HMAC-SHA256 over the timestamp, a dot, and the raw body bytes, keyed with the secret.
- Send
Ochio-Timestamp: <timestamp>andOchio-Signature: v1=<hex digest>.
Ochio checks the signature over the exact bytes it receives, so sign the body you send, not a copy you format again. It refuses a timestamp more than 300 seconds away from its clock, so keep the sensor's clock set.
A repeat of a request Ochio has already received, with the same timestamp and body, is answered but changes nothing: a check-in answers "repeat": true, an alert answers duplicate. A captured check-in can't keep a dead sensor alive, so sign each new request with a fresh timestamp.
Two endpoints take sensor signatures: Check in and Send an alert. Both also take an API key with alerts:write, for systems that speak for many sensors.
BODY='{"id":"pir02-000412","source":"east-gate-pir-02","type":"motion","priority":"high"}'
TS=$(date +%s)
SIG=$(printf '%s.%s' "$TS" "$BODY" | openssl dgst -sha256 -hmac "$SENSOR_SECRET" | awk '{print $NF}')
curl -X POST "$OCHIO_URL/v1/alerts" \
-H "Content-Type: application/json" \
-H "Ochio-Timestamp: $TS" \
-H "Ochio-Signature: v1=$SIG" \
-d "$BODY"import hashlib, hmac, json, os, time
import requests
secret = os.environ["SENSOR_SECRET"]
body = json.dumps({"id": "pir02-000412", "source": "east-gate-pir-02",
"type": "motion", "priority": "high"}).encode()
ts = str(int(time.time()))
sig = hmac.new(secret.encode(), f"{ts}.".encode() + body, hashlib.sha256).hexdigest()
r = requests.post(f"{os.environ['OCHIO_URL']}/v1/alerts", data=body, headers={
"Content-Type": "application/json",
"Ochio-Timestamp": ts,
"Ochio-Signature": f"v1={sig}",
})
print(r.status_code, r.json())import crypto from "node:crypto";
const body = JSON.stringify({ id: "pir02-000412", source: "east-gate-pir-02", type: "motion", priority: "high" });
const ts = Math.floor(Date.now() / 1000).toString();
const sig = crypto.createHmac("sha256", process.env.SENSOR_SECRET).update(`${ts}.${body}`).digest("hex");
const res = await fetch(`${process.env.OCHIO_URL}/v1/alerts`, {
method: "POST",
headers: { "Content-Type": "application/json", "Ochio-Timestamp": ts, "Ochio-Signature": `v1=${sig}` },
body,
});
console.log(res.status, await res.json());{
"error": {
"code": "invalid_signature",
"message": "The signature does not match the body. Nothing was recorded."
}
}{
"error": {
"code": "timestamp_out_of_range",
"message": "Ochio-Timestamp is 600 s away from the core's clock; the limit is 300 s."
}
}{
"error": {
"code": "missing_signature",
"message": "Send both Ochio-Timestamp and Ochio-Signature headers."
}
}Checking Ochio's signature
Ochio signs every webhook delivery the same way, with the subscription's whsec_ secret. Before you trust a delivery:
- Read the raw body, before any JSON parsing.
- Compute HMAC-SHA256 over
Ochio-Timestamp, a dot, and the raw body, keyed with your secret. - Compare it with the hex after
v1=inOchio-Signature, in constant time. - Refuse it if the timestamp is more than 300 seconds from your clock.
Then answer with any 2xx status within 5 seconds, and do the slow work afterwards. How deliveries work covers retries and ordering.
import hashlib, hmac, time
def verify(secret: str, body: bytes, timestamp: str, signature: str) -> bool:
"""True when the delivery came from Ochio and is less than 5 minutes old."""
if abs(time.time() - int(timestamp)) > 300:
return False
expected = hmac.new(secret.encode(), f"{timestamp}.".encode() + body, hashlib.sha256).hexdigest()
given = [p.strip()[3:] for p in signature.split(",") if p.strip().startswith("v1=")]
return any(hmac.compare_digest(expected, g) for g in given)
# in your handler:
# ok = verify(WEBHOOK_SECRET, request.get_data(),
# request.headers["Ochio-Timestamp"], request.headers["Ochio-Signature"])import crypto from "node:crypto";
// True when the delivery came from Ochio and is less than 5 minutes old.
export function verify(secret, rawBody, timestamp, signature) {
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.`).update(rawBody).digest("hex");
return signature.split(",").map((p) => p.trim()).filter((p) => p.startsWith("v1="))
.some((p) => p.length === 67 && crypto.timingSafeEqual(Buffer.from(p.slice(3)), Buffer.from(expected)));
}
// with Express: app.post("/ochio", express.raw({ type: "application/json" }), (req, res) => {
// if (!verify(SECRET, req.body, req.get("Ochio-Timestamp"), req.get("Ochio-Signature"))) return res.sendStatus(401);
// res.sendStatus(204); // then handle JSON.parse(req.body)
// });The sandbox's test mode
The sandbox starts in test mode, so you can try requests without a key. In test mode, a request made on the same computer, from a terminal, a script or the sandbox's own pages, acts as the operator key.
Web pages from other sites, requests from other machines, and anything sent to another host name still need a key. Turn test mode off whenever other machines can reach Ochio: start it with --no-dev, or set OCHIO_DEV_MODE=0.
Send a key anyway while you build. Your code then works unchanged against a real Ochio server, where test mode is off.
When authentication fails
| Status | Code | What happened |
|---|---|---|
| 401 | unauthorized | No key was sent, or the Authorization header isn't Bearer <key>. |
| 401 | invalid_key | The key isn't one Ochio knows. It may have been revoked. |
| 401 | missing_signature | Only one of Ochio-Timestamp and Ochio-Signature was sent. |
| 401 | invalid_signature | The signature doesn't match the body, or isn't in the v1=<hex> form. Nothing was recorded. |
| 401 | timestamp_out_of_range | The timestamp is more than 300 seconds away from Ochio's clock. |
| 403 | missing_scope | The key is valid but lacks the scope this endpoint needs. On most endpoints details.required_scope names it. |
| 404 | unknown_sensor | A signed request, or any alert, names a sensor that isn't registered. |