# API quickstart

Source: https://docs.askaniela.com/user/api-quickstart/

The API takes and returns JSON over HTTPS at **`https://api.askaniela.com`**. This page walks you through the calls
an integration usually needs, from the key to the results. Every endpoint, field and error is in the
[API reference](https://docs.askaniela.com/reference/api.md), generated from `https://api.askaniela.com/openapi.json`.

All prices below are Just Ask (pay as you go) prices in USD. Packages and top-ups are cheaper: see
[Pricing](https://docs.askaniela.com/guide/pricing.md). Failed work costs $0, and reading results you already ordered (`GET`) is free.

## 1. Key and scopes

Create a project key in the project's **API keys** tab ([API keys](https://docs.askaniela.com/user/api-keys.md)) or in the
[developer panel](https://docs.askaniela.com/guide/developer-portal.md). The key (`gsj_...`) is shown once. Send it in every request:

```bash
export ASKANIELA_URL=https://api.askaniela.com
export ASKANIELA_API_KEY=gsj_...
curl -s "$ASKANIELA_URL/v1/usage" -H "Authorization: Bearer $ASKANIELA_API_KEY"
```

Without a key the API answers `401 unauthorized`. A new key has every scope this page needs:

| Scope | What it allows |
|---|---|
| `judge` | page checks (`/v1/judge`, `/v1/judge/batch`), Search Intent (`/v1/intent`), Google indexing checks, rule catalog |
| `jobs` | jobs (`/v1/jobs`), site audits (`/v1/audits/site`), pause, resume, cancel, audit add-ons |
| `reports:read` | reports, audits, intent reports, exports and fix plans |
| `labels:write`, `labels:read` | the Labeler: label pages and texts, read batches |
| `context:write` | page context (`/v1/context`) |

A call without the needed scope answers `403 insufficient_scope` with the missing scope in
`error.details.required_scope`. Scopes are fixed when the key is created; older keys may lack the newer ones.
More: [Authentication](https://docs.askaniela.com/guide/authentication.md).

### Top up your balance

Every paid call takes its price from the organization's prepaid USD balance. API keys use the same balance as the
app. Top up in the app under **Balance** (`https://app.askaniela.com/balance`): pick $10, $50, $100 or your own
amount (from $10), pay by card and the amount lands on the balance; a service fee of 2.9% + $0.30 is added to each
top-up and every purchase comes with an invoice. Packages (Ani Sip, Ani Cup, Ani Teapot) add a monthly amount
instead. Prices: [Pricing](https://docs.askaniela.com/guide/pricing.md), step by step: [Balance and payments](https://docs.askaniela.com/user/manual/balance.md).

Check the balance before the first paid call:

```bash
curl -s "$ASKANIELA_URL/v1/usage" -H "Authorization: Bearer $ASKANIELA_API_KEY"
# {"unit": "usd", ..., "balance": {"balance_usd": 50.0, "overdraft_usd": 5.0, ...}}
```

A call starts when the balance covers the amount reserved for it (the most it can cost); the balance may go down to
-$5.00 to let a running call finish. Unused reservation goes back to the balance when the call ends. With too little
balance the API answers `402 insufficient_balance` and does no work.

## 2. Check one page

```bash
curl -s "$ASKANIELA_URL/v1/judge" --max-time 300 \
  -H "Authorization: Bearer $ASKANIELA_API_KEY" -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/", "modes": ["spam"], "explain": true}'
```

- Send `url`, `html` or `text`. With `html` or `text` the page is not fetched and there is no fetch fee.
- `modes` picks the audit types: `spam`, `quality`, `helpful` (empty = all three). `rules` takes rule ids from
  `GET /v1/rules` or a ready set such as `preset:quick`. `explain: true` adds quotes and fixes for findings.
- Optional: `query` and `market` (fit to a target phrase), `render_js`, `report_lang` (`en` or `pl`), `project_id`.
- The call is synchronous and can take a few minutes. Set the client timeout to at least 300 seconds.

Price per page: Potential spam $0.0300, Quality rater $0.0300, Helpful content $0.0150, all three together $0.0650.
Your own rule selection up to 40 rules costs $0.0200. Page fetch +$0.0015, JavaScript rendering +$0.0060 (only when
the page was rendered). Every paid response has an `X-Cost-USD` header with the amount charged. Details:
[Billing](https://docs.askaniela.com/guide/billing.md).

The response has `violations` (spam policies), `quality_signals` (quality), `labels` (neutral information),
`positives` and `not_assessed`. Each rule result has `rule_id` and `signal`, the signal strength 0-100 (a ranking,
not a percentage). `report_id` and `report_url` point to the stored report. Field guide:
[Concepts](https://docs.askaniela.com/guide/concepts.md).

Up to 10 pages in one call: `POST /v1/judge/batch` with `{"items": [{"url": ...}, ...]}`. Each page gets its own
`report` or `error` in `results[]`.

## 3. Check a text before publishing

For a guest post or a sponsored article, check the text before it goes live. Write links as
`[anchor](https://address)`, set `url` to the address of the article or the publisher's domain (used as context,
not fetched) and use the `preset:guest-post` rule set:

```bash
curl -s "$ASKANIELA_URL/v1/judge" --max-time 300 \
  -H "Authorization: Bearer $ASKANIELA_API_KEY" -H "Content-Type: application/json" \
  -d '{"text": "Choosing a road bike...\n\nSee [our size guide](https://shop.example/size-guide) for details.",
       "url": "https://publisher.example/", "rules": ["preset:guest-post"], "explain": true}'
```

Price: **$0.0300 per text**, quotes included; the fix plan is a paid add-on ($0.10 when the text needs changes). The checks look at link anchors, the author bio and
promotional wording. Checks that need the page HTML are listed in `not_applicable`. The fix plan for the author: buy it with
`POST /v1/reports/{report_id}/fix-plan/order`, then `GET /v1/reports/{report_id}/fix-plan?format=md`.

## 4. Label pages and texts (Labeler)

The Labeler returns IAB Content Taxonomy 3.1 and Google Content Categories v2 categories, each with a strength 0-100.
Send one of `text`, `html` or `url`:

```bash
curl -s "$ASKANIELA_URL/v1/labels" --max-time 300 \
  -H "Authorization: Bearer $ASKANIELA_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: post-1842-v1" \
  -d '{"text": "Our sourdough uses only rye flour, water and salt...", "taxonomies": ["iab", "google"], "ref": "post-1842"}'
```

- `text` (up to 50,000 characters) and `html` (up to 2,000,000 characters) are labelled without a fetch. `url` is
  fetched by us. `ref` is your own id, returned unchanged.
- Price: $0.03 per 1 million document tokens for each taxonomy (a typical page costs about $0.06 per 1000 checks
  with one taxonomy). A URL adds $1.50 per 1000 pages for the fetch, and `render_js: true` adds $6.00 per 1000
  pages, only when the page was rendered. `charged_usd` in the response is the price of the check, split into
  `model_usd` (labeling), `fetch_usd` (page fetch) and `render_usd` (rendering).
- Batches of up to 1000 items: `POST /v1/labels/batch` (`202`, optional `webhook_url`), then
  `GET /v1/labels/batch/{id}` or `.../results.csv`. Free estimate first: `POST /v1/labels/estimate`.

Full guide with response fields, limits and errors: [Page labels](https://docs.askaniela.com/guide/labels.md).

## 5. Search Intent

```bash
curl -s "$ASKANIELA_URL/v1/intent?wait=30" \
  -H "Authorization: Bearer $ASKANIELA_API_KEY" -H "Content-Type: application/json" \
  -d '{"query": "best running shoes", "market": "en-US", "tier": "basic"}'
```

- **Levels** (`tier`): `basic` - intents, shares and the best form of page ($0.0098 per phrase); `premium` - also
  the top pages: length, elements, expectations ($0.0750); `compare` - also your page from `compare_url` next to the
  top pages ($0.0850).
- **Reused results** (`freshness: auto`, the default): a new order for a phrase, market and device checked in the
  last 3 days reuses what is ready. The basic part gets cheaper, the `premium` and `compare` surcharge stays:

  | `tier` | Nothing reused (`cache: miss`) | Search results reused (`serp`) | Ready analysis reused (`profile`) |
  |---|---|---|---|
  | `basic` | $0.0098 | $0.0030 | $0 |
  | `premium` | $0.0750 | $0.0682 | $0.0652 |
  | `compare` | $0.0850 | $0.0782 | $0.0752 |

  `freshness: fresh` always pays the first column. `price_usd` and `cache` in the report show what you paid and why.
- **New order, read, retry**: every new `POST /v1/intent` is a new order and is charged by the table above.
  `GET /v1/intent/{id}` reads an existing report for free. A `POST` repeated within 24 hours with the same
  `Idempotency-Key` and the same body returns the first answer without a new charge.
- **Waiting**: `?wait=N` (up to 60 s) keeps the request open. A report that is ready (`done` or `failed`) comes
  back as `200`. Otherwise you get `202` with the report `id` (`itr_...`) and a `Retry-After` header: wait that many
  seconds and read `GET /v1/intent/{id}`.
- **Many phrases**: `POST /v1/intent/batch` (JSON `items`, up to 100 phrases) or `POST /v1/intent/batch/csv`.
  Track a batch with `GET /v1/intent?batch_id=...` and download it with `GET /v1/intent/batches/{batch_id}/export.csv`.
- **Your own data**: on `POST /v1/intent` you can send your own search results (`serp`) and the documents of the top
  pages (`pages`, `premium` and `compare` only). Then we do not fetch them and you do not pay for our fetch.

Full guide with prices for your own data, fields and errors: [Search intent](https://docs.askaniela.com/guide/search-intent.md).

### Gain & Gap and Query Pack

Gain & Gap compares your page or text with the search results for one phrase: what it adds, what it misses and
where other pages say something different ($0.2000 per report). Query Pack is Search Intent and Gain & Gap for the
same phrase ($0.2700 with your page URL, $0.2600 with text only, $0.1500 for the phrase only, as a brief for a new
page).

```bash
curl -s "$ASKANIELA_URL/v1/infogain?wait=30" \
  -H "Authorization: Bearer $ASKANIELA_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: running-shoes-guide-v1" \
  -d '{"query": "how to choose running shoes", "market": "en-US", "url": "https://example.com/running-shoes"}'
# usually 202 with the report id (200 when ready within wait); read it with GET /v1/infogain/{id} (or ?format=md for an AI agent)
```

`POST /v1/query-pack` takes the same fields, then `GET /v1/query-pack/{id}`. A report usually takes several minutes.
Guide: [Gain & Gap and Query Pack](https://docs.askaniela.com/guide/gain-gap.md).

## 6. Page context

`POST /v1/context` checks one page (a URL or your text) and shows how well the title, H1, meta description and
H2/H3 headings match the content, each with a strength 0-100. Optional: page categories, fit to a site you audited
(`site`) and tips on how to fix weak elements (`fix: true`).

```bash
curl -s "$ASKANIELA_URL/v1/context" \
  -H "Authorization: Bearer $ASKANIELA_API_KEY" -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/sailing-course", "categories": ["iab"], "fix": true}'
```

Price per check: $0.0010, plus categories as in the Labeler, page fetch $0.0015, JavaScript rendering $0.0060 and
fix tips $0.0040 (only when there is something to fix). Free estimate: `POST /v1/context/estimate`.
Guide: [Page context](https://docs.askaniela.com/guide/page-context.md).

## 7. Site audits

A site audit checks a sample of pages from one site in the background (scope `jobs`).

```bash
# 1. preview (free): finds the sitemap and groups URLs into patterns
curl -s "$ASKANIELA_URL/v1/audits/site/preview" \
  -H "Authorization: Bearer $ASKANIELA_API_KEY" -H "Content-Type: application/json" \
  -d '{"site": "example.com"}'
# 2. estimate (free) with the same body you will run, then 3. start (paid)
curl -s "$ASKANIELA_URL/v1/audits/site" \
  -H "Authorization: Bearer $ASKANIELA_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: example-com-2026-11" \
  -d '{"site": "example.com", "preview_id": "...", "pages": 50, "modes": ["spam"]}'
# 202 {"audit_id": "aud_...", "job_id": "job_...", ...}
```

The estimate (`POST /v1/audits/site/estimate`) returns `cost_usd` and `cost_per_page_usd` before you pay. Send
`"start": false` to save the audit as a draft and start it later with `POST /v1/audits/{id}/start`.

**When is the audit ready?** Poll `GET /v1/audits/{id}` and wait the number of seconds in `Retry-After`.
`status: done` means the pages are assessed. Aniela's summary, the fix plan and add-ons are computed after that and
their state is in `completeness`:

| `status` | `completeness` | Ready? |
|---|---|---|
| `queued`, `running`, `pausing`, `paused`, `cancelling` | `null` | no, keep polling |
| `done` | `state: finishing` | no, keep polling |
| `done` | `state: complete`, or `null` | yes |
| `done` | `state: incomplete` | yes, without the parts listed in `missing` |
| `failed`, `cancelled` | `null` | final, see `error` |

Until the audit is ready, exports, share links, add-ons, retries and a new fix plan answer
`409 audit_in_progress` with `Retry-After`. Reading the audit works at any time. Details and code examples:
[When the audit is ready](https://docs.askaniela.com/guide/site-audits.md#when-the-audit-is-ready).

**Webhooks instead of polling.** An organization owner or admin registers an endpoint in the developer panel
(**Webhooks**). It receives a signed `job.finished` event for each site audit once the audit is ready, with
`audit.completeness` set to `complete` or `incomplete`. See [Organization webhooks](https://docs.askaniela.com/guide/developer-portal.md#organization-webhooks)
and [Site audits in webhooks](https://docs.askaniela.com/guide/webhooks.md#site-audits-in-webhooks).

Your own list of pages without sampling: `POST /v1/jobs` with up to 1000 `items` (`url`, `html` or `text`), see
[Webhooks and jobs](https://docs.askaniela.com/guide/webhooks.md). Topicality only, without rule checks (`"judge": false`), costs $0.0060 per
page plus the fetch.

## 8. Reports, exports and add-ons

| What | Call |
|---|---|
| Page reports | `GET /v1/reports` (`?url=`, `?limit=`, `?audit_id=`, next page `?cursor=` from the `X-Next-Cursor` header), `GET /v1/reports/{id}` |
| Signal strength of every rule | `GET /v1/reports/{id}/signals` |
| Page fix plan | `GET /v1/reports/{id}/fix-plan?format=md` or `json` |
| Page exports | `GET /v1/reports/{id}/export.html`, `export.pdf` |
| Audits | `GET /v1/audits` (light list; `?view=full` for full objects), `GET /v1/audits/{id}` |
| Audit results | `GET /v1/audits/{id}/export.json` (machine-readable), `export.csv`, `export.html`, `export.pdf`, `export.zip` |
| Site fix plan | `GET /v1/audits/{id}/fix-plan?format=md` or `json` |
| Content pruning | `GET /v1/audits/{id}/pruning`, `pruning.csv` |
| Internal links | `GET /v1/audits/{id}/links.csv` |
| Intent exports | `GET /v1/intent/{id}/export.html`, `.pdf`, `.md`, `.csv` |

Large exports and new fix plans answer `202` with `Retry-After` while they are prepared; repeat the GET after that
time.

Add-ons extend a finished report or audit without checking everything again. `GET /v1/reports/{id}/addons` and
`GET /v1/audits/{id}/addons` list what can be added, with `price_usd`; `POST` on the same path orders one `kind`
(`indexing`, `fix_plan`, `audit_type`, and for audits also `topicality`). Google indexing of any list
of addresses: `POST /v1/indexing` ($0.0100 per address that gets a result), then `GET /v1/indexing/{id}`.

## 9. Usage, retries and errors

- `GET /v1/usage` shows spending today and this month for you, the project and the organization, plus the balance in
  USD. Prices for the current price list: `GET /v1/tiers` (no key needed).
- What to do with an error:

  | Status and `code` | What happened | What to do |
  |---|---|---|
  | `401 unauthorized`, `invalid_api_key`, `api_key_expired` | no key, wrong or revoked key, expired key | send `Authorization: Bearer gsj_...`; create or rotate the key |
  | `402 insufficient_balance` | the balance does not cover this call (`details.balance_usd`, `requested_usd`, `topup_url`) | top up at `details.topup_url`, then send the call again; retrying earlier does not help |
  | `402 fix_plan_not_purchased` | the fix plan of this report or audit is not bought | buy it with `POST .../fix-plan/order` (price in `details.price_usd`) |
  | `403 insufficient_scope` | the key lacks a scope (`details.required_scope`) | create a key with that scope |
  | `409 audit_in_progress` | the audit is not ready yet | wait `Retry-After` seconds and repeat |
  | `413 ...`, `422 ...`, `400 ...` | the request is too large or invalid (`details` lists the fields) | fix the request; do not retry it unchanged |
  | `429 rate_limited`, `labels_rate_limited` | too many requests per minute | wait `Retry-After` seconds and retry |
  | `429 quota_exceeded` | a spending limit set for you, the project or the organization is used up | wait for the next day or month (UTC) or ask the organization owner to raise the limit |
  | `429 too_many_active_jobs` | too many audits or jobs running at once | wait `Retry-After` seconds or until one finishes |
  | `503 start_uncertain` (`POST /v1/intent`, `/v1/intent/batch`) | the order may have been accepted and its price stays reserved until it is settled | do not retry automatically: first look for it in `GET /v1/intent` (or `?batch_id=`); send it again only if it is not there. A retry can order a second paid analysis |
  | `507 idempotency_result_too_large` | the work was done and charged, but the stored answer is too large to replay | do not retry; find the result with `GET /v1/reports` or `GET /v1/jobs` |
  | other `5xx` (`fetch_failed`, `inference_failed`, `unavailable`, ...) | the page could not be fetched or a service is busy | nothing is charged; retry later with the same `Idempotency-Key` |
- Send an `Idempotency-Key` header on paid `POST` calls. A retry with the same key and body returns the first answer
  without new work or charge for 24 hours. See [Retrying safely](https://docs.askaniela.com/user/agents.md#retrying).
- Every error has the same shape. Branch on `code`, not on `message`:

```json
{"error": {"code": "insufficient_scope", "message": "...", "details": {"required_scope": "jobs"}, "request_id": "..."}}
```

All codes: [Errors](https://docs.askaniela.com/reference/errors.md). Connecting an AI agent, a script or n8n: [API for AI agents](https://docs.askaniela.com/user/agents.md).
