# API basics

> Keys, answers with a sentence, errors and limits.

Everything a person can do in Okidoki, an agent or a script can do through the API. It is a plain JSON API at `https://okidoki.sh/api/v1`, and every answer comes with one sentence that can be repeated as it is.

## Your first call

Make a key under **Settings → Connections → Your AI agent** (see [API keys](https://docs.okidoki.sh/api/keys)), then:

```bash
curl -H "Authorization: Bearer oks_..." "https://okidoki.sh/api/v1/sites/mysite.com/summary?period=7d"
```

```json
{
  "message": "312 visitors came in the last 7 days, 18% more than the 7 days before.",
  "data": { "...": "the numbers" }
}
```

`GET https://okidoki.sh/api/v1` without a key lists every endpoint, report, period and filter. The whole API is also described as OpenAPI 3.1 at [`https://okidoki.sh/api/v1/openapi.json`](https://okidoki.sh/api/v1/openapi.json): load it in Postman, Insomnia or Scalar, or generate a client from it.

## Signing in

Send a key in the `Authorization` header:

```text
Authorization: Bearer oks_...
```

| Who | Token | Can do |
| --- | --- | --- |
| Agents and scripts | API key, `oks_...` | What the key allows: one site or the whole account, read-only or read and change |
| People in the dashboard | Session, after signing in on okidoki.sh | Everything in their account |
| Anyone with a share link | The share token, in the address | Read the shared site's reports |

## Answers

Every successful answer is JSON with two fields:

| Field | What it is |
| --- | --- |
| `message` | One plain sentence, written to be repeated to a person as it is |
| `data` | The numbers and details, for programs |

Agents should repeat `message` rather than describe `data` in their own words. That way what they say always comes from Okidoki.

## Errors

Errors have a status code, a stable `code` for programs and a message that says what to do, in words that can be passed on:

```json
{
  "error": {
    "code": "site_not_found",
    "message": "There is no site \"mysite.co\" in this account. List your sites with GET /api/v1/sites.",
    "status": 404,
    "request_id": "req_6f1c0a9e2b7d4c3a8e5f1b2c",
    "docs": "https://docs.okidoki.sh/api#errors"
  }
}
```

Programs should branch on `code`, never on the message, which may be reworded. Every answer, also a good one, has an `X-Request-Id` header: quote it when you write to us about a call.

| Status | Meaning | Common codes |
| --- | --- | --- |
| `400` | Something in the request is wrong | `bad_domain`, `bad_period`, `bad_filter`, `bad_goal`, `bad_json`, `bad_cursor`, `bad_idempotency_key` |
| `401` | No key, or the key does not work | `unauthorized` |
| `402` | Needs Plus, or the plan has no room | `plus_required`, `site_limit`, `history_limit` |
| `403` | The key may not do this, or the domain is blocked | `read_only_key`, `site_key`, `owner_only`, `blocked` |
| `404` | No such site, goal, link or endpoint | `site_not_found`, `webhook_not_found`, `not_found` |
| `405` | The endpoint exists, but not with this method. The `Allow` header lists the ones it takes | `method_not_allowed` |
| `409` | It already exists, a limit is reached, or the same Idempotency-Key is still running | `site_exists`, `goal_exists`, `goal_limit`, `account_exists`, `idempotency_in_progress` |
| `413` | The body is too large | `too_large` |
| `422` | The Idempotency-Key was used for another request | `idempotency_key_reused` |
| `429` | Too many calls; wait `Retry-After` seconds | `rate_limited`, `agent_read_limit`, `busy` |
| `500` | Something went wrong on our side | `internal` |

## Rate limits

Two limits, both with headers so a script can pace itself:

| Limit | How much | Headers |
| --- | --- | --- |
| Burst, per key | 120 calls a minute | `RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset` (seconds), `RateLimit-Policy` |
| Report reads (questions from AI tools), per account | 20 a month on Free, 2,000 on Plus, back on the 1st (UTC) | `Okidoki-Monthly-Reads-Limit`, `Okidoki-Monthly-Reads-Remaining` |

Over a limit the answer is `429` with a `Retry-After` header in seconds. Wait that long and try again; do not retry at once in a loop. Plus has no daily limit, and the dashboard has none at all.

## Retries and Idempotency-Key

Calls that change something (`POST`, `PATCH`, `DELETE`) take an `Idempotency-Key` header: any unique string up to 255 characters, like a UUID. If the connection drops and you send the same call again with the same key within 24 hours, Okidoki does not do it twice: you get the first answer again, with `Idempotent-Replayed: true`.

```bash
curl -X POST https://okidoki.sh/api/v1/sites/mysite.com/goals \
  -H "Authorization: Bearer oks_..." -H "Content-Type: application/json" \
  -H "Idempotency-Key: 7d0c5d4e-2b1a-4c1e-9f7a-3e8b6a2c9d10" \
  -d '{"name":"Signed up","page":"/thanks"}'
```

- Use a new key for each new thing you want done. The same key with another body is `422 idempotency_key_reused`.
- Answers with a status of 500 or more are not kept, so a retry after one runs again.
- Secrets are never kept. Replaying `POST /keys` or `POST /webhooks` gives the same id, with the secret written as `[shown only in the first answer]`.
- Retry `GET` calls and `5xx` answers freely, with a growing wait (1, 2, 4 seconds…). Do not retry other `4xx` answers without changing the request.

## Pages

Lists that can grow long are paged with a cursor: [events](https://docs.okidoki.sh/api/reference#get-sites-site-events) and the [webhook delivery log](https://docs.okidoki.sh/webhooks#the-delivery-log). Ask for up to `limit` items (1 to 100), and pass `next_cursor` from the answer as `cursor` to get the next page. `has_more` is `false` and `next_cursor` is `null` on the last page.

```json
{ "message": "...", "data": { "events": ["..."], "next_cursor": "evt_1042", "has_more": true } }
```

Reports are not paged: they return the top `limit` rows (up to 100), sorted by what matters most.

## Versions

The version is in the address: `/api/v1`, and in the `Okidoki-Api-Version` header of every answer. Version 1 only grows. We add endpoints, fields, report columns, event types and error codes, but never remove or rename them, and never change what a field means. Write your code to ignore fields and event types it does not know.

If something ever has to change in a way that breaks code, it comes as `/api/v2`, and `/api/v1` keeps working for at least 12 months after we tell every account with a key by email. Endpoints on their way out answer with `Deprecation` and `Sunset` headers before then. Webhook events carry `api_version` too.

## Sites in addresses

Wherever an address has `:site`, use the site's domain, like `mysite.com`, or its id. Domains are cleaned up the same way as when you add a site, so `www.mysite.com` works too.

## Periods and filters

Reports, summaries, insights and exports take the same query parameters:

| Parameter | Values |
| --- | --- |
| `period` | `today`, `24h`, `yesterday`, `7d`, `30d`, `90d`, `month`, `last_month`, `year`, `all`, `custom`. Defaults to `7d` |
| `from`, `to` | Dates like `2026-11-01`, for `period=custom` |
| `compare` | `previous` (the default) or `year`, the same dates last year |
| `limit` | Rows per list, 1 to 100. Defaults to 10 |
| Filters | `page`, `source`, `channel`, `campaign`, `utm_source`, `utm_medium`, `country`, `region`, `device`, `browser`, `os` |

See [Periods and comparisons](https://docs.okidoki.sh/periods) and [Filters](https://docs.okidoki.sh/filters).

## Requests

- Send bodies as JSON with `Content-Type: application/json`, up to 64 KB.
- The API allows calls from any origin (CORS), so it works from a browser too. Never put a key that can change things in public code.
- Answers are never cached: `Cache-Control: no-store`.
- Times are ISO 8601 in UTC, like `2026-11-10T08:00:00.000Z`. Days in reports are the site's own days, in its time zone.
- Ids are opaque strings. Store them as they are.
- The API runs in the EU, in Stockholm.

## Plus features

Exports with a key, alerts, revenue, campaign costs, benchmarks and history older than 12 months need Plus. On Free, all your data downloads as CSV in the web app: see [Export your data](https://docs.okidoki.sh/export). When a key's account does not have it, the answer is `402` with a message saying so. See [Plans and pricing](https://docs.okidoki.sh/plans).

## Next

- [API keys](https://docs.okidoki.sh/api/keys) Make, scope and turn off keys.
- [API reference](https://docs.okidoki.sh/api/reference) Every endpoint with examples.
- [Webhooks](https://docs.okidoki.sh/webhooks) Events sent to your address, signed.
- [MCP server](https://docs.okidoki.sh/mcp) The same, as tools for AI apps.


