Skip to the documentation
All documentation pages ↓

Authentication

API keys, the X-API-Key header, optional request signing and key hygiene.

API keys

Every request carries one header:

Header
X-API-Key: ngk_<prefix>_<secret>
  • A key is bound to one organisation. The tenant comes from the key on the server. No request field names a tenant, so a caller cannot reach anybody else's data however the request is shaped.
  • The secret is shown once, at creation and at rotation. Only a SHA-256 hash is stored.
  • Scopes are explicit and read-only: incidents:read, alerts:read, security_score:read, security_events:read. You can only grant a scope you hold yourself in the console.
  • Sending events is a separate capability, chosen when the key is created and off unless stated. Keys that existed before the capability was introduced kept it.
  • Expiry and revocation apply on the next request. Expiry is checked on every use, not by a nightly sweep.

An unknown, revoked or expired key, a missing header and a suspended organisation all answer the same 401. A valid key without the scope a route needs answers 403 and names the missing scope.

Request signing (optional)

A key proves the caller holds a credential. A signature also proves that this request was not altered in transit and is not a replay of an earlier one. Signing applies to the two sending endpoints.

It is opt-in per key. Each key is issued with a signing secret alongside it; the secret is only needed once the key enforces signing. From then on an unsigned delivery is refused — a key that has adopted signing never silently falls back.

What is signed

  1. X-Timestamp: the current time in Unix seconds. It must be within 300 seconds of the server's clock.
  2. X-Nonce: a random string of 8 to 128 characters. Each nonce is accepted once per key.
  3. The message is v1, the timestamp, the nonce and the lowercase hex SHA-256 of the exact request body, joined with newlines (\n).
  4. X-Signature is v1= followed by the lowercase hex HMAC-SHA256 of that message, keyed with the signing secret.
Python
import hashlib, hmac, json, secrets, time

def signed_headers(secret: str, body: bytes) -> dict[str, str]:
    timestamp = str(int(time.time()))          # Unix seconds, within 300 s of ours
    nonce = secrets.token_urlsafe(12)          # 8-128 characters, never reused
    digest = hashlib.sha256(body).hexdigest()  # hash of the exact bytes you send
    message = f"v1\n{timestamp}\n{nonce}\n{digest}".encode()
    mac = hmac.new(secret.encode(), message, hashlib.sha256).hexdigest()
    return {
        "X-Timestamp": timestamp,
        "X-Nonce": nonce,
        "X-Signature": f"v1={mac}",
    }

body = json.dumps(event, separators=(",", ":")).encode()
headers = {"X-API-Key": api_key, "Content-Type": "application/json",
           **signed_headers(signing_secret, body)}
Node.js
import { createHash, createHmac, randomBytes } from "node:crypto";

function signedHeaders(secret, body) {
  const timestamp = String(Math.floor(Date.now() / 1000));
  const nonce = randomBytes(12).toString("base64url");
  const digest = createHash("sha256").update(body).digest("hex");
  const mac = createHmac("sha256", secret)
    .update(`v1\n${timestamp}\n${nonce}\n${digest}`)
    .digest("hex");
  return { "X-Timestamp": timestamp, "X-Nonce": nonce, "X-Signature": `v1=${mac}` };
}

const body = JSON.stringify(event);   // sign exactly the bytes you send
await fetch(url, {
  method: "POST",
  headers: { "X-API-Key": apiKey, "Content-Type": "application/json",
             ...signedHeaders(signingSecret, body) },
  body,
});

A refused signature answers 401 with WWW-Authenticate: X-Signature, and the detail says which check failed: the three headers are missing, the version is unsupported, the nonce or timestamp is malformed, the timestamp is outside the accepted window, the signature does not match, or the request has already been delivered. If replay protection itself is unavailable, a signed request is refused rather than accepted unprotected.

Turning signing on

In the console, Settings → Developers, create a key with Require signed requests ticked. The signing secret is shown once, beside the key, in the same panel; copy both before leaving the page. Neither can be shown again — the key is stored only as a hash and the secret only encrypted — so a lost one is replaced by rotating the key.

Every key has a signing secret, and it is shown when the key is created even if the key does not require signatures; signing is then optional. Requiring signatures is decided when a key is issued and cannot be switched on in place, because an integration already sending unsigned events would start being refused mid-stream.

To move an existing integration to signing, rotate its key with Require signed requests on the new key ticked and an overlap long enough to deploy: the new key and its secret are shown once, the old key keeps working until the overlap ends, and the integration switches over when it is ready. A rotation can keep or add the requirement but never drop it: a key that requires signatures is always replaced by one that does too.

Clock skew is the most common cause of a refused signed delivery. Keep the sending host on NTP; the SDK's doctor reports the difference.

Key hygiene

  • Keep keys in a backend service's secret store. Never in a browser, a mobile app, a repository or a log line.
  • One key per system, named for it, with only the scopes it needs. A sender does not need read scopes; a reporting job does not need to send.
  • Give keys an expiry. The console offers 30 days, 90 days (the default), a year, or never.
  • Rotate on the Developers & API page: the successor carries the same scopes and capabilities, and you choose how long the old key keeps working — immediately for a leak, or 1 hour, 24 hours or 7 days for a deployment window. Rotation can narrow what a key may do, never widen it.
  • Revoke stops a key on the next request and cannot be undone. Rotate with an overlap if the integration is live.
  • Creating, rotating and revoking a key, and a key reaching for a scope it does not have, are written to your organisation's audit log.

We use only the cookies needed to sign you in securely and to remember your language and display choices. No analytics, advertising or third-party cookies.

Cookie policy