# Audit log API

> Read a team's audit log with an admin key: gap-free cursors, filters, exports, the hash chain, webhook streams, limits and errors.

Source: https://www.sume.com/docs/audit-logs

A team's Owner and Admins can read the team's audit log from a script or a
SIEM. It is the log of Settings → Audit log: who did what, to whom, when and
from where. Pull it page by page, export it as a file, or have Sume send it
to your server as it is written.

```text
GET  /v1/admin/audit_logs                         events, newest or oldest first
GET  /v1/admin/audit_logs/{id}                    one event
GET  /v1/admin/audit_logs/event_types             every event type, with its category
GET  /v1/admin/audit_logs/verify                  Sume checks the hash chain
POST /v1/admin/audit_logs/exports                 export to NDJSON, CSV or JSON
GET  /v1/admin/audit_logs/exports                 the team's recent exports
GET  /v1/admin/audit_logs/exports/{id}            one export
GET  /v1/admin/audit_logs/exports/{id}/download   a signed link to the file
```

[Streams](#streams) push new events to your HTTPS endpoint. The live
[OpenAPI](https://api.sume.com/reference/json) gives the exact schemas.
[Pull your audit log into your SIEM](https://www.sume.com/docs/audit-log-siem) sets up a whole
pipeline, step by step.

## Keys

The audit log API takes an [admin key](https://www.sume.com/docs/admin#admin-keys) with audit log
access. A team Owner or Admin makes one in the team on
[Settings → API keys](https://www.sume.com/dashboard/api-keys), with one of
three accesses:

| Access | Scopes | It can |
|---|---|---|
| **Audit log only** | `audit_logs:read`, `account:read` | read the audit log, export it and check its chain. Nothing else. |
| **Admin, read only** | `admin:read`, `audit_logs:read`, `account:read` | the same, and read members, usage, limits and policy |
| **Admin** | `admin:read`, `admin:write`, `audit_logs:read`, `audit_logs:write`, `account:read` | the same, change limits and policy, and run [streams](#streams) |

For a SIEM, make an **Audit log only** key. It is read only. Any admin route
outside `/v1/admin/audit_logs` answers it `403 insufficient_scope`.

- Like every admin key it calls `/v1/admin` only, works for its own team only,
  and cannot generate or spend.
- Every request reads the role of the key's owner again. When they are no
  longer an Owner or Admin of the team, the key answers
  `403 insufficient_role`. When they leave the team, the key is revoked.
- The team's IP allowlist and maximum key lifetime apply.
- An admin key made before audit log access existed has no `audit_logs:read`
  and answers `403 insufficient_scope` with
  `details.required_scope: "audit_logs:read"`. Make a new one.
- A personal workspace has no audit log API: `404 team_only`.

```bash
export SUME_AUDIT_KEY="sume_live_..."
```

## List events

```bash
curl "https://api.sume.com/v1/admin/audit_logs?limit=100" \
  -H "Authorization: Bearer $SUME_AUDIT_KEY"
```

```json
{
  "object": "list",
  "schema_version": "2026-11-27",
  "data": [{ "object": "audit_log.event", "id": "ale_2n9c", "sequence": 4182 }],
  "has_more": true,
  "next_cursor": "eyJ2IjoxLCJ3IjoiM2E5...",
  "first_sequence": 4182,
  "last_sequence": 4083,
  "order": "desc",
  "head_sequence": 4182,
  "retention": {
    "days": 365,
    "oldest_effective_at": "2025-11-27T06:12:03.481Z",
    "oldest_sequence": 1
  }
}
```

- `order=desc`, the default, gives the newest first. `order=asc` gives the
  oldest first and is the way to follow the log.
- `first_sequence` and `last_sequence` are the first and last event of the
  page, `null` when it is empty.
- `head_sequence` is the team's newest sequence when the page was read,
  whatever the filters.
- `retention` is the API's window: every event from `oldest_sequence` on
  (see [Retention](#retention)).

## An event

```json
{
  "object": "audit_log.event",
  "id": "ale_2n9c",
  "schema_version": "2026-11-27",
  "sequence": 4182,
  "type": "security_settings.changed",
  "category": "access",
  "effective_at": "2026-11-27T06:12:03.481920Z",
  "actor": {
    "type": "user",
    "id": "user_2ada",
    "email": "ada@example.com",
    "role": "owner",
    "api_key": { "id": "key_8f1", "prefix": "sume_live_ab12cd34", "kind": "ledger" }
  },
  "context": {
    "client": "api",
    "ip_address": "203.0.113.9",
    "user_agent": "python-requests/2.32.3",
    "request_id": "iad1::7c2b0e"
  },
  "target": { "type": "setting", "id": "security", "name": null },
  "result": { "status": "success", "reason": null },
  "changes": {
    "before": { "ip_allowlist": [] },
    "after": { "ip_allowlist": ["203.0.113.0/24"] }
  },
  "details": {},
  "backfilled": false,
  "integrity": {
    "algorithm": "sha256-chain-v1",
    "hash": "9f2c51…",
    "prev_hash": "41aa07…"
  }
}
```

- `id` is stable (`ale_…`). Use it to de-duplicate.
- `sequence` is the event's place in the team's log: 1, 2, 3… with no gaps,
  in the order events were written ([Pages and cursors](#pages-and-cursors)).
- `type` says what happened. `category` is its group: `auth`, `members`,
  `access`, `credentials`, `ai_governance`, `data`, `billing`, `spend`,
  `workspace`, `compute` or `audit`. [Event types](#event-types) lists them.
  New types are added over time: keep the events of a type you do not know.
- `effective_at` is when it happened, UTC, to the microsecond. A backfilled
  event keeps its original time, so it can be older than events with a lower
  sequence.
- `actor.type` is `user` for a team member, `sume_staff` for Sume support
  acting for the team, `system` for a webhook, a sweep or a worker, and
  `api_key` for a credential with no person behind it (a service account, or
  a refused key). `email` and `role` are as they were when the event was
  written.
- `actor.api_key` names the credential the request used: `id`, `prefix`, and
  `kind` (`ledger` for an API key, `mcp_oauth` for an MCP or CLI sign-in,
  `desktop_session` for the Mac app, `service_account`). It is `null` for an
  action taken in the app.
- `context.client` is `web`, `desktop`, `api`, `mcp`, `cli`, `scim` or
  `system`.
- `changes` holds the fields of a setting before and after the change, or is
  `null`. `details` holds everything else the event records. Neither ever
  holds a secret, a token, key material, a card number or prompt text.
- `backfilled` is `true` for an event rebuilt from earlier records after the
  fact.
- `integrity` is the event's place in the hash chain ([Integrity](#integrity)).

Events never change once written. Fields may be added to this schema; a
change that removes or renames a field comes with a new `schema_version`.

## Filters

Send the same filters with every page.

| Parameter | Takes |
|---|---|
| `effective_at[gte]`, `effective_at[gt]`, `effective_at[lte]`, `effective_at[lt]` | a time: RFC 3339 with an offset (`2026-11-27T06:00:00Z`), a date (`2026-11-27`, read as 00:00 UTC) or Unix seconds. Send `gte` or `gt`, and `lte` or `lt`, not both. |
| `sequence[gte]`, `sequence[lte]` | a sequence, 1 or more |
| `event_types` | exact types such as `api_key.created`, or a prefix such as `billing.*` |
| `exclude_event_types` | types or prefixes to leave out, such as `audit_log.api_read` |
| `categories` | `auth`, `members`, `access`, `credentials`, `ai_governance`, `data`, `billing`, `spend`, `workspace`, `compute`, `audit` |
| `actor_ids` | the acting people's user ids |
| `actor_emails` | their email addresses, in any case |
| `actor_types` | `user`, `sume_staff`, `system`, `api_key` |
| `target_types` | target types such as `api_key`, `member` or `setting` |
| `target_ids` | target ids |
| `clients` | `web`, `desktop`, `api`, `mcp`, `cli`, `scim`, `system` |
| `result` | `success` or `failure` |
| `request_ids` | request ids, as in `context.request_id` |
| `order` | `desc` (default) or `asc` |
| `limit` | events per page, 1 to 1,000. Default 100. |
| `cursor` | `next_cursor` from the previous page |
| `include` | `integrity.preimage` adds the hashed fields to each event |

- A list takes up to 100 values. Repeat the parameter
  (`event_types=member.invited&event_types=billing.*`), use brackets
  (`event_types[]=member.invited&event_types[]=billing.*`) or commas
  (`event_types=member.invited,billing.*`).
- Filters combine with AND. The values of one filter combine with OR, and the
  exact types and prefixes of `event_types` together. An excluded type is
  always left out.
- `result`, `order`, `limit`, `cursor` and each bound are sent once.
- A parameter the API does not know is refused with `400 invalid_request` and
  `details.param` naming it, so a typo never widens a read.
  `event_type=member.invited` answers "event_type is not a parameter of the
  audit log. Did you mean event_types?".
- Times in filters are compared to the microsecond, in UTC:
  `effective_at[gt]` set to an event's own `effective_at` leaves that event
  out. Events are always in sequence order, so to continue where you stopped,
  use the cursor rather than a time.

## Pages and cursors

Each team's events are numbered 1, 2, 3… by `sequence`, in the order they
were written, with no gaps. Sume gives an event its sequence inside the write,
under a lock for the team that is held until the write commits. A higher
sequence therefore never becomes visible before a lower one, and paging by
sequence never skips or repeats an event, even while events are being
written.

- Send `next_cursor` back as `cursor`, with the same filters. The cursor
  keeps its order, so later pages may leave `order` out.
- A cursor is bound to the team, the filters and the order. Another team,
  other filters or the other order answer `400 invalid_cursor` with
  `details.reason` `workspace`, `filter` or `order`; a cursor this API did not
  return answers `malformed`. Do not build or change a cursor.
- `has_more` is `true` while more events match now.
- In `desc` order `next_cursor` is `null` on the last page.
- In `asc` order `next_cursor` is always set, on the last page too. Keep it
  and ask again later to get only the events written since. That is how a
  SIEM follows the log.
- While `has_more` is `true`, the answer also carries
  `Link: </v1/admin/audit_logs?…&cursor=…>; rel="next"`.
- To read a fixed snapshot, send the first page's `head_sequence` as
  `sequence[lte]` with every page.

## Unchanged pages

- The list answers an `ETag`, with `Cache-Control: private, no-cache`. Send it
  back as `If-None-Match`: when the page would be the same, the answer is
  `304 Not Modified` with no body.
- One event answers a strong `ETag` and `Cache-Control: private,
  max-age=3600`, because an event never changes.
- A `304` is still a read, and it is still written to the audit log.

## Your own reads

Every call to the audit log API is itself written to the team's audit log,
with the key's owner as the actor, the key in `actor.api_key` and
`context.client: "api"`:

| Type | Written for | `details` |
|---|---|---|
| `audit_log.api_read` | each read: the list, one event, the event types, a chain check, the export list, one export, and a refused download | `operation` (`list`, `get`, `event_types`, `verify`, `export_list`, `export_get` or `export_download`), the filter, the rows read, the sequences, and `not_modified` for a `304` |
| `audit_log.export_requested` | each export | the export id, format, compression, filter and `snapshot_sequence` |
| `audit_log.export_downloaded` | each download link | the export id, rows, bytes and sha256 |
| `audit_log.stream_*` | each change to a stream | see [Streams](#streams) |

A request the API refuses with `403` (scope, role or IP allowlist) is
written as `access.denied`, once per key and route every 10 minutes.

A poller therefore reads its own earlier reads back, and a page never stays
the same long enough for a `304`. Leave them out with
`exclude_event_types=audit_log.api_read`. That also leaves out the reads of
other keys; read those apart with `event_types=audit_log.api_read`.

## Event types

```bash
curl "https://api.sume.com/v1/admin/audit_logs/event_types" \
  -H "Authorization: Bearer $SUME_AUDIT_KEY"
```

```json
{
  "object": "list",
  "schema_version": "2026-11-27",
  "data": [
    {
      "object": "audit_log.event_type",
      "type": "member.invited",
      "category": "members",
      "description": "An Admin invited someone to the team."
    }
  ]
}
```

## One event

```bash
curl "https://api.sume.com/v1/admin/audit_logs/ale_2n9c?include=integrity.preimage" \
  -H "Authorization: Bearer $SUME_AUDIT_KEY"
```

It answers the event, or `404 audit_log_event_not_found` when the team has no
such event or it is older than the window.

## Integrity

Each team's events form one SHA-256 hash chain, `sha256-chain-v1`. An event's
hash covers its stored fields and the hash of the event before it, so an
event that was changed, removed or put out of order breaks the chain from that
point. The store refuses every change and every deletion of an event.

- `integrity.hash` is the event's SHA-256, in hex.
- `integrity.prev_hash` is the hash of the event before it, `null` for
  sequence 1.
- With `include=integrity.preimage`, `integrity.preimage` holds the 22 hashed
  fields as strings. Join them with U+001F (the unit separator), take the
  SHA-256 of the UTF-8 bytes, and the hex digest is `integrity.hash`.

| # | Field | |
|---|---|---|
| 1 | the previous event's hash | empty for sequence 1 |
| 2 | sequence | |
| 3 | the team's id | `org_…` |
| 4 | time | `effective_at`, as `2026-11-27T06:12:03.481920Z` |
| 5 | type | |
| 6 | category, as stored | empty for an event written before categories |
| 7 | actor kind, as stored | `member`, `sume_staff`, `system` or `credential` |
| 8 | actor user id | |
| 9 | actor email | |
| 10 | actor role | |
| 11 | client | |
| 12 | target type | |
| 13 | target id | |
| 14 | target name | |
| 15 | detail, as stored | JSON text, with `before`, `after` and `credential` still inside |
| 16 | IP address | |
| 17 | user agent | |
| 18 | result | `success` or `failure` |
| 19 | failure reason | |
| 20 | request id | |
| 21 | backfilled | `true` or `false` |
| 22 | source of a backfilled event | |

An empty field is an empty string. Hash the preimage as it is given: it holds
the stored values, which the event shows in a friendlier shape (the actor kind
`member` is `actor.type: "user"`, `before` and `after` move to `changes`, and
`credential` to `actor.api_key`). Then check that the fields you rely on match
it: field 1 is `prev_hash` (empty for `null`), 2 is `sequence`, 4 is
`effective_at` and 5 is `type`.

### Check the chain yourself

Read a range without filters, oldest first, with
`include=integrity.preimage`. A filter leaves gaps on purpose. Then check
that:

1. each event's preimage hashes to its `hash`;
2. each event's `prev_hash` is the `hash` of the event before it;
3. each `sequence` is one more than the one before.

```python
import hashlib

def chain_break(events):
    previous = None
    for event in events:
        integrity = event["integrity"]
        preimage = integrity["preimage"]
        digest = hashlib.sha256("\x1f".join(preimage).encode("utf-8")).hexdigest()
        if digest != integrity["hash"] or preimage[1] != str(event["sequence"]):
            return event["sequence"], "hash"
        if preimage[0] != (integrity["prev_hash"] or ""):
            return event["sequence"], "link"
        if previous is not None:
            if event["sequence"] != previous["sequence"] + 1:
                return previous["sequence"] + 1, "gap"
            if integrity["prev_hash"] != previous["integrity"]["hash"]:
                return event["sequence"], "link"
        previous = event
    return None
```

The first event you hold anchors the chain: its `prev_hash` names an event
you do not have. Keep the last hash and sequence you checked, and go on from
there next time. The [SIEM guide](https://www.sume.com/docs/audit-log-siem#4-verify-the-chain)
has a script that pulls and checks the whole range.

Start a full check at `retention.oldest_sequence`: the window keeps every
sequence from there on, so a pull from it has no gaps. Sume's chain check
below reads the whole chain, older events included.

### Sume checks the chain

```bash
curl "https://api.sume.com/v1/admin/audit_logs/verify?from_sequence=1" \
  -H "Authorization: Bearer $SUME_AUDIT_KEY"
```

```json
{
  "object": "audit_log.chain_check",
  "status": "verified",
  "algorithm": "sha256-chain-v1",
  "from_sequence": 1,
  "to_sequence": 4182,
  "rows": 4182,
  "first_break": null,
  "last_hash": "9f2c51…",
  "head_sequence": 4182,
  "complete": true,
  "next_from_sequence": null
}
```

- Sume recomputes each hash from the stored fields and checks each link and
  sequence, up to 50,000 events per request, from `from_sequence` (default 1)
  to `to_sequence` (default the head).
- When `complete` is `false` and nothing broke, ask again from
  `next_from_sequence`.
- `status: "broken"` names the first bad event in `first_break`:
  `{ "sequence": 1207, "reason": "hash" }`. `reason` is `hash` (the fields do
  not match the hash), `link` (`prev_hash` is not the hash before it) or
  `gap` (a sequence is missing).
- `last_hash` is the hash of the last event that checked out. Compare it with
  the hash you hold for that sequence.
- It reads the whole chain, older than the window too, and it takes the
  smaller rate budget ([Limits](#limits)).

## Exports

An export writes the matching events to one file, for a first backfill or an
archive.

```bash
curl -X POST "https://api.sume.com/v1/admin/audit_logs/exports" \
  -H "Authorization: Bearer $SUME_AUDIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "format": "ndjson", "compression": "gzip", "filter": { "effective_at": { "gte": "2026-01-01" }, "exclude_event_types": ["audit_log.api_read"] } }'
```

| Field | Value |
|---|---|
| `format` | `ndjson` (default): one event per line, the list's event shape. `csv`: one row per event, with `changes` and `details` as JSON cells. `json`: one document with a `data` list. |
| `compression` | `gzip` (default) or `none` |
| `filter` | the list's filters, as JSON (below) |
| `include` | `["integrity.preimage"]` adds each event's preimage, in NDJSON and JSON. A CSV export with it is refused (`400`, `details.param: "include"`). |

The filter takes the list's filters by the same names. Lists are arrays of
strings, `effective_at` takes `gte`, `gt`, `lte` and `lt`, and `sequence`
takes `gte` and `lte`:

```json
{
  "effective_at": { "gte": "2026-01-01", "lt": "2026-07-01" },
  "sequence": { "lte": 50000 },
  "event_types": ["member.*", "security_settings.changed"],
  "exclude_event_types": ["audit_log.api_read"],
  "categories": ["access"],
  "actor_ids": ["user_2ada"],
  "actor_emails": ["ada@example.com"],
  "actor_types": ["user"],
  "target_types": ["api_key"],
  "target_ids": ["key_8f1"],
  "clients": ["web"],
  "result": "success",
  "request_ids": ["iad1::7c2b0e"]
}
```

A field the API does not know, in the body or in `filter`, is refused with
`400 invalid_request`, so a typo never widens an export.

The answer is `201 Created`, with `Location: /v1/admin/audit_logs/exports/{id}`:

```json
{
  "object": "audit_log.export",
  "id": "alx_6f1c2a9e0b3d4c5e6f7a8b9c",
  "status": "queued",
  "format": "ndjson",
  "compression": "gzip",
  "filter": {
    "effective_at": { "gte": "2026-01-01T00:00:00.000Z" },
    "exclude_event_types": ["audit_log.api_read"]
  },
  "include": [],
  "snapshot_sequence": 4182,
  "rows": null,
  "bytes": null,
  "sha256": null,
  "first_sequence": null,
  "last_sequence": null,
  "last_hash": null,
  "created_at": "2026-11-27T06:20:00.000Z",
  "started_at": null,
  "completed_at": null,
  "expires_at": null,
  "error": null,
  "download_url": null
}
```

- An export is a snapshot. It holds the matching events up to
  `snapshot_sequence`, the team's newest sequence when you asked (or your
  `sequence.lte`, when that is lower), oldest first. Events written later are
  not in it. To follow on from an export, list with
  `sequence[gte]` set to `snapshot_sequence + 1`.
- Read `GET /v1/admin/audit_logs/exports/{id}` until `status` is `succeeded`
  or `failed`. It goes `queued`, `running`, then `succeeded` or `failed`, and
  `expired` after 7 days.
- Once it succeeded: `rows`, `bytes`, `sha256` (of the file as you download
  it, so of the gzip bytes when compressed), `first_sequence`,
  `last_sequence`, `last_hash` (the hash of the last event in the file) and
  `download_url`.
- `GET /v1/admin/audit_logs/exports/{id}/download` answers `302` to a signed
  link valid for 15 minutes. With `redirect=false` it answers the link as
  JSON: `{ "object": "audit_log.export_download", "url", "expires_at",
  "sha256", "bytes" }`. The link is signed already: do not send your key to
  it.
- Before it succeeded, or after it expired, the download answers
  `409 audit_log_export_not_ready` with `details.status`.
- A team has at most 3 exports queued or running. A fourth answers
  `409 audit_log_export_in_progress`.
- An export holds at most 2,000,000 events. A larger one fails with
  `error.code: "export_too_large"`: narrow the filter or split the range.
- A run that fails is tried again, up to 3 times. Then the export is `failed`
  with `error.code: "export_failed"`.
- An export keeps to the window ([Retention](#retention)).
- Read-only and Audit log only keys can export.
- `GET /v1/admin/audit_logs/exports?limit=20` lists the team's exports,
  newest first, 1 to 100.

CSV columns: `id`, `sequence`, `effective_at`, `type`, `category`,
`actor_type`, `actor_id`, `actor_email`, `actor_role`, `actor_api_key_id`,
`actor_api_key_prefix`, `client`, `ip_address`, `user_agent`, `request_id`,
`target_type`, `target_id`, `target_name`, `result`, `result_reason`,
`changes_before`, `changes_after`, `details`, `backfilled`, `hash`,
`prev_hash`. A cell that starts with `=`, `+`, `-`, `@`, a tab or a carriage
return gets a leading `'`, so a spreadsheet does not run it as a formula.

The JSON document is
`{ "object": "list", "schema_version", "export_id", "workspace_id",
"snapshot_sequence", "filter", "data": [ … ] }`.

## Streams

A stream sends new events to your HTTPS endpoint as they are written, in
order, in signed batches.

```text
POST   /v1/admin/audit_logs/streams                   make a stream
GET    /v1/admin/audit_logs/streams                   the team's streams
GET    /v1/admin/audit_logs/streams/{id}              one stream
PATCH  /v1/admin/audit_logs/streams/{id}              change its URL, filter, batch size or status
DELETE /v1/admin/audit_logs/streams/{id}              delete it
POST   /v1/admin/audit_logs/streams/{id}/replay       deliver again from a sequence
POST   /v1/admin/audit_logs/streams/{id}/test         send one signed test delivery now
GET    /v1/admin/audit_logs/streams/{id}/deliveries   the delivery log
```

```bash
curl -X POST "https://api.sume.com/v1/admin/audit_logs/streams" \
  -H "Authorization: Bearer $SUME_ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://siem-bridge.example.com/sume/audit", "filter": { "exclude_event_types": ["audit_log.api_read"] }, "batch_size": 500, "start": "now" }'
```

- Making, changing, replaying, testing and deleting a stream take an
  **Admin** key (`audit_logs:write`). Read-only and Audit log only keys can
  read streams and their deliveries.
- `url` is a public HTTPS URL; anything else answers
  `400 invalid_webhook_url`. `filter` and `include` are those of an export.
  `batch_size` is 1 to 1,000, default 100. `start` is `"now"` (from the next
  event, and the default), `"beginning"` (from the oldest in the window) or
  `{ "after_sequence": 4000 }`.
- A team has at most 5 streams: `409 audit_log_stream_limit`.
- The stream answers `{ "object": "audit_log.stream", "id", "url",
  "url_fingerprint", "description", "status", "filter", "include", "batch_size",
  "cursor_sequence", "lag", "consecutive_failures", "next_attempt_at",
  "last_success_at", "last_failure_at", "last_status_code", "last_error",
  "created_at", "updated_at" }`. `status` is `active`, `paused` or `failing`.
  `cursor_sequence` is the last sequence delivered, and `lag` is how far the
  head is ahead of it.
- Sume never shows the full URL again after you set it, because collectors
  often carry a token in the path or query. `url` is its origin
  (`https://siem-bridge.example.com/…`), and `url_fingerprint` is the first
  16 hex characters of the SHA-256 of the full URL:
  `printf %s "$URL" | sha256sum | cut -c1-16` tells you which URL is set. The
  audit log records the host only.

Each delivery is a POST of:

```json
{
  "object": "audit_log.delivery",
  "id": "ald_…",
  "stream_id": "als_…",
  "schema_version": "2026-11-27",
  "test": false,
  "data": [{ "object": "audit_log.event", "id": "ale_2n9c", "sequence": 4182 }],
  "first_sequence": 4180,
  "last_sequence": 4182,
  "next_cursor": "eyJ2IjoxLCJ3IjoiM2E5..."
}
```

- It is signed as [webhooks](https://www.sume.com/docs/webhooks) are: HMAC SHA-256 with the
  team's webhook signing secret over `<timestamp>.<raw_body>`, sent as
  `x-sume-webhook-timestamp` and `x-sume-webhook-signature: sume-v1=<hex>`
  (two entries, newest first, during a secret rotation). It also carries
  `x-sume-webhook-id` (the delivery id) and `user-agent: Sume-Audit-Log/1`.
- Read the signing secret on the dashboard's **Webhooks** tab, or from
  `GET /v1/webhooks/signing-secret` with a regular API key that has
  `account:read`. An admin key cannot read it.
- Store the batch, then answer `2xx` within 10 seconds.
- Delivery is at least once and in order. A batch is sent again until it gets
  a `2xx`, and the stream never moves past it. Use each event's `id` to
  de-duplicate.
- A failed attempt is tried again after 10 seconds, then twice as long each
  time, up to 1 hour. A `Retry-After` on a `429` or `503` is followed, up to
  1 hour.
- After 24 hours of failures in a row the stream turns `failing` and stops,
  and an `audit_log.stream_failing` event is written. Fix the endpoint, then
  set `"status": "active"` with `PATCH`.
- `replay` with `{ "from_sequence": 4000 }` delivers again from that
  sequence.
- `test` sends `{ "object": "audit_log.delivery", "test": true, "data": [] }`
  and answers your endpoint's status code and the time it took. It works on a
  paused or failing stream and does not move it.
- The delivery log keeps 30 days: each attempt, its sequences, status code,
  duration and error.
- Each change is written to the audit log as `audit_log.stream_created`,
  `audit_log.stream_updated`, `audit_log.stream_deleted`,
  `audit_log.stream_replayed` or `audit_log.stream_tested`.

## Not yet

Sume does not push to Splunk, Datadog, Elastic or an S3 bucket by itself.
Today you pull the log, export it, or receive a stream on your own endpoint
and forward it from there. The [SIEM guide](https://www.sume.com/docs/audit-log-siem) shows each.

## Retention

The API returns the last 365 days of events, or 730 days for an enterprise
team. The window starts at the oldest event written in that time and keeps
every sequence after it, so a pull from `retention.oldest_sequence` has no
gaps. An event backfilled with an older `effective_at` keeps its place by
sequence. Sume keeps the events longer: older ones stay in the app's audit
log and its downloads, and in the chain that `verify` checks. The list, one
event, exports and streams keep to the window.

## CLI and TypeScript

```bash
sume audit-logs list --order asc --all --json > sume-audit.ndjson
sume audit-logs export --format ndjson --output sume-audit.ndjson.gz
sume audit-logs verify
sume audit-logs streams create --url https://siem-bridge.example.com/sume/audit --exclude-type audit_log.api_read
```

The [CLI reference](https://www.sume.com/docs/cli/commands) lists every `sume audit-logs`
command. In TypeScript, `@sume-com/sdk` has `iterateAuditLogEvents`,
`verifyAuditLogEvent` and `verifyAuditLogChain`.

## Limits

- The audit log API has two rate budgets of its own, apart from your other
  reads and writes. Reads take half of your plan's write number per minute:
  60 on Free, 150 on Pro, 300 on Startup, 600 on Scale. The chain check and
  every change (exports, streams) take a twentieth: 6, 15, 30 and 60.
- A budget counts per key, and all of one person's keys in the team share it
  too.
- Every answer carries `ratelimit-limit`, `ratelimit-remaining` and
  `ratelimit-reset` (seconds). Past the budget the answer is
  `429 rate_limited`, with `retry-after` in seconds and `details.scope:
  "report"`.
- A page holds up to 1,000 events and a filter up to 100 values. A chain check
  covers up to 50,000 events and an export up to 2,000,000. A team has at
  most 3 exports running and 5 streams.

## Errors

| Status | Code | When |
|---|---|---|
| 400 | `invalid_request` | A parameter, a body field or a filter is wrong or unknown. `details.param` names it, or `details.errors[].path` for a value the schema refuses. |
| 400 | `invalid_cursor` | `details.reason`: `malformed` (not a cursor this API returned), `workspace` (another team's), `filter` (made with other filters) or `order` (the other order). |
| 400 | `invalid_webhook_url` | A stream URL is not a public HTTPS URL. |
| 403 | `insufficient_scope` | Not an admin key with audit log access (`details.required_scope: "audit_logs:read"`), a stream change without `audit_logs:write`, or an admin key outside `/v1/admin` (`details.reason: "admin_key"`). |
| 403 | `insufficient_role` | The key's owner is no longer an Owner or Admin of the team. |
| 403 | `ip_not_allowed` | The request came from outside the team's IP allowlist. |
| 404 | `team_only` | The key belongs to a personal workspace. |
| 404 | `audit_log_event_not_found` | The team has no such event, or it is older than the window. |
| 404 | `audit_log_export_not_found` | The team has no such export. |
| 404 | `audit_log_stream_not_found` | The team has no such stream. |
| 409 | `audit_log_export_in_progress` | The team already has 3 exports queued or running. |
| 409 | `audit_log_export_not_ready` | The export has not succeeded, or it expired; `details.status` says which. |
| 409 | `audit_log_stream_limit` | The team already has 5 streams. |
| 429 | `rate_limited` | Past a budget. Wait `retry-after` seconds. |
| 503 | `provider_not_configured` | A stream test cannot sign right now. Retry. |
| 503 | `audit_log_api_unavailable` | The audit log or the export storage cannot be reached right now. Retry. |
