# Page labels: IAB 3.1 and Google categories

Source: https://docs.askaniela.com/guide/labels/

The Labeler tells you what a page or a piece of text is about. You send a text or a URL and get categories from
two standard taxonomies:

| Key | Taxonomy | Category id | Classifier |
|---|---|---|---|
| `iab` | IAB Content Taxonomy 3.1 | the unique id published by IAB Tech Lab, e.g. `653` | `taxonomy-small-iab` |
| `google` | Google Content Categories v2 | the full path, e.g. `/Travel & Transportation` | `taxonomy-small-nv2` |

Common uses: sorting large lists of sites or articles by topic, checking that a page fits a campaign or a
publisher's vertical, and grouping a site's pages before an audit.

## Endpoints

| Method and path | What it does | Scope |
|---|---|---|
| `POST /v1/labels` | Label one text or one URL, answer in the same response | `labels:write` |
| `POST /v1/labels/batch` | Label up to 1000 items in the background, `202` | `labels:write` |
| `GET /v1/labels/batch/{id}` | Batch status and results | `labels:read` |
| `GET /v1/labels/batch/{id}/results.csv` | Results of a finished batch as CSV | `labels:read` |
| `POST /v1/labels/batch/{id}/cancel` | Cancel items that have not started, the rest of the hold returns | `labels:write` |
| `POST /v1/labels/estimate` | Free price estimate, nothing is charged or held | `labels:read` |
| `POST /v1/labels/{id}/items/{index}/recheck` | Check one page again after your changes, the previous result stays | `labels:write` |
| `GET /v1/labels/{id}/items/{index}/revisions` | All checks of one page and a before/after comparison | `labels:read` |
| `GET /v1/labels/{id}/items/{index}/agent.md` | Instructions for an AI agent (Markdown): how to make the topic of the page clear | `labels:read` |
| `POST /v1/labels/raw` | Raw taxonomy model output for a text (selected partners, see [Raw model output](#raw-model-output)) | `labels:write` |
| `POST /v1/labels/decide` | Your own yes/no, choice or score questions about a text (selected partners, see [Decision model](#decision-model-your-own-questions)) | `labels:write` |

Base URL: `https://api.askaniela.com`. Authenticate with an API key in `Authorization: Bearer <key>`
([Authentication](https://docs.askaniela.com/guide/authentication.md)). New keys get both `labels:write` and `labels:read`. A key that only
reads results needs just `labels:read`. You can create and test keys in the
[developer panel](https://docs.askaniela.com/guide/developer-portal.md).

## Label one text

Send the text itself whenever you have it. This is the cheapest and fastest option (price variant `document`).

```bash
curl --max-time 300 https://api.askaniela.com/v1/labels \
  -H "Authorization: Bearer $ANIELA_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: post-1842-v1" \
  -d '{"text": "Our sourdough uses only rye flour, water and salt. Feed the starter the night before...",
       "taxonomies": ["iab", "google"]}'
```

```python
import os, httpx

r = httpx.post(
    "https://api.askaniela.com/v1/labels",
    headers={"Authorization": f"Bearer {os.environ['ANIELA_KEY']}",
             "Idempotency-Key": "post-1842-v1"},  # same key on retry = no second charge
    json={"text": article_text, "taxonomies": ["iab", "google"], "ref": "post-1842"},
    timeout=300,
)
r.raise_for_status()
res = r.json()
print(res["labels"]["iab"]["primary"])  # {'id': '210', 'name': 'Food & Drink', 'strength': 91}
```

```javascript
const r = await fetch("https://api.askaniela.com/v1/labels", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.ANIELA_KEY}`, "Content-Type": "application/json",
             "Idempotency-Key": "post-1842-v1" },
  body: JSON.stringify({ text: articleText, taxonomies: ["iab"] }),
  signal: AbortSignal.timeout(300_000),
});
const res = await r.json();
console.log(res.labels.iab.primary.name, res.labels.iab.primary.strength);
```

## Label one URL

Send `url` instead of `text` (price variant `url`). We fetch the page, extract the main text and label it.
JavaScript is not rendered unless you set `render_js: true`.

```bash
curl --max-time 300 https://api.askaniela.com/v1/labels \
  -H "Authorization: Bearer $ANIELA_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: lisbon-url-v1" \
  -d '{"url": "https://example.com/blog/lisbon-in-three-days", "taxonomies": ["iab"]}'
```

## Label page HTML you already have

If you already downloaded the page (your own crawler, a CMS export), send its HTML in `html` instead of `url`.
We extract the title and main content exactly as after our own fetch (cookie and consent pop-ups are cut, lists of
posts are marked) and label it. No fetch, no fetch fee: the price is the same as for `text` (variant `document`).
`html` takes up to 2,000,000 characters; `render_js` is ignored.

```bash
curl --max-time 300 https://api.askaniela.com/v1/labels \
  -H "Authorization: Bearer $ANIELA_KEY" -H "Content-Type: application/json" \
  -d "$(jq -n --rawfile h page.html '{html: $h, taxonomies: ["iab"]}')"
```

Request fields (`POST /v1/labels`):

| Field | Type | Notes |
|---|---|---|
| `text` | string | Plain text, up to 50,000 characters. Give exactly one of `text`, `html` or `url` |
| `html` | string | Page HTML, up to 2,000,000 characters. Same extraction as after a fetch, no fetch fee |
| `url` | string | Public `http(s)` address, up to 2048 characters (we fetch it, fetch fee) |
| `taxonomies` | array | `["iab"]` (default), `["google"]` or both |
| `ref` | string | Your own id, up to 200 characters, returned unchanged |
| `render_js` | boolean | URL only. `true` renders JavaScript (extra fee, only when the page was rendered) |
| `project_id` | string | Project to bill and store the result in. You can also use the `X-Project-ID` header |

`POST /v1/labels` accepts an `Idempotency-Key` header, so a retried request is not charged twice. Use one key per request (e.g. your own record id) and send the same key when you retry after a timeout or network error.

## Response

```json
{
  "index": 0,
  "ref": null,
  "url": "https://example.com/blog/lisbon-in-three-days",
  "variant": "url",
  "status": "ok",
  "error": null,
  "rendered": false,
  "low_content": false,
  "failed": [],
  "charged_usd": 0.00156,
  "model_usd": 0.00006,
  "fetch_usd": 0.0015,
  "render_usd": 0.0,
  "document_tokens": 2000,
  "run_id": "lbl_...",
  "labels": {
    "iab": {
      "taxonomy": "iab",
      "taxonomy_name": "IAB Content Taxonomy 3.1",
      "primary": {"id": "659", "name": "Europe Travel", "strength": 71},
      "primary_l1": {"id": "653", "name": "Travel", "strength": 95},
      "paths": [
        {"id": "659", "path": "Travel > Travel Locations > Europe Travel", "strength": 71},
        {"id": "672", "path": "Travel > Travel Type > City Trips", "strength": 12}
      ],
      "primary_path": [
        {"level": 1, "id": "653", "name": "Travel", "strength": 95},
        {"level": 2, "id": "655", "name": "Travel Locations", "strength": 88},
        {"level": 3, "id": "659", "name": "Europe Travel", "strength": 85}
      ],
      "primary_confident": {"id": "659", "name": "Europe Travel", "strength": 85}
    }
  }
}
```

| Field | Meaning |
|---|---|
| `status` | `ok`, `partial` (one of two taxonomies has no answer, see `failed`) or `error` (see `error`) |
| `labels.<taxonomy>.primary` | Main category: the deepest category of the best path in the main top-level branch |
| `labels.<taxonomy>.primary_l1` | Main top-level category (the branch of `primary`) |
| `labels.<taxonomy>.primary_path` | Levels of `primary` from the top level down, each with its conditional strength (see below). Empty in results made before 2026-11-13 |
| `labels.<taxonomy>.primary_confident` | Deepest level of `primary_path` reached while every level so far is at or above the taxonomy threshold (IAB 35, Google 25). `null` when even the top level is below it |
| `low_content` | `true` below about 600 characters of readable text: labels are less reliable |
| `labels.<taxonomy>.paths` | Best paths from the top level down, strongest first. `id` is the deepest category of the path |
| `strength` | Signal strength 0-100 |
| `failed` | Taxonomies without a result. They are not charged |
| `rendered` | `true` when JavaScript was rendered (and paid for) |
| `variant` | `document` (you sent text or html) or `url` (we fetched the page) |
| `charged_usd` | Price of this check in USD. `0` when it failed |
| `model_usd`, `fetch_usd`, `render_usd` | Parts of `charged_usd`: labeling, page fetch, JavaScript rendering |
| `document_tokens` | Size the check was billed on, summed over taxonomies. A secondary detail, you can ignore it |

### How to read strength

Strength shows how clearly the text points at a category compared with the other options in the same answer.
It is a ranking, not a probability or a percentage. Use it to compare categories within one result, for
example "take the main category, and also the paths above 30". A low strength on every path usually means
the text is short, mixed or off-topic for the taxonomy. Pick your own cut-off on a sample of your data.

A path is scored as a whole, so a deep path is usually weaker than its top-level category. That is expected.

There are two kinds of strength:

- **Path strength** - `primary.strength` and `paths[].strength`. The whole path from the top level down: the
  choices at each level multiplied together. The deeper the category, the lower it gets, even when every level
  is a clear choice (for example 95 × 88 × 85 gives 71).
- **Conditional strength** - `primary_path[].strength` and `primary_confident.strength`. How clearly the text
  points at this level once the level above is chosen. It does not drop with depth, so it tells you how deep
  the main category is still reliable.

If you want a single category you can trust, use `primary_confident`: it stops at the first level whose
conditional strength is below the taxonomy threshold (IAB 35, Google 25). Use `primary` when you want the most
specific guess.

## Batches (up to 1000 items)

For more than a handful of items use a batch. It runs in the background and is easier on rate limits.

```bash
curl --max-time 300 https://api.askaniela.com/v1/labels/batch \
  -H "Authorization: Bearer $ANIELA_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: batch-2026-11-01-a" \
  -d '{"taxonomies": ["iab", "google"],
       "webhook_url": "https://example.com/hooks/labels",
       "items": [{"url": "https://example.com/a", "ref": "a"},
                 {"text": "Plain text of another article...", "ref": "b"}]}'
# 202 {"id": "lbl_...", "status": "queued", "total": 2, "price_usd": ..., "estimated_usd": ...}
```

```python
import time, httpx

api = httpx.Client(base_url="https://api.askaniela.com",
                   headers={"Authorization": f"Bearer {key}"}, timeout=300)
run = api.post("/v1/labels/batch", json={"items": items, "taxonomies": ["iab"]}).json()
while run["status"] in ("queued", "running"):
    time.sleep(10)
    run = api.get(f"/v1/labels/batch/{run['id']}").json()
for item in run["items"]:
    print(item["ref"], item["status"], item["labels"].get("iab", {}).get("primary"))
```

- `GET /v1/labels/batch/{id}` returns the batch with `items` (same fields as a single result). While it runs,
  the response has `Retry-After` with the number of seconds to wait before asking again.
- Batch `status`: `queued`, `running`, `done`, `partial` (some items failed), `failed`, and after a cancel
  `cancelling` (items already running are finishing) and `cancelled`.
- `POST /v1/labels/batch/{id}/cancel` stops a batch: items that have not started become `cancelled`, are not run
  and not charged, and their held amount returns to your balance. Items already running finish and are charged as
  usual. The answer is `{"run": <batch>, "changed": true}`; a second call or a finished batch returns
  `changed: false`. `done` counts items with a result or an error, `cancelled` the cancelled ones. The webhook
  `labels.finished` is sent once the batch is `cancelled`.
- `render_js` on the batch is the default for items, each item can override it.
- One bad item does not reject the batch. An item that is empty, has more than one of `url`, `html` and `text`,
  has a URL that is not a public `http(s)` address, a field over its limit (`url` 2048, `ref` 200, `text` 50,000,
  `html` 2,000,000 characters) or `source_url` without `html` stays at its `index` with `status: "error"`, your
  `ref`, the reason in `error` and a stable `error_code` (`missing_input`, `multiple_inputs`, `invalid_url`,
  `field_too_long`, `invalid_source_url`, `invalid_item`). It is not held, run or charged; the other items run as
  usual and the batch ends `partial`. Such an item cannot be rechecked: send it again in a new check. The whole
  request is rejected (`422`) only when `items` is not a list, is empty or has more than 1000 items, or a
  taxonomy is unknown.
- `GET .../results.csv` returns one row per item: `index`, `ref`, `url`, `status`, `error`, then per taxonomy
  the main category id, name and strength and the top 3 paths as `path|strength` separated by `; `, and at the
  end `document_tokens`, `charged_usd` and its parts `model_usd`, `fetch_usd`, `render_usd`, `error_code`. Asking for the CSV of a running batch returns `409 label_batch_running`.

### Webhook

With `webhook_url` (https) we send one POST when the batch finishes:

```http
POST /hooks/labels
Content-Type: application/json
X-GSPAMJUDGE-Event: labels.finished
X-GSPAMJUDGE-Delivery: 5f0c...
X-GSPAMJUDGE-Timestamp: 1761926400
X-GSPAMJUDGE-Signature: sha256=<hex>

{"event": "labels.finished", "id": "5f0c...", "run": {"id": "lbl_...", "status": "done", "total": 1000, "done": 1000, "errors": 3, "charged_usd": 0.61, ...}}
```

The body has the batch summary without items, fetch them with `GET`. Deduplicate on `X-GSPAMJUDGE-Delivery`.
Delivery is retried up to 3 times when your endpoint does not answer with 2xx.

The `webhook_url` request is signed with a server secret that is not shown to customers, the same as the per-job
`webhook_url` ([Webhooks and jobs](https://docs.askaniela.com/guide/webhooks.md#webhook)). To verify the signature, register an
[organization webhook](https://docs.askaniela.com/guide/developer-portal.md#organization-webhooks) with the `labels.finished` event. It receives
the same event for every batch of the organization (or of the endpoint's project), signed with the endpoint's
signing secret (`whsec_…`, shown on the endpoint page):

```json
{"event": "labels.finished", "data": {"id": "lbl_...:labels.finished", "run": {"id": "lbl_...", "status": "done", "total": 1000, ...}}}
```

`data.id` is the same for every repeat of one batch, so deduplicate on it. The signature check is the same as for
other organization webhooks: HMAC-SHA256 of `timestamp + "." + raw body` with the endpoint secret. You can use the
organization webhook alone and skip `webhook_url`.

## Check your fixes (recheck)

Changed a page so that it fits its intended category better? Check only this page again:

```bash
curl -X POST https://api.askaniela.com/v1/labels/lbl_.../items/0/recheck \
  -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"targets": {"iab": "229", "google": "/Health/Nutrition"}}'
```

- `{id}` and `{index}` are the run and the item of the first check. `POST /v1/labels` returns `run_id` for this; in a
  batch, `index` is the item's position. A recheck's own `lbl_...` id works too (it points to the same page).
- An empty body fetches the URL again. To check a draft before publishing, send its `html` (or `text`). An item that
  was checked from `text` or `html` needs the new version in the body, because we do not keep your input.
- The answer comes in the same response: `revision` (number, `status` `done` or `failed`, labels) and `compare`
  (per taxonomy: main category before and after, the deepest confident level, and with `targets` where your intended
  category is now: `main`, `branch`, `other` or `absent`, with its strength 0-100). A failed recheck (e.g. the page
  did not load) costs nothing and the previous result stays current.
- The previous result does not change. `GET .../revisions` lists every check of the page (`rev` 0 = the first one)
  and compares the first with the latest. `classifier_changed: true` means the classifier was updated between the
  two checks, so part of the difference may come from that.
- Price: the first recheck of each page is free; later ones cost the normal price per check (see below).
  `next_check_free` and `next_check_max_usd` in `revisions` tell you what the next one costs at most.
- Limits: one recheck of a page at a time (`409 page_check_running`), at least 60 seconds between rechecks of
  one page (`429 recheck_cooldown`, `Retry-After`), 20 rechecks of one page per day (`429 recheck_daily_limit`).

## Instructions for an AI agent

`GET .../agent.md?iab=<id>&google=<path>&lang=en|pl` returns a Markdown file for an AI agent that edits the page:
what the classifier shows, which topics from other branches compete with your intended category, and steps to make
the main topic clear, with rules for safe work (backups, drafts, no publishing without a person, no keywords added
only for the classifier). It is built from the latest result only, without a new check, and is free. Without
`iab`/`google` the agent first agrees the intended category with you. The pack ends with a report template; check
the result with a recheck.

## Raw model output

`POST /v1/labels/raw` sends your text as is to the taxonomy model and returns its raw output, before we turn it into
categories with `strength`. Use it when you build your own category logic on top of the model scores. There is no
URL fetching, no HTML extraction and no stored run: send the final text you want classified.

No charge for now. Available to selected partners on request: other organizations get
`403 labels_raw_not_enabled`. [Contact us](https://askaniela.com/contact-sales) to enable it.

| Field | Required | Meaning |
|---|---|---|
| `text` | yes | Plain text or Markdown, 100 to 50,000 characters (otherwise `422`) |
| `taxonomy` | no | `iab`, `google` or `both` (default) |
| `ref` | no | Your own id, echoed back |

```bash
curl --max-time 120 https://api.askaniela.com/v1/labels/raw \
  -H "Authorization: Bearer $ANIELA_KEY" -H "Content-Type: application/json" \
  -d '{"text": "How to choose a tennis racket as a beginner? Weight, head size and balance matter most...",
       "taxonomy": "iab", "ref": "post-1842"}'
```

```json
{
  "results": {
    "iab": {
      "taxonomy": "iab",
      "primary": "539",
      "primary_path": "Sports > Tennis",
      "primary_confidence": 0.1295,
      "primary_conditional": [{"node": "483", "level": 1, "p": 0.988}, {"node": "539", "level": 2, "p": 0.4244}],
      "primary_l1": "483",
      "primary_l1_probs": {"483": 0.988, "223": 0.0041, "473": 0.0034},
      "paths": [{"node": "473", "path": "Shopping", "confidence": 0.2204},
                {"node": "539", "path": "Sports > Tennis", "confidence": 0.1295}],
      "accepted": ["483", "473", "223", "539", "551"],
      "dists": [{"level": 1, "parent": null, "choice": {"483": 0.3051, "473": 0.2204, "223": 0.2009}},
                {"level": 2, "parent": "483", "choice": {"539": 0.4244, "551": 0.4052, "none_of_these": 0.0157}}],
      "document_tokens_read": 79,
      "truncated": false
    }
  },
  "failed": [],
  "document_tokens_read": 79,
  "truncated": false,
  "ref": "post-1842"
}
```

- `results[taxonomy]` is the model answer, unchanged (distributions shortened above). `primary` is the deepest
  main node and `primary_conditional` its levels, each with the probability of that level given its parent.
  `primary_l1_probs` is the top-level distribution, `paths` the best paths with `confidence` (product from the root),
  `accepted` the nodes the model kept and `dists` the full distribution at each level it explored.
- Numbers are model scores, not calibrated probabilities. The answer may gain new fields, so ignore keys you do not
  know.
- The model reads at most the first 7,500 tokens of the text; `truncated: true` means it read only the beginning.
- A taxonomy without an answer is listed in `failed`. No answer at all: `503 labeling_unavailable`, retry later.
- Same scope (`labels:write`) and per-minute limits as `POST /v1/labels`.

## Decision model: your own questions

`POST /v1/labels/decide` asks the decision model (the model behind the Labeler) your own questions about a text and
returns its probabilities. Use it when you need a yes/no, a pick from your own list or a position on a scale, and want
to build your own logic on top of the numbers. There is no URL fetching, no HTML extraction and no stored result.

No charge for now. Available to selected partners on request (the same list as raw model output): other
organizations get `403 labels_decide_not_enabled`. [Contact us](https://askaniela.com/contact-sales) to enable it.

| Field | Required | Meaning |
|---|---|---|
| `text` | yes | Plain text or Markdown, up to 50,000 characters |
| `mode` | one question | `yes_no`, `choice` or `score` |
| `question` | one question | Your question about the text, up to 1,000 characters |
| `options` | `choice` | 2-20 distinct answer labels, up to 200 characters each |
| `levels` | no (`score`) | 2-10 distinct level names, lowest first; default = the 1-10 scale |
| `questions` | several questions | 1-20 questions keyed by your own names, each with `mode`, `question`, `options` / `levels` |
| `ref` | no | Your own id, echoed back |

Send either `question` + `mode` (the answer comes back under the key `answer`) or `questions`. Several questions
about one text in one call are faster than separate calls: the model reads the text once.

### Yes or no

```bash
curl --max-time 120 https://api.askaniela.com/v1/labels/decide \
  -H "Authorization: Bearer $ANIELA_KEY" -H "Content-Type: application/json" \
  -d '{"text": "How to choose a tennis racket as a beginner? Weight, head size and balance matter most...",
       "mode": "yes_no", "question": "Does this page sell products?", "ref": "post-1842"}'
```

```json
{"answers": {"answer": {"mode": "yes_no", "yes": 0.7042}},
 "document_tokens_read": 50, "truncated": false, "input_tokens": 56, "ref": "post-1842"}
```

### Choice from your options

```bash
curl --max-time 120 https://api.askaniela.com/v1/labels/decide \
  -H "Authorization: Bearer $ANIELA_KEY" -H "Content-Type: application/json" \
  -d '{"text": "How to choose a tennis racket as a beginner? Weight, head size and balance matter most...",
       "mode": "choice", "question": "What is the main topic of the text?",
       "options": ["Sports", "Food", "Finance", "Travel"]}'
```

```json
{"answers": {"answer": {"mode": "choice", "pick": "Sports",
   "probs": {"Sports": 0.99993, "Food": 0.00002, "Finance": 0.00002, "Travel": 0.00002}}},
 "document_tokens_read": 50, "truncated": false, "input_tokens": 63}
```

### Score on a scale

```bash
curl --max-time 120 https://api.askaniela.com/v1/labels/decide \
  -H "Authorization: Bearer $ANIELA_KEY" -H "Content-Type: application/json" \
  -d '{"text": "How to choose a tennis racket as a beginner? Weight, head size and balance matter most...",
       "mode": "score", "question": "How commercial is the text?",
       "levels": ["not commercial", "somewhat commercial", "very commercial"]}'
```

```json
{"answers": {"answer": {"mode": "score", "pick": "not commercial", "score": 1.328,
   "dist": [0.8104, 0.0513, 0.1383],
   "levels": ["not commercial", "somewhat commercial", "very commercial"]}},
 "document_tokens_read": 50, "truncated": false, "input_tokens": 62}
```

### Several questions at once

```bash
curl --max-time 120 https://api.askaniela.com/v1/labels/decide \
  -H "Authorization: Bearer $ANIELA_KEY" -H "Content-Type: application/json" \
  -d '{"text": "How to choose a tennis racket as a beginner? Weight, head size and balance matter most...", "ref": "post-1842",
       "questions": {
         "sells": {"mode": "yes_no", "question": "Does this page sell products?"},
         "topic": {"mode": "choice", "question": "What is the main topic of the text?",
                   "options": ["Sports", "Food", "Finance", "Travel"]},
         "expertise": {"mode": "score", "question": "How much expertise does the author show?"}}}'
```

```json
{"answers": {
   "sells": {"mode": "yes_no", "yes": 0.7042},
   "topic": {"mode": "choice", "pick": "Sports", "probs": {"Sports": 0.99993, "Food": 0.00002, "Finance": 0.00002, "Travel": 0.00002}},
   "expertise": {"mode": "score", "pick": "1", "score": 1.237,
     "dist": [0.9537, 0.0165, 0.0026, 0.0015, 0.0014, 0.0012, 0.0012, 0.0012, 0.0025, 0.0182],
     "levels": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]}},
 "document_tokens_read": 50, "truncated": false, "input_tokens": 98, "ref": "post-1842"}
```

- `yes` is the probability of yes. `probs` sums to 1 over your options and `pick` is the most likely one.
- `score` is the expected level: 1 = the lowest of your `levels`, N = the highest (default scale 1-10). `dist` is the
  probability of each level, lowest first, and `pick` the most likely level.
- Numbers are model scores, not calibrated probabilities. Short, concrete questions work best; test a question on a
  few texts where you know the answer before you rely on it.
- The model reads at most the first 7,500 tokens of the text; `truncated: true` means it read only the beginning.
  `document_tokens_read` = tokens of your text it read, `input_tokens` = the text once plus every question.
- A question the model cannot take (too long together with its options): `422 validation_error`. No answer:
  `503 labeling_unavailable`, retry later.
- Same scope (`labels:write`) and per-minute limits as `POST /v1/labels`; each question counts as one item.

## Price per check

You pay per check. The price depends on how much text we read, how many taxonomies you ask for and whether we
fetch the page. Single calls and batches cost the same. The price has three parts, always shown separately:

- **Labeling**: $0.03 per 1 million document tokens for each taxonomy (`model_usd`).
- **Page fetch**: $0.0015 per URL we fetch, only for `url` (`fetch_usd`).
- **JavaScript rendering**: $0.006 per page, only when you ask for it and the page was rendered (`render_usd`).

Typical prices per 1000 checks with one taxonomy:

| Text length | Labeling | Page fetch (`url` only) | Total, text you send (`document`) | Total, URL we fetch (`url`) |
|---|---|---|---|---|
| short (~1,500 characters) | $0.015 | $1.50 | $0.015 | $1.515 |
| typical (~6,000 characters) | $0.06 | $1.50 | $0.06 | $1.56 |
| long (~20,000 characters and more) | $0.225 | $1.50 | $0.225 | $1.725 |

- Two taxonomies double the label part. The fetch fee for a URL is paid once.
- JavaScript rendering adds $6 per 1000 checks, only when you ask for it and the page was really rendered.
  A page that blocks plain fetching fails without charge, retry it with `render_js: true` if you need it.
- Failed checks and failed taxonomies cost nothing.
- For a batch we hold the maximum price of every item (`price_usd`) and show `estimated_usd` for typical pages.
  You pay the actual price, the rest comes back when the batch finishes.

Ask for a free estimate before a large order:

```bash
curl --max-time 300 https://api.askaniela.com/v1/labels/estimate \
  -H "Authorization: Bearer $ANIELA_KEY" -H "Content-Type: application/json" \
  -d '{"checks": 50000, "taxonomies": ["iab"], "variant": "document", "avg_chars": 4000}'
```

The answer has `estimated_usd` and `price_per_check_usd` (each with `low`, `typical`, `high`), the same split into
labeling (`model_usd`, `model_per_check_usd`), page fetch (`fetch_usd`, `fetch_per_check_usd`) and rendering
(`render_usd`, `render_per_check_usd`), the `rates` behind them, `hold_usd` and
`per_1000_checks`, a table for short, typical and long texts keyed by number of taxonomies. Instead of
`avg_chars` you can send up to 20 sample texts in `samples`. They are measured and not stored.
More on balance and limits: [Billing](https://docs.askaniela.com/guide/billing.md).

## Text length and languages

- We read up to about 20,000 characters of each document. Longer texts are cut and only the first part is
  labelled, so put the main content first. The price never goes above the "long" row in the table.
- Best quality: English, German and Polish (tested). Also supported: French, Dutch, Spanish, Japanese, Italian,
  Portuguese, Russian, Romanian, Swedish, Czech, Korean, Turkish and Finnish. Category names in the response
  are always in English, whatever the language of the text.

## Response time

Time grows with text length and is longer for `google` than for `iab`:

| Text | `iab` | `google` |
|---|---|---|
| typical (~6,000 characters) | under 1 s | about 2 s |
| long (~20,000 characters) | about 3 s | up to 10 s |

With a URL add the time to fetch the page (usually 1-5 s, more with `render_js`). When many requests are queued a single call
can take a few minutes: set your client timeout to at least 300 s. For thousands of items use batches and wait for the webhook.

## Good practice

- Send plain text in `text`, not HTML: markup, menus and footers in `text` make the result worse and cost more.
  If you have the page HTML, send it in `html` (we extract the main content, no fetch fee) or send the `url`.
- Send at least about 600 characters of main content. Below that the result has `low_content: true`; below
  100 characters the check fails with `status: error` and is not charged; a longer
  text beyond the main content does not make them better.
- Do not paste a URL into `text`. A URL as text has almost no content to label.
- Use batches for volume and a webhook instead of tight polling.
- Ask only for the taxonomies you need. The second one doubles the label price.
- Use `ref` to match results with your own records, and `Idempotency-Key` for safe retries.

## Limits and errors

Per minute: 60 requests to `/v1/labels*` per API key, 300 per organization, and 10,000 checks per
organization (a batch counts all its items). Above that you get `429` with code `labels_rate_limited` and a
`Retry-After` header. Wait that many seconds and retry.

| Status | Code | When |
|---|---|---|
| 400 | `invalid_url` | `POST /v1/labels`: the URL is not a public `http(s)` address. In a batch the item gets `error_code: invalid_url` instead |
| 400 | `invalid_webhook_url` | `webhook_url` is not a public https address |
| 422 | `validation_error` | `POST /v1/labels`: not exactly one of `text`, `html` and `url`, text or html too long. Both: unknown taxonomy; batch: `items` not a list, empty or more than 1000 items (bad single items do not reject a batch) |
| 403 | `insufficient_scope` | The key lacks `labels:write` or `labels:read` |
| 403 | `labels_raw_not_enabled` | `POST /v1/labels/raw` is not enabled for your organization (on request) |
| 403 | `labels_decide_not_enabled` | `POST /v1/labels/decide` is not enabled for your organization (on request) |
| 404 | `label_batch_not_found` | Unknown batch id, or a batch from another organization |
| 409 | `label_batch_running` | CSV requested before the batch finished |
| 400 | `recheck_input_required` | Recheck of an item checked from `text` or `html` without a new version in the body |
| 404 | `page_not_found` | Recheck, revisions or agent pack: no such item, or a run from another organization |
| 409 | `page_not_recheckable` | Recheck while the first check is still running, or of a cancelled item or a batch item rejected as invalid |
| 409 | `page_check_running` | This page is being checked again right now |
| 429 | `recheck_cooldown` | Less than 60 seconds since the last recheck of this page. Header `Retry-After` |
| 429 | `recheck_daily_limit` | 20 rechecks of this page today. Start a new check with `POST /v1/labels` |
| 429 | `labels_rate_limited` | Per-minute limit, see above. Header `Retry-After` |
| 429 | `quota_exceeded` | Not enough balance, or a spending limit reached ([Billing](https://docs.askaniela.com/guide/billing.md)) |
| 503 | `labeling_unavailable` | The Labeler is temporarily unavailable. Nothing was charged, retry later |

A page that cannot be fetched is not an HTTP error: you get `200` with `status: "error"`, the reason in
`error` and `charged_usd: 0`. In a batch an invalid item is reported the same way, with an `error_code`. All error codes: [Errors](https://docs.askaniela.com/reference/errors.md).
