# Local HTTP API reference

> Look up the Sonjoo HTTP API routes, run options, limits, status codes, and error responses.

Canonical documentation: <https://sajaddehshiri.ir/sonjoo-seo-audit/api/reference/>

The local HTTP API serves `/api` on the Sonjoo dashboard's loopback listener. Send [the local token header](https://sajaddehshiri.ir/sonjoo-seo-audit/api/authentication/) with each API request. `GET /api` lists the routes in the running build. `GET /api/info` reports the version, category IDs, and capabilities available on that machine.

## Routes

Path parameters begin with `:`. Substitute a URL-encoded value when making a request.

| Method   | Path                                   | Use                                                                                                                                            |
| -------- | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `GET`    | `/api`                                 | List API methods and paths.                                                                                                                    |
| `GET`    | `/api/info`                            | Read version, rule count, category IDs and weights, and runtime capabilities.                                                                  |
| `POST`   | `/api/runs`                            | Start an audit. Returns `202` with `runId`, the initial `run` state, and `Location: /api/runs/current`.                                        |
| `GET`    | `/api/runs/current`                    | Get the active run, or `{ "run": null }` when idle.                                                                                            |
| `DELETE` | `/api/runs/current`                    | Request cancellation. Returns `202` if active or `204` if idle.                                                                                |
| `GET`    | `/api/runs/:runId`                     | Read the state of the current or most recent run.                                                                                              |
| `GET`    | `/api/runs/:runId/result`              | Read the retained run's `result` and audit metadata.                                                                                           |
| `GET`    | `/api/runs/:runId/rules/:ruleId/pages` | Page through per-URL evidence for one rule on a retained run.                                                                                  |
| `GET`    | `/api/runs/:runId/export`              | Download the retained report. Accepts `format=html\|markdown\|json\|llm`.                                                                      |
| `GET`    | `/api/runs/:runId/crawl`               | Browse a retained crawl's URLs or export CSV.                                                                                                  |
| `POST`   | `/api/runs/:runId/save`                | Save a retained result that is still unsaved and return its `auditId`.                                                                         |
| `GET`    | `/api/events`                          | Stream progress via server-sent events.                                                                                                        |
| `GET`    | `/api/audits`                          | List saved audits, newest first. Supports `domain`, `status`, `limit`, and `offset`.                                                           |
| `GET`    | `/api/audits/:id`                      | Read a saved audit by `auditId`. Findings are aggregated per rule.                                                                             |
| `DELETE` | `/api/audits/:id`                      | Delete a saved audit and its stored report. Returns `204`.                                                                                     |
| `GET`    | `/api/audits/:id/rules/:ruleId/pages`  | Page through per-URL evidence for one rule on a saved audit.                                                                                   |
| `GET`    | `/api/audits/:id/export`               | Download the saved report. Accepts `format=html\|markdown\|json\|llm`.                                                                         |
| `GET`    | `/api/audits/:id/crawl`                | Browse a saved crawl's URLs, export CSV, or compare saved crawls.                                                                              |
| `GET`    | `/api/audits/:id/compare`              | Compare reports. Use `against=<auditId>` to choose the baseline.                                                                               |
| `GET`    | `/api/domains`                         | List audited domains with current scores and recent movement.                                                                                  |
| `GET`    | `/api/domains/:domain/trend`           | Read the domain's score history in chronological order.                                                                                        |
| `GET`    | `/api/schedules`                       | List local crawl schedules and recent outcomes.                                                                                                |
| `POST`   | `/api/schedules`                       | Schedule from a saved completed website report. Send `auditId` and `intervalHours` of `24` or `168`. Returns `201` with `{ "created": true }`. |
| `PATCH`  | `/api/schedules/:scheduleId`           | Send `enabled`, `intervalHours` of `24` or `168`, or both.                                                                                     |

The rule-pages routes return `total` and `pages`. Their pagination defaults to `limit=100` and `offset=0`. Use `status=issues` for failing or warning evidence excluding advisory rows. Other `status` values leave the results unfiltered, and HTTP rule-pages routes do not use a `url` parameter. For an exact URL filter on per-rule evidence, use [MCP `get_rule_pages`](https://sajaddehshiri.ir/sonjoo-seo-audit/features/mcp-agent-skills/#mcp-tool-capabilities).

Crawl inventory routes default to `limit=25` and `offset=0`. Filter rows with `status`, `indexability`, `canonical`, `path`, `source` or `orphans=true`. Use `url` for a single URL and its links, or set `export` to `urls` or `broken-inlinks` to download the filtered rows as CSV. A saved crawl can be compared using `against=<auditId>` on its crawl route. Comparison requires inventory for both IDs.

The saved-audit list defaults to `limit=50` and `offset=0`. The audit list, crawl inventory and rule-pages routes accept limit values from 1–200 and offsets from 0–1,000,000. The domain trend route returns the most recent scores in chronological order and accepts `limit` from 1–100, with a default of 10. For report shapes and retained results, see [runs and findings](https://sajaddehshiri.ir/sonjoo-seo-audit/api/runs-and-findings/).

## Start request options

Send a JSON object of up to 2 MiB using `Content-Type: application/json`. The simplest body is `{ "url": "https://example.com", "save": false }`. To nest options, use `{ "url": "https://example.com", "options": { "save": false } }`. When `options` is an object, the server reads run options from that object. The `url` stays at the top level unless a URL list provides the entry.

| JSON field                      | Meaning and default                                                                                                                                                                                                                                            |
| ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `url`                           | Absolute HTTP(S) URL without credentials, up to 2,048 bytes. Required unless using `urlList`.                                                                                                                                                                  |
| `urlList`, `listFormat`         | Up to 1,000 input rows of URL list text with `listFormat: "text"` by default or `"csv"`. Each seed must be an absolute HTTP(S) URL without credentials and at most 2,048 bytes. List mode enables crawl and uses the valid, distinct seeds as its page budget. |
| `crawl`                         | Browse linked pages. Defaults to `false`.                                                                                                                                                                                                                      |
| `maxPages`                      | Crawl page budget. Integer `1–1000`, default `10`.                                                                                                                                                                                                             |
| `concurrency`                   | Parallel crawl fetch limit. Integer `1–20`, default `3`.                                                                                                                                                                                                       |
| `timeout`                       | Request timeout in milliseconds. Integer `1000–120000`, default `30000`.                                                                                                                                                                                       |
| `maxDuration`                   | Optional crawl collection budget in seconds. Integer `10–3600`. Report processing can continue after collection stops.                                                                                                                                         |
| `categories`                    | Array of category IDs. Omitting it or supplying an empty array selects all categories.                                                                                                                                                                         |
| `question`                      | Optional question of 1–500 characters for matching a passage on the entry page.                                                                                                                                                                                |
| `measureCwv`                    | Enable supported browser rendering and lab measurements. If omitted, a `true` value for `mobile` or `simulateInteraction` enables it automatically. Explicit `false` disables browser capture.                                                                 |
| `mobile`, `simulateInteraction` | Mobile emulation and simulated interaction for rendered single-page audits. Each defaults to `false`. Crawl mode clears both flags.                                                                                                                            |
| `save`                          | Save the report in history. Defaults to `true`.                                                                                                                                                                                                                |
| `staging`                       | Mark the run as a staging audit. Defaults to `false`.                                                                                                                                                                                                          |
| `refresh`                       | Request refresh where supported. Defaults to `false`.                                                                                                                                                                                                          |
| `ignoreCrawlDelay`              | Ignore a declared crawl delay. Defaults to `false`.                                                                                                                                                                                                            |

The HTTP server uses the engine's default project configuration and the options sent in the request. The limits here apply to HTTP and can differ from the CLI limits. See [the API quickstart](https://sajaddehshiri.ir/sonjoo-seo-audit/api/quickstart/) for runnable examples.

## Errors

An API error response has an `error` object with `code` and `message`. It may also contain `hint` or `details`. Check both the HTTP status and the error code before handling a failure.

```json
{
  "error": {
    "code": "invalid-option",
    "message": "A \"url\" is required.",
    "hint": "POST { \"url\": \"https://example.com\" }",
    "details": { "option": "url" }
  }
}
```

| HTTP status | Typical cause                                                                                  |
| ----------- | ---------------------------------------------------------------------------------------------- |
| `400`       | Request JSON, ID, query, or an option is invalid.                                              |
| `401`       | Token missing or invalid.                                                                      |
| `403`       | Request fails the local host or origin check.                                                  |
| `404`       | Route, report, run, or crawl data unavailable. A newer run can replace the retained result.    |
| `405`       | Method does not match the route. Inspect the `Allow` header.                                   |
| `409`       | Audit already running or a schedule for that domain already exists.                            |
| `413`       | Start request body exceeds 2 MiB.                                                              |
| `415`       | Start request content type is not JSON.                                                        |
| `422`       | A schedule request contains well-formed JSON that does not match the expected fields or types. |
| `429`       | Too many open progress streams.                                                                |
| `500`       | Internal processing, persistence, or export failed.                                            |
