# HTTP API

> Every public /v1 route with its parameters, request and response shapes, errors, rate limit and allowance behaviour.

Base URL: `https://api.cookiecrowbar.com`. Requests and responses are JSON. The [MCP tools](https://cookiecrowbar.com/docs/mcp-tools)
call these routes, so anything your assistant does you can also call directly.

Examples use invented values: `acme.example`, the placeholder key `cs_live_YOUR_KEY` and made-up ids. Responses
can carry more fields than this page shows; the ones listed are the ones to build on.

## Authentication

Send your key in the `X-API-Key` header on every route except `GET /v1/health`:

```bash
curl -s https://api.cookiecrowbar.com/v1/credits -H "X-API-Key: cs_live_YOUR_KEY"
```

`/v1` routes read only `X-API-Key`. `Authorization: Bearer` is for the [MCP endpoint](https://cookiecrowbar.com/docs/quickstart).

| Status | Body `error` | When |
|---|---|---|
| `401` | `Missing X-API-Key header` | No `X-API-Key` header |
| `401` | `Invalid API key` | Unknown or revoked key |

## Errors

Application errors share one envelope: a message in `error`, a stable `code` to branch on, and sometimes extra
fields. Two responses don't use it: `GET /v1/health` when unhealthy (below), and a path that matches no route, which
gets the framework's default `404` body (`message`, `error`, `statusCode`).

```json
{ "error": "No shared observations for this domain", "code": "NOT_FOUND" }
```

| `code` | Status | When |
|---|---|---|
| `INVALID_REQUEST` | `400` | A body or query fails validation. An enum miss lists the allowed values |
| `INVALID_REQUEST` | `413` | The request body is over the route's size limit (`POST /v1/feedback`: 32 KiB) |
| `INVALID_REQUEST` | `415` | Unsupported `Content-Type`. Send JSON bodies as `application/json` |
| `INVALID_REQUEST` | `503` | Collection is paused. Nothing was queued; shared observations stay readable |
| `INVALID_DOMAIN` | `400` | A domain can't be parsed. Batch routes return the bad inputs in `invalid` |
| `INVALID_CONFIG` | `400` | A config fails validation. `errors` usually holds `path: message` lines |
| `UNAUTHORIZED` | `401` | See [Authentication](#authentication) |
| `NOT_FOUND` | `404` | Unknown or not yours: scan, batch, config, revision, or no shared observations |
| `SUBMISSION_CONFLICT` | `409` | A feedback `submission_id` reused with different content |
| `RATE_LIMIT_EXCEEDED` | `429` | Over this key's per-minute request budget |
| `TOO_MANY_QUEUED` | `429` | This key has too many unfinished domains of this kind |
| `TOO_MANY_QUEUED` | `503` | The shared queue is full |
| `MONTHLY_LIMIT` | `429` | The request would pass this key's monthly domain allowance |
| `INTERNAL` | `500` | Our fault. No detail is returned |

Scans, batches and configs belong to the key that made them: another key's id reads as `404`.

## Rate limit, queue and allowance

**Requests.** Each key has a per-minute request budget, set when the key is issued. Over it you get `429` with a
`Retry-After` header (seconds) and `retry_after_ms` in the body:

```json
{ "error": "Rate limit exceeded", "code": "RATE_LIMIT_EXCEEDED", "retry_after_ms": 1400 }
```

**Queue.** A key can hold a limited number of unfinished domains per kind (explore and scan count separately).
Over it, `429 TOO_MANY_QUEUED` carries `pending`, `limit` and `batch_ids` (newest first): poll those batches
instead of resubmitting. When the shared queue is full you get `503 TOO_MANY_QUEUED` with a `Retry-After` header.
Explore and scan responses show the room left in `queue.free`.

**Monthly allowance.** Explore and scan count each requested domain against the key's allowance for the UTC
calendar month, including domains answered from cached observations. Failed domains don't count. Shared reads
(`GET /v1/domains/:domain` and its evidence route) don't count. Responses carry `usage.month`:

```json
{ "domains": 42, "limit": 500, "remaining": 458 }
```

`limit` and `remaining` are `null` when the key has no monthly cap. A request that would pass the allowance is
rejected in full: `429 MONTHLY_LIMIT` with `limit` and `remaining`, and nothing is queued.

## GET /v1/health

No key. Returns `{ "status": "ok" }` or `{ "status": "degraded" }` with `200`, or `{ "status": "unhealthy" }`
with `503`. The body is only `status`, with no `error` or `code`.

## GET /v1/credits

This key's usage and the allowance rules.

```json
{
  "charged": false,
  "usage": { "explore_domains": 12, "scan_domains": 30, "module_units": 210 },
  "allowance_policy": {
    "unit": "requested_domains",
    "cache_requests_count_toward_allowance": true,
    "shared_lookup_counts_toward_allowance": false,
    "failed_requests_count_toward_allowance": false
  },
  "month": { "domains": 42, "limit": null, "remaining": null }
}
```

`module_units` counts collection work, not a charge. Nothing is charged during the private beta.

## GET /v1/catalog

The vendors detected out of the box and the category vocabulary.

| Query | |
|---|---|
| `category` | Only vendors in this category |
| `q` | Only vendors whose name contains this text |

```json
{ "categories": ["crm", "marketing-automation", "..."], "vendors": [{ "name": "HubSpot", "category": "crm" }] }
```

## GET /v1/domains/:domain

What is already known about one domain, from shared observations (the `lookup` tool). Never collects. Doesn't
count against the allowance.

| Query | |
|---|---|
| `max_age_days` | Positive integer, default `14`. Observations older than this are returned in `prior_observations` and `prior_findings`, not as current |

```json
{
  "domain": "acme.example",
  "report": {
    "technologies": [
      { "name": "HubSpot", "category": "crm", "confidence": "confirmed", "verification": "used",
        "activity": "active", "sources": ["script", "dns"] }
    ],
    "coverage": [{ "module": "page.home", "target": "acme.example", "status": "completed" }],
    "partial": false
  },
  "shared": {
    "observations": [
      { "observation_id": "3f1c9a2e-0000-4000-8000-000000000001", "collector": "page.home",
        "observed_at": "2026-11-06T20:57:44.629Z", "stale": false }
    ],
    "prior_observations": [],
    "prior_findings": [],
    "missing": []
  }
}
```

- `confidence`, `verification` and `activity` are explained in [Scoring](https://cookiecrowbar.com/docs/scoring). `sources` lists the
  kinds of evidence behind a row.
- `coverage` has one entry per check with its `status` (`completed`, `failed`, `blocked`, `incomplete`,
  `limited`, `skipped`). Completed means the check ran, including when it found nothing.
- A check with no current observation is listed in `shared.missing` and shows as `incomplete` in `coverage`.
- `prior_findings` are dated older readings, not current positives.
- `404 NOT_FOUND` (`No shared observations for this domain`): nothing has been collected yet under the current
  collection version, which is also the case after a release changes it, until the domain is collected again. Collect it
  with [`POST /v1/explore`](#post-v1explore).

A missing technology means "not observed in the checks performed", qualified by coverage. It is never proof of
absence.

## GET /v1/domains/:domain/changes

Alpha: the shape can change. Technologies first observed between two stored observations of one domain (the
`changes` tool). It reads stored observations and never collects. Doesn't count against the allowance.

| Query | |
|---|---|
| `max_age_days` | Integer, 1 to 365, default `180`. The read window |

Two observations are compared only when they come from the same check, target, parameters and collector version.
A pair that can't be compared reports `unknown`. Removals are not reported.

```json
{
  "domain": "acme.example",
  "window": { "max_age_days": 180, "from": "2026-05-26T00:00:00.000Z", "to": "2026-11-22T00:00:00.000Z" },
  "history": { "observations": 6, "snapshots": 3, "pairs": 2 },
  "changes": [
    { "vendor": "HubSpot", "category": "crm", "change": "added",
      "observed_between": { "from": "2026-10-01T08:00:00.000Z", "to": "2026-11-06T20:57:44.629Z" },
      "summary": "HubSpot: first observed between 2026-10-01T08:00:00.000Z and 2026-11-06T20:57:44.629Z",
      "before": [{ "observation_id": "3f1c9a2e-0000-4000-8000-000000000001", "module": "page.home",
                   "observed_at": "2026-10-01T08:00:00.000Z", "started_at": "2026-10-01T07:59:50.000Z" }],
      "after": ["..."], "proof": ["..."] }
  ],
  "gaps": [], "refused": [], "truncated": { "observations": 0, "evidence_blobs": 0, "events": 0, "bytes": false },
  "note": "..."
}
```

- `change: "added"` means the vendor was first observed between `observed_between.from` and `.to`, the collection
  end times of the two observations. It is not the date the site adopted it.
- `change: "unknown"` means the evidence can't establish a change; `reason` is one of `collection-changed`,
  `params-changed`, `coverage-incomplete`, `target-changed`, `unsafe-target`, `no-attributable-coverage`,
  `collect-time-only`, `dns-incomplete`, `metadata-missing` or `page-unconfirmed` (an addition the evidence can't
  confirm).
- An empty `changes` list doesn't mean nothing changed. `history` counts what was compared; `gaps` lists
  observations whose evidence couldn't be read; `refused` lists pairs that couldn't be compared; `truncated`
  says what the read limits cut.
- A catalog update is never reported as a change on the site.
- `400 INVALID_DOMAIN` when the domain can't be parsed.

## GET /v1/domains/:domain/evidence

Drill into the shared observations behind a domain's findings, without scanning again.

| Query | |
|---|---|
| `kind` | One evidence kind (below). Without it you get the digest: which kinds exist per page, and page coverage |
| `target` | One page, e.g. `acme.example` |
| `filter` | Case-insensitive substring, 2 to 200 characters |
| `limit` | Items per page, default `100`, max `1000` |
| `max_age_days` | Positive integer, default `14`. Older observations are still returned, marked `stale: true` in `shared.observations`; they aren't moved to prior results |
| `observation_id` | A UUID: pin one observation of this domain |

Kinds: `requests`, `scripts`, `cookies`, `localStorageKeys`, `sessionStorageKeys`, `windowKeys`, `metas`,
`iframeSrcs`, `anchors`, `prefetchLinks`, `jsonLd`, `dataLayer`, `forms`, `webSockets`, `sse`, `serviceWorkers`,
`failedResponses`, `responseHeaders`, `html`, `domHtml`, `consent`, `seededCookies`, `trust`, `bundledSdks`, `dns`.

With `kind`, the response shape depends on the kind:

| Kind | Shape |
|---|---|
| List kinds (`requests`, `scripts`, `cookies` and the other array kinds, `trust`) | `targets[]`, each with `target`, `total` (items collected), `matched` (items after `filter`) and up to `limit` `items` |
| Text kinds (`html`, `domHtml`) | `targets[]`, each with `target` and `length`, plus `head` (the start of the text), or `snippets` around each hit when you pass `filter` |
| A kind with a single value on that page | `targets[]`, each with `target` and `value` (`null` when the page has none) |
| `dns` | One `dns` object for the domain, not per page, or `null` when there is no DNS evidence; its lists cut by `filter` and `limit`; `scoped` is added when related domains matched |

For list kinds, when `matched` is more than you received, raise `limit` or narrow `filter` before concluding
anything. This page doesn't document the items themselves.

```json
{
  "domain": "acme.example",
  "kind": "scripts",
  "shared": { "observations": [{ "observation_id": "3f1c9a2e-0000-4000-8000-000000000001", "collector": "page.home" }] },
  "targets": [{ "target": "acme.example", "total": 14, "matched": 2, "items": ["..."] }]
}
```

`404 NOT_FOUND` when no observation matches the domain, or the pinned `observation_id` doesn't belong to it.

## POST /v1/explore

Collect 1 to 3 domains with every check, for designing a config. Counts against the allowance.

| Body | |
|---|---|
| `domains` | 1 to 3 domains. Required |
| `pages` | Extra paths to visit, up to 10 |
| `modules` | Run only these checks instead of all: 1 to 20 entries |
| `max_age_days` | Positive integer. Reuse observations younger than this, collect the rest. Default `14` |
| `force_refresh` | `true` collects everything fresh |

```bash
curl -s https://api.cookiecrowbar.com/v1/explore -H "X-API-Key: cs_live_YOUR_KEY" \
  -H "Content-Type: application/json" -d '{"domains": ["acme.example"]}'
```

The request waits a short while for collection. It answers `200` when every domain finished, otherwise `202` with
what is ready so far: poll [`GET /v1/scans/:batchId`](#get-v1scansbatchid) with its `batch_id`. The body is the
batch (below) plus `usage`, `queue` and, when an identical explore from this key was reused, `reused: true`.

## GET /v1/evidence/:scanId

The same drill-down for one of your own scans, by `scan_id` (a UUID) from a batch, with the same response shapes.
Takes `kind`, `target`, `filter` and `limit` as above, plus `revision` (an integer, 1 or more) to pin an earlier
version of the result. `404` when the scan, the revision or
its evidence isn't available.

## POST /v1/configs/test

Run a draft config over stored evidence from your scans: no collection, seconds, no allowance.

| Body | |
|---|---|
| `config` | The draft config, a JSON object. Required |
| `scan_ids` | 1 to 20 of your scan ids (UUIDs). Required |
| `revisions` | Optional `{ scan_id: revision }` pins: up to 20, each revision an integer, 1 or more |

Config syntax is in the `guide` MCP tool.

```json
{
  "results": [
    { "scan_id": "7d2e1b40-0000-4000-8000-000000000002", "revision": 1, "domain": "acme.example",
      "missing": [], "report": { "technologies": ["..."], "coverage": ["..."], "partial": false } }
  ],
  "warnings": ["custom matchers matched nothing in these scans: Example Widget"]
}
```

- `missing`: checks or pages the config wants that the evidence never collected. Explore them first.
- A scan id this key can't read comes back as an `error` inside its result, not as a `404`.
- `stale` lists scans whose evidence predates what the config now reads: explore them again before trusting
  their rows.

## POST /v1/configs

Save a config. Send it wrapped in an object; no other body fields are accepted:

```json
{ "config": { "...": "..." } }
```

Configs never change: saving a changed one gives a new id. `201`:

```json
{ "config_id": "5b8f0c11-0000-4000-8000-000000000003", "name": "crm-check", "config": { "...": "..." },
  "created_at": "2026-11-10T09:00:00.000Z" }
```

`400 INVALID_CONFIG` with `errors` when it doesn't validate.

## GET /v1/configs/:id

Read a saved config back by its id (a UUID), same shape. `404` when it isn't yours.

## POST /v1/scans

Run a saved config over a list of domains. Counts against the allowance.

| Body | |
|---|---|
| `config_id` | A saved config's id (a UUID). Required |
| `domains` | 1 to 10,000 by default. Required |
| `max_age_days`, `force_refresh` | As for explore |

`202`, straight away:

```json
{
  "batch_id": "9a4c7e55-0000-4000-8000-000000000004",
  "domains": 20,
  "execution_mode": "collector",
  "status_url": "/v1/scans/9a4c7e55-0000-4000-8000-000000000004",
  "usage": { "charged": false, "unit": "requested_domains", "batch_domains": 20, "month": { "domains": 62, "limit": null, "remaining": null } },
  "queue": { "kind": "scan", "unfinished": 20, "free": 99980 }
}
```

## GET /v1/scans/:batchId

Progress and per-domain results of a batch, from a scan or an explore, by its `batch_id` (a UUID).

| Query | |
|---|---|
| `status` | `pending`, `running`, `completed` or `failed` |
| `after` | The previous page's `next_after` |
| `limit` | Domains per page, default `100`, max `1000` |
| `view` | `full` (the whole report and evidence digest per domain) or `summary` (rows and coverage flags). Default `full` |
| `order` | `completed` lists completed rows only, in completion order. Use it, on every page, when walking a running scan batch. `after` then takes a previous `next_after` and `status`, if set, must be `completed`; otherwise `400 INVALID_REQUEST` |

```json
{
  "batch_id": "9a4c7e55-0000-4000-8000-000000000004",
  "kind": "scan",
  "status": "running",
  "counts": { "pending": 12, "running": 2, "completed": 6, "failed": 0 },
  "scans": [
    { "scan_id": "7d2e1b40-0000-4000-8000-000000000002", "domain": "acme.example", "status": "completed",
      "revision": 1, "progress": { "completed": 4, "pending": 0, "running": 0, "failed": 0 }, "result": { "...": "..." } }
  ],
  "next_after": "acme.example",
  "next": { "tool": "results", "batch_id": "9a4c7e55-0000-4000-8000-000000000004", "poll_after_seconds": 30 }
}
```

- With `order=completed`, `next_after` keeps a continuation while rows are still held back, including after
  `status` reads `completed`. Stop only when both `next_after` and `next` are absent, and follow `next`: repeat the
  call with its `order`, `after`, `limit`, `view` and `status`. An empty page can repeat the cursor.
- Read each domain as soon as it has a `result`. Wait only while its `progress` shows pending or running checks.
- `status` is `completed` once no domain is pending or running. No `next` means there is nothing left to wait for.
- Poll no faster than `next.poll_after_seconds`.
- In `view=summary`, each technology carries `name`, `category`, `confidence` and `verification`, with
  `partial`, `coverageGaps` and, when nothing third-party ran on the homepage, a `note`.

### Optional result fields

- `configured`: tools declared in a site's Google Tag Manager, apart from `technologies`. Each entry has `name`,
  `category`, `source` (`configured-in-tag-manager`), `strength` (`declared; execution not established`) and
  `alsoObserved` (`true` when a technology row of the same name exists). They are not scored, and a declared tool may
  never run. Absent when nothing was found; that is not proof of no tools.
- `emailPosture`: present on reports whose config runs `dns.records`.
  - `platform`: `microsoft-365`, `google-workspace`, `other` or `none` (no MX record observed).
  - `platformVia`: `mx`, `spf` or `dkim`, when a platform is named.
  - `gateways`: email-security vendor names. An empty list is not "no email security".
  - `dmarc`: `policy` (`none`, `quarantine`, `reject`, `missing` or `invalid`) and, when a policy exists, `pct`.
  - `dmarcMonitoring`: names of DMARC report vendors.
- Categories `itsm` and `device-management` are new. Jamf is now `device-management`, was `security`.

## GET /v1/feedback/template

The current feedback template: a fresh `submission_id`, the allowed issue kinds and field guidance.

## POST /v1/feedback

Send a filled template. Body up to 32 KiB. `201` with `feedback_id`, `submission_id` and `status: "received"`.
Sending the same `submission_id` with the same content again returns `200` and the original `feedback_id`;
different content with that id is `409 SUBMISSION_CONFLICT`. A `scan_id`, `config_id` or `batch_id` this key
can't read, or a `revision` that doesn't exist, is `404` with the `field` named.
