# Conventions

These rules hold across the whole surface. If you learn them once, you do not have to read each operation description.

## Path shape [#path-shape]

Workspace and domain are always path segments, in the same position:

```
/api/public/v1/workspaces
/api/public/v1/workspaces/{workspace_id}
/api/public/v1/domains
/api/public/v1/domains/{domain_id}
/api/public/v1/domains/{domain_id}/uptime/timeline
/api/public/v1/domains/{domain_id}/gsc/performance
```

Search Console hangs off the domain its property is linked to, rather than exposing an internal property identifier.

The dashboard's own API accumulated several path-shape inconsistencies over the years. None of them is inherited here: a frozen public contract is the wrong place to preserve drift.

## Pagination [#pagination]

Two forms. **Check which one an endpoint uses before you write the loop**, because they are not interchangeable.

### Cursor [#cursor]

This is the default, and you get it on every read of a table that receives new rows all the time. There, `LIMIT 100 OFFSET 200` returns duplicate and skipped rows when new data arrives between two pages. Both pages look correct, so a client cannot see the problem.

```json
{
  "items": [ ... ],
  "next_cursor": "eyJ0IjoxNzUw...",
  "has_more": true,
  "total": null
}
```

| Field | Meaning |
|---|---|
| `items` | The page |
| `next_cursor` | Pass back verbatim as the `cursor` query parameter |
| `has_more` | Keep paging while this is `true` |
| `total` | Present only where counting is cheap. Absent rather than wrong. |

<Callout type="warning">
  Cursors are opaque base64url. Never parse one, never construct one, never store one across a config change. A malformed cursor returns a `400` naming the parameter, not a silent restart from the beginning.
</Callout>

`limit` defaults to **50** and **clamps** at **1000**. It clamps and does not reject. An agent that asks for 5,000 rows gets 1,000 rows and a correct `has_more`. It does not get a `400` in a paging loop.

Some endpoints clamp lower than 1000, because the handler behind them has a lower limit. `/rum/pages` and `/rum/pageviews` clamp at 500. Other endpoints use other maximums. Before you hard-code a page size, check the maximum of the endpoint in the OpenAPI document. Do not expect 1000 everywhere. The published maximum is the one that the endpoint accepts.

A correct loop:

```python
cursor = None
while True:
    page = get("/domains/{id}/robots/changes", cursor=cursor, limit=200)
    for row in page["items"]:
        handle(row)
    if not page["has_more"]:
        break
    cursor = page["next_cursor"]
```

### Offset [#offset]

Some Search Console and analytics reads use `limit` and `offset`, because they read a stored result that does not change. They return `has_more`, but `next_cursor` stays empty and they do not accept a cursor. Examples:

```
GET /domains/{domain_id}/gsc/queries
GET /domains/{domain_id}/gsc/pages
GET /domains/{domain_id}/gsc/countries
GET /domains/{domain_id}/gsc/new-rankings
GET /domains/{domain_id}/gsc/reports/runs/{run_id}/rows
GET /domains/{domain_id}/analytics/reports/runs/{run_id}/rows
```

`/analytics/pages` and `/analytics/ecommerce/products` accept both forms. If you send a `cursor`, they ignore `offset`.

A client that assumes a cursor everywhere loops forever on these, because `has_more` can be `true` while `next_cursor` is empty. Branch on which fields come back, or check the OpenAPI document per endpoint.

## Time ranges [#time-ranges]

<Callout type="warning">
  Most endpoints have no `from` or `to` parameter. `GET /domains/{domain_id}/health` is an exception: it takes `from` and `to` as UTC days. Some other endpoints use `from` and `to` for other values, for example two page versions to compare. Check the parameters of each endpoint in the OpenAPI document.
</Callout>

These are the usual forms, depending on the endpoint:

| Form | Used by | Shape |
|---|---|---|
| `start_date` / `end_date` | Most endpoints with a time range | `YYYY-MM-DD` calendar dates, not timestamps |
| `period` | Many endpoints, often together with `start_date` / `end_date` | A window named rather than calculated, resolved on the server. See [Named periods](#named-periods) |
| `period_days` | Some endpoints | Integer window ending now. Usually default 30, range 1 to 365 |
| `days` | A small number of endpoints | Integer number of days. The default and the range are different for each endpoint |

The defaults are different for each endpoint, so read them. On Search Console endpoints, `end_date` is **two days ago** by default, not today. Google publishes its data about two days late. Thus a request for yesterday correctly returns nothing.

The OpenAPI document is authoritative per endpoint, and this is the parameter set most worth checking there before writing a query.

How long VitalSentinel keeps data depends on the type of data. See [Data privacy](/help/data-privacy).

### Named periods [#named-periods]

Many endpoints accept `period`, which names a reporting window instead of asking you to calculate its edges. Seven values are accepted:

| Value | Window |
|---|---|
| `last_7_days` | The 7 days ending today |
| `last_30_days` | The 30 days ending today |
| `last_90_days` | The 90 days ending today |
| `this_week` | Monday of the current week through today |
| `last_week` | The last complete Monday to Sunday week |
| `this_month` | The 1st of the current month through today, month to date |
| `last_month` | The last complete calendar month |

**`last_month` is the last complete calendar month, not the last 30 days.** These are two different questions with two different answers. A report called "last month" that sends a 30-day window can show a different figure from the calendar month.

Trailing windows remain the default on every endpoint, so a named period is opt-in. A client that never sends one behaves exactly as it did before.

You cannot use `period` together with `start_date` or `end_date`. If you send both, you get a `400`. VitalSentinel does not select one of the two windows for you, because then a report could cover days that nobody chose.

The response always shows the resolved boundaries. Thus you can label a chart with the days that VitalSentinel counted, and not with the name that you sent.

### Comparing against a previous window [#comparing-against-a-previous-window]

Five endpoints pair a comparison with `compare_mode`, which decides what "previous" means:

| Value | Baseline window |
|---|---|
| `previous_period` | The window immediately preceding yours, of equal length |
| `calendar_month` | The whole calendar month before the one your window ends in |
| `previous_year` | The same calendar dates one year earlier. Only on the three Search Console endpoints |

If you do not send `compare_mode`, it becomes `calendar_month` when `period` is a calendar month (`this_month` or `last_month`). Otherwise it becomes `previous_period`. This default is what people mean by "compared to last month": a calendar month is compared with the previous calendar month.

On the three Search Console endpoints, `compare_previous` uses the preceding window of equal length by default, and `compare_mode` changes the baseline. A `compare_start_date` and `compare_end_date` pair sets any baseline window. The pair turns the comparison on by itself and replaces `compare_mode`. Send both dates, or neither.

`compare_mode` exists on `/analytics/overview`, `/gsc/overview`, `/gsc/pages`, `/gsc/queries` and `/uptime/availability`, and nowhere else. Other endpoints that accept `compare_previous`, such as `/rum/overview` and `/rum/pages`, always compare against the immediately preceding window of equal length.

## Idempotency keys are mandatory on `run:` endpoints [#idempotency-keys-are-mandatory-on-run-endpoints]

Every `run:`-class endpoint **requires** an `Idempotency-Key` header. This is not optional polish:

```bash
curl -sS -X POST \
  "https://app.vitalsentinel.com/api/public/v1/domains/$DOMAIN_ID/reports/$TEMPLATE_ID/generate" \
  -H "Authorization: Bearer $VITALSENTINEL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: report-$(echo -n "$TEMPLATE_ID$BODY" | shasum -a 256 | cut -c1-32)" \
  -d "$BODY"
```

| Rule | Detail |
|---|---|
| Same key, same body | Replays the original response and spends nothing |
| Same key, **different** body | `409 conflict`. This is a client bug, and returning the first response to a different request would corrupt your state without an error |
| Missing key | `400 invalid-request` |
| Maximum length | 255 characters |
| Retention | 24 hours, long enough to cover re-running a failed CI job the next morning |
| Namespacing | Per credential, so two customers generating the same key never collide |

One `write:` endpoint has the same requirement. `POST /domains/{domain_id}/robots/sitemap-conflicts/recompute` uses `write:robots`, not a `run:` scope. It still rejects a call without a key, because a retry would otherwise start a second recompute of the same domain.

<Callout type="warning">
  **Derive the key from the request, not from a fresh UUID.** A UUID regenerated on each attempt defeats the entire purpose: your retry becomes a second billed run. A hash of the operation and its arguments is the right shape.
</Callout>

This matters most for automated callers. Agents and job runners retry aggressively, on a timeout, on a transport hiccup, or on their own uncertainty about whether a call succeeded. Without an idempotency key, one retried report run is billed a second time and the customer sees a credit balance they cannot account for.

## A POST does not always mean a mutation [#a-post-does-not-always-mean-a-mutation]

A handful of endpoints are POSTs that take a body and change nothing. They exist because the input does not fit in a query string: a batch of URLs to test, a candidate robots.txt to simulate.

They are recognizable three ways: they live under a `/query`-style sub-path, they require only a `read:` scope, and their OpenAPI description says so explicitly.

```
POST /domains/{domain_id}/robots/test-urls/query
POST /domains/{domain_id}/robots/simulate/query
POST /domains/{domain_id}/robots/overlapping-rules/query
POST /domains/{domain_id}/reports/data/{template_id}
```

None of these needs an `Idempotency-Key`, and none of them costs a dispatch price.

## Response headers [#response-headers]

An authenticated response carries these headers. `X-Credits-Remaining` is absent on some free routes:

| Header | Meaning |
|---|---|
| `X-Request-Id` | Quote this in any support conversation |
| `X-RateLimit-Limit` | The ceiling of whichever [bucket](/api/rate-limits) will refuse you first |
| `X-RateLimit-Remaining` | Your remaining budget in that bucket |
| `X-RateLimit-Reset` | Absolute epoch second. Sleep **until** it, not **for** it |
| `X-Credits-Cost` | What this request cost. See [API credits](/api/credits) |
| `X-Credits-Remaining` | Balance after this request, for the [workspace it was charged to](/api/credits#which-workspace-is-charged) |
| `X-Cache` | `HIT`, `MISS`, or `UNAVAILABLE`. Explains why a heavy read cost zero |

## Null is not zero [#null-is-not-zero]

Reading a response means telling three states apart: measured and zero, not measured, and not measurable. The API keeps them separate and does not show all of them as `0`. On a chart, a false zero looks the same as a real zero.

- **A metric an endpoint did not measure is `null`, never `0`.** `GET /analytics/pages?type=entry` reports entry data, so `exits` and the bounce fields come back null there rather than as zeros you might plot. The same applies to `entries` under `type=exit` and to `chain_valid` on a domain that was never scanned.
- **A percentage change with nothing to compare against is `null`,** not a fabricated `100.0` or `0.0`. That covers `visitors_change_pct` and its siblings on `/analytics/overview`, `revenue_change` and `orders_change` on `/analytics/ecommerce/overview`, and `actual_ctr` on `/gsc/ctr-benchmark`. `bounce_rate_change_pp` is a percentage-point difference. It is null when the preceding window recorded no sessions.
- **A class that was never counted is absent, not `0`.** On `GET /uptime/incidents`, an `error_class` that you send appears in `class_counts` even when its count is 0. A present `0` means none. A missing key means that the class was not counted.
- **A date on which nothing was recorded is `null`,** not a placeholder like `1970-01-01`.

## RUM is stricter here than the dashboard [#rum-is-stricter-here-than-the-dashboard]

Every RUM response on the public API is redacted unconditionally. There is no scope that widens this, and no plan that changes it.

| What | Treatment |
|---|---|
| `session_id` | **Omitted entirely** from every RUM response, not nulled |
| `url`, `referrer`, `resource_url`, `sample_url` | Query strings stripped |
| Error `message`, `stack`, `filename`, `element_id`, `element_class` | Email-shaped and long token-shaped substrings replaced with `[redacted]` |
| LCP, CLS and INP element selectors, rage-click selectors | Returned exactly as stored. Only `data-mask-selectors` on the RUM script removes them |
| Individual visitor session records | Not reachable at all |

This is why the API hides a query string that your dashboard shows. Personal data is often in the query string of an error URL. An API credential could collect it at a much larger scale than a person in the dashboard. This difference is on purpose, and the API will not become less strict.

Aggregate and page-level RUM metrics are unaffected. Everything you need to rank pages by 75th-percentile LCP, break down INP subparts, or count error groups is still there.

### An explicit `end_date` now ends the window [#an-explicit-end_date-now-ends-the-window]

A public RUM route with an explicit `end_date` once included the events of the next day. For example, `end_date=2026-07-31` counted events from August 1. That is fixed. The window ends where `end_date` says, and `window_end` in the response states the exact window.

The dashboard still adds the extra day, on purpose. Thus a dashboard figure and an API figure with the same `end_date` can differ by one day of traffic. The API reports the window that you asked for. A RUM total that you stored before this change covers one more day than its label.

## Kill switches are not deprecations [#kill-switches-are-not-deprecations]

Two `503` responses are operational levers rather than contract changes:

| Type | Meaning |
|---|---|
| `api-disabled` | The public API is temporarily off. Retry after `Retry-After`. |
| `read-only-mode` | Reads are still being served; writes and runs are temporarily disabled. |

Neither means an endpoint is going away. See [Versioning and stability](/api/versioning) for what an actual retirement looks like.

## Five habits that keep a client working [#five-habits-that-keep-a-client-working]

The [compatibility promise](/api/versioning) is written against clients that do these five things. A client that does not is not covered:

1. **Ignore unknown fields.** New fields ship inside `v1` without a version bump.
2. **Tolerate unknown enum values.** New enum members are additive.
3. **Branch on the error `type` URI**, never on the prose in `detail`.
4. **Treat cursors as opaque.**
5. **Honor `Retry-After`.**

## Related [#related]

- [API introduction](/api/introduction) - what the API covers
- [Scopes](/api/scopes) - previous step: what to ask for
- [Endpoint reference](/api/endpoints) - next step: every operation
- [Versioning and stability](/api/versioning) - the compatibility promise
- [API Credits](/api/credits) - which workspace pays for a call
