# Site audits

Source: https://docs.askaniela.com/guide/site-audits/

A site audit checks a sample of pages from one site and returns one site report: risk per policy, URL
patterns, worst pages and a site verdict.

The flow has two steps: **preview** (count pages and group them into URL patterns), then **select and run**.

## 1. Preview

```bash
curl -H "Authorization: Bearer $KEY" -H 'content-type: application/json' \
  -d '{"site": "example.com"}' https://api.askaniela.com/v1/audits/site/preview
```

Sources (one of):

- `site` - domain or page URL; the sitemap is read from `robots.txt` (`Sitemap:`) or `/sitemap.xml`.
- `sitemap_url` - a direct sitemap or sitemap index.
- `urls` - your own list of URLs. Duplicates, invalid and private addresses are skipped (`rejected`); with
  `same_site: true` (default) only URLs from the host of the first URL are kept.
- `items` - bulk import: `[{"url": "…", "html": "…"}]`. Items with `html` are judged from that HTML **without
  fetching**; items without `html` are fetched. HTML limits are the same as for `POST /v1/jobs` (per item and
  in total, `413 item_too_large`).

`/path` and `/path/` count as the same URL (many CMS serve both); send `distinct_slash: true` to keep them apart.

In the panel you can upload a **TXT** file (one URL per line), a **CSV** with columns `url` and optional `html`
(use standard CSV quoting for HTML), or a **ZIP** with `index.csv` (`url,filename`) and the `.html` files.

Response: `preview_id`, `total`, `rejected`, and `patterns` - each with `count`, `lastmod_min`, `lastmod_max` and
up to three `samples`. A pattern replaces variable path segments with `<n>`, `<date>` and `<slug>`
(e.g. `/news/<slug>`).

## 2. Select, estimate, run

Send the same body to `/v1/audits/site/estimate` (no job is created) and then to `/v1/audits/site`:

```json
{
  "preview_id": "…",
  "site": "example.com",
  "scope": {"exclude_patterns": ["/people/<slug>"], "exclude": ["/tag/*"], "include": [], "exclude_urls": []},
  "pages": 30,
  "strategy": "groups",
  "seed": 20261013,
  "preset": "quick",
  "rules": ["SP-KWS-REPEAT", "SP-AFF"]
}
```

- **Scope**: `include_patterns` / `include` (empty = all), then `exclude_patterns`, `exclude` and `exclude_urls`.
  Text rules are globs (`*`, `?`): starting with `/` they match the path (`/people/*`), otherwise the full URL.
  Regular expressions are not accepted.
- **Changed default (beta)**: requests without `strategy` used `newest+stratified` before and now use `groups`,
  so the same request picks a different sample. Send `"strategy": "newest+stratified"` to keep the previous behaviour.
- **Strategy**: `groups` (default): pages linked from the home page (10%), the newest sitemap pages from the current
  year by lastmod (25%) and a random sample of the whole list (the rest); shares in `group_shares{home, newest}`, a group
  with too few URLs is topped up by the others. Each sampled page keeps its group (`plan.pages[].reason`), the plan has
  `plan.groups[{group, pool, sampled}]` and the site report shows the result per group. The home page is read once
  as raw HTML (links only, no rendering, no charge). `newest+stratified` (a third newest by lastmod, the rest stratified random per pattern),
  `stratified` (random per pattern), `newest` (by lastmod), `all` (all selected, up to `pages`). The same seed and
  URL list give the same sample.
- **Estimate**: `cost_usd = pages × price per page` (`cost_per_page_usd`: one full mode Spam $0.0300, Quality $0.0300 or Helpful content $0.0150;
  several full modes = their sum, never more than the full audit $0.0650; another rule selection: $0.0200 up to 40
  rules, otherwise $0.0650; +$0.0015 fetch per page without your HTML, +$0.0060 per fetched page
  with `render_js` `on` or `auto`, refunded for pages that were not rendered; see [Billing](https://docs.askaniela.com/guide/billing.md) and
  [Fetching](https://docs.askaniela.com/guide/fetching.md)), plus time. Prices come from the versioned price list. `preset` only affects the estimate; send `rules` to choose rules.
  `categories` (`["spam", "quality", "helpful"]`, default all) narrows the rules and the estimate; the
  findings CSV has a `category` column and the page CSV a `helpful_level` column.
- `preview_id` reuses the URL list (and imported HTML) from step 1 for a limited time, only for the same user or
  API key and project. With an expired id the site is read again; an import must be sent again (`preview_expired`).
- The estimate shows `with_html` - selected pages that will be judged from your HTML.

The audit stores the selection (source, patterns and rules, estimate) and shows it in the site report.
Preview, estimate and run need an API key with the `jobs` scope ([Authentication](https://docs.askaniela.com/guide/authentication.md)).

## 3. Progress and results

`POST /v1/audits/site` returns `202 {"audit_id": "aud_…", "job_id": "job_…", "pages": …, "patterns": …}`. Poll
`GET /v1/audits/{id}` for progress (while queued or running it sends `Retry-After` in seconds, 15-300, and
`eta_seconds` from the current engine pace and the queue ahead): `progress.status` uses the same 8 values as a job (see
[Job statuses](https://docs.askaniela.com/guide/webhooks.md#job-statuses)); the audit is finished at `done`, `failed` or `cancelled`. The
`job_id` also works with `GET /v1/jobs/{id}` and the `pause`, `resume` and `cancel` actions
(`POST /v1/audits/{id}/pause|resume|cancel`). Organization webhooks receive `job.finished` with this `job_id`
once the audit is ready (see below).

### When the audit is ready

`status: done` means that **the pages are assessed**. Some parts of a site audit are computed after that, in the
background: Aniela's summary, the fix plan, categories, topicality and Visibility. Their state is in `completeness`
in `GET /v1/audits/{id}`. Read the results only when the audit is ready:

| `status` | `completeness` | Ready? | What to do |
|---|---|---|---|
| `queued`, `running`, `pausing`, `paused`, `cancelling` | `null` | no | keep polling (`Retry-After`) |
| `done` | `{"state": "finishing", …}` | no | parts are still computed or retried; keep polling (`Retry-After`) |
| `done` | `{"state": "complete", …}` | yes | every ordered part is ready |
| `done` | `{"state": "incomplete", "missing": […]}` | yes | finished without the parts in `missing`; the rest of the audit is final |
| `done` | `null` | yes | no parts are tracked for this audit (older audits) |
| `failed`, `cancelled` | `null` | final | the audit stopped; see `error` and `progress` |

`completeness.parts[]` lists each part with `state` (`done`, `running`, `retry` = failed for a temporary reason and
retried automatically, `failed` = no result after all attempts), `attempts` and `next_retry_at`:

| Part | What it is |
|---|---|
| `site_steps` | site-level steps right after page assessment are still running; the other parts appear as they start |
| `decision` | Aniela's summary of the site and the notes per role |
| `fix_plan` | the site fix plan, when ordered (also `progress.fix_plan`); paid add-on since 2026-11-15: `fix_plan: true` buys it when the audit finishes, or buy it later with `POST /v1/audits/{id}/fix-plan/order` |
| `categories` | content categories of the site and its pages (`content_categories`) |
| `topicality` | topical focus of the site (`topicality`) |
| `visibility` | the Visibility add-on, when ordered (`visibility`) |

While `status` is `done` and `completeness.state` is `finishing`, `GET /v1/audits/{id}` also sends `Retry-After`.
The `status` field itself does not change: it stays the job status, so existing integrations keep working.

Until the audit is ready, actions on it return **409 `audit_in_progress`** with `Retry-After` (seconds): exports
(`export.html`, `export.pdf`, `export.csv`, `export.json`, `export.zip`, `pruning.csv`, `links.csv`), new share links
(`POST /v1/audits/{id}/shares`), add-ons (`POST /v1/audits/{id}/addons`, `/upgrade`, `/evidence/refresh`,
`/indexing`), `POST /v1/audits/{id}/retry-failed` and a new fix plan (`GET`/`POST /v1/audits/{id}/fix-plan` when no
plan was ordered yet, or with `?regenerate=true`). A fix plan that is already being prepared is returned as usual
(202 while it is generated). Reading the audit (`GET /v1/audits/{id}`, `/pruning`, `/addons`) works at any time.

```bash
until curl -sS --fail-with-body "https://api.askaniela.com/v1/audits/$ID" -H "Authorization: Bearer $KEY" \
  | jq -e '(.status | IN("failed","cancelled")) or (.status == "done" and .completeness.state != "finishing")' >/dev/null
do sleep 30; done
```

```python
# client = httpx.Client(base_url="https://api.askaniela.com", headers={"Authorization": f"Bearer {KEY}"})
def ready(audit: dict) -> bool:
    if audit["status"] in ("failed", "cancelled"):
        return True  # final, without results to wait for
    state = (audit.get("completeness") or {}).get("state")
    return audit["status"] == "done" and state != "finishing"  # complete, incomplete or null

while True:
    r = client.get(f"/v1/audits/{audit_id}")
    if ready(audit := r.json()):
        break
    time.sleep(int(r.headers.get("Retry-After", "30")))
missing = (audit.get("completeness") or {}).get("missing", [])  # parts without a result, if any
```

Organization webhooks wait for the same moment: `job.finished` for a site audit is sent once, after `completeness` is
`complete` or `incomplete`, and carries that state in `audit.completeness` (see
[Site audits in webhooks](https://docs.askaniela.com/guide/webhooks.md#site-audits-in-webhooks)).

Results: `GET /v1/audits/{id}/export.json` (machine-readable, answers `202` with `Retry-After` while it is being
prepared), `export.csv`, `export.html`, `export.pdf`, and `GET /v1/audits/{id}/fix-plan?format=json|md` for the fix
plan (also `202` with `Retry-After` on the first request). The Markdown fix plan is a ready instruction set for an
AI agent: context, rules for safe work (backups, only the listed pages, no publishing without a person's approval,
before/after, no invented facts), steps page by page with the quote from each page, verification with signal strength
(0-100) and a report template for a person. In JSON each action has `steps` (`page`, `quotes`, `signal`). All need `reports:read`. Results are in the audit's
language (`report_lang`); `?lang=en|pl` on `GET /v1/audits/{id}` and the exports gives them in the other language.
In `export.json` (`schema_version` 1.21) `rule_id` is the rule id from `GET /v1/rules`, `policy` the policy name and
`title` the rule title. For link rules each verified quote in `evidence[]` has `links[]` with the page links it points
to (`anchor`, `href`, `rel`, `host`, `region`, `external`), taken from the page's link list, not from the quote text.
Reports of one audit: `GET /v1/reports?audit_id=aud_…` (next page `?cursor=` from the `X-Next-Cursor` header).

**Listing audits.** `GET /v1/audits` returns a light item per audit (`view=summary`, default): status, progress
counters, `brief`, `completeness`, `pages` and `report_count`, without the page list, report ids and site parts.
`brief.max_signal` is the strongest signal strength 0-100 on any checked page across the audit types you ordered,
with `brief.max_signal_level` (`high`, `medium`, `low`); both are empty (`null`, `""`) when no rule was scored and
may be empty for audits finished before these fields were added.
`?view=full` returns full objects (about 1 MB for an audit of several hundred pages). Before this change the list
always returned full objects; send `?view=full` to keep that behaviour. Errors: `invalid_url`, `item_too_large`, `preview_expired`, `invalid_scope`, `empty_selection`, `sitemap_not_found`,
`audit_too_large`, `insufficient_balance`, `quota_exceeded`, `queue_unavailable`.

A finished site audit usually also has `topicality` in `GET /v1/audits/{id}` (on by default, no extra charge; `null`
when it could not be measured): how consistently the site sticks to its topics. `score` 0-100 (higher = more focused), `outliers[]` (pages far from the
site's main topics), `clusters[]` (groups of pages on one topic), `clones[]` (near-duplicate page pairs),
`excluded[]` (list and technical pages left out). With too few content pages `no_measure` is set
(`too_few_content_pages`) and the score fields are 0. `partial: true` = measured on part of the pages. The measurement is
descriptive and does not change rule results.

**Topicality only** (`"judge": false`, needs `"topicality": true`): the pages are fetched and measured (topical focus,
content map, categories, heading coherence), with no rule checks. The report has no spam or quality findings; instead it
lists what to fix from the measurement (pages far from the main topic, near-duplicates, loose sections, home page off the
main sections, titles/H1/meta/headings off the content, repeated headings, missing title/H1/description). Price per page:
`topicality` + page fetch (see [Pricing](https://docs.askaniela.com/guide/pricing.md)). `modes`, `rules`, `explain` and `fix_plan` are ignored.
Example: `{"site": "example.com", "pages": 50, "judge": false}`. Single pages and lists: not available (use Labels for categories).

In the panel: **New site audit** → enter a site or upload a file → tick patterns, add include/exclude rules,
set pages and preset → check the estimate → **Run audit**.

## Check my fixes (one page again)

`POST /v1/audits/{id}/pages/{index}/recheck` downloads one page of a finished audit again and checks it with the
audit's rules; `POST /v1/reports/{report_id}/recheck` does the same from a page report. The answer is 202 with
`revision_id`, `job_id` and `reserved_usd` (`job_id` is `null` while the check waits in the queue). The result is a new page report (a revision); the previous one is kept and
the audit (`GET /v1/audits/{id}`, exports, share link) shows the newest revision of each page. `page_revisions` in the
audit lists re-checked pages by their current report id with the page `index`.

`GET /v1/audits/{id}/pages/{index}/revisions` returns the revisions and `compare`: for each rule with a finding before
or after, signal strength 0-100 before and after and `fixed`, `still` or `new`, plus `next_check_free` and
`next_check_usd`. The first check of each page is free; later checks of the same page cost one page of that audit
type. Limits: one live check per page (409 `page_check_running`), 10 minutes between checks of a page (429
`recheck_cooldown`) and a daily limit per audit (429 `recheck_daily_limit`). Up to 5 checks of an organization run
at once; further checks are accepted and wait in the organization's queue (`status: waiting`, the panel shows "In the
queue") and start in order - only an overfull queue (200 waiting) returns 429 `recheck_busy`. To check many pages in
one call use `POST /v1/audits/{id}/pages/recheck` with `{"indexes": [...]}`. The org webhook `audit.page_rechecked`
reports the end of each check. A check closed in the queue before it started (24 hours of waiting, or the audit
was archived, deleted or moved) gets `status: failed` with the reason in `revision.error`, the reserved amount is
returned and the webhook is sent too; `audit` is `null` when the audit was deleted or moved. You can also poll
`GET /v1/audits/{id}/pages/{index}/revisions` to see the final state of a waiting check. If the audit was deleted (or moved to another organization), this call
returns 404 `audit_not_found` - treat it as the end of polling in this organization. The reserved amount is always returned, but after a project
is deleted the return can take a few minutes.
