> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> API keys, scopes and rate limits, managing keys through the API, and the request log.

All API requests require a bearer token in the `Authorization` header. You can generate API keys from the [API Keys](https://insightchain.ai/dashboard/api-keys) page of the app.

```text theme={null}
Authorization: Bearer YOUR_API_KEY
```

A live key starts with `ic_live_` and works on your data. A test key starts with `ic_test_` and reaches only your [sandbox](/docs/sandbox.md). A key can carry an expiry (`expires_at`); past it the key answers `401` `api_key_expired`. Keys can also be created, rotated and revoked [through the API](#api-keys-by-api).

Every endpoint requires an API key, except public passport resolution (see [Product passports](/docs/passports.md)). A request without one is rejected with `401`.

## Scopes

Each key carries the scopes chosen when it was created. Every route names the scope it needs. `execute` includes `read`; no other scope includes another, so a key for the full API holds `execute` and `ingest`, and `approve` only when it must decide orders or manage webhooks. `keys` manages keys through the API and nothing else.

Since 2026-11-21 the decisions of Passports need `execute` where they took `ingest`; keys that existed then, in organizations with the module, had `execute` added.

| Scope | For | What it allows |
| - | - | - |
| `read` | reads | Every `GET` route except the key routes (`keys`) and the webhook routes (`approve`), plus the trade calculators, forecast check and explanations. |
| `ingest` | data in | Push data: records, supplier invoices, sensor events and competitor data (`/v1/ingest/...`) and passport content. Does not include `read`, and makes no decision. |
| `execute` | act | Includes `read`. Every decision: draft and cancel orders, set a recommendation's status, acknowledge alerts, start a connector sync, publish passports and confirm origin evidence. A decision is made for the key's creator, who must still be a member. |
| `approve` | decide | Approve, reject, run and verify orders, and manage webhooks, acting as the key's creator, who must be an organization admin. Only an admin can put it on a key; no other scope includes it, and it includes no other. |
| `keys` | manage keys | List, create, change, rotate and revoke the API keys of the key's own environment. Only an admin can put it on a key, and the key's creator must still be an organization admin. It can put on a key only scopes it holds itself. No other scope includes it, and it includes no other. |

A route outside the key's scope answers `403` with code `scope_missing`.

## Rate limits

* **Per key:** 120 requests per minute, and a daily limit (1,000 by default; an organization admin can set up to 10,000) that resets at 00:00 UTC.
* **On every answer:** `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` (seconds) for the minute window; `X-RateLimit-Limit-Day` and `X-RateLimit-Remaining-Day` for the daily limit.
* **On a 429:** `Retry-After` is the real wait in seconds: the rest of the minute window, or the time to 00:00 UTC for the daily limit.
* **Routes that use AI** (an explanation's narrative, reading a document) also draw on a daily budget per organization, reported in `X-Model-Budget-Remaining`.
* **Unauthenticated requests:** a per-address flood limit applies to them. A request with a valid key is limited by its key alone.

The headers, request ids, safe retries and lists are described in full under [Conventions](/docs/conventions.md).

## API keys by API

Manage keys through the API: list them, create one for a job, change its scopes, limit or expiry, rotate its secret and revoke it. Every route needs a key with the `keys` scope, which only an organization admin can put on a key, and the key's creator must still be an organization admin. No key has the scope until you add it. The same can be done on the [API Keys](https://insightchain.ai/dashboard/api-keys) page.

| Method | Path | What it does |
| - | - | - |
| `GET` | `/v1/api_keys` | The API keys of your organization (never a secret). A test key lists the sandbox's keys. |
| `POST` | `/v1/api_keys` | Create a key; its secret is in this response only. |
| `GET` | `/v1/api_keys/:id` | One key (never its secret). |
| `PATCH` | `/v1/api_keys/:id` | Change a key's name, scopes, expiry, daily limit or active flag. |
| `DELETE` | `/v1/api_keys/:id` | Revoke a key: it stops working at once. |
| `POST` | `/v1/api_keys/:id/rotate` | A new secret for a key, in this response only. |

### Rules

* **Scopes:** a key can put on a key only scopes it holds itself. A key that holds a scope the caller lacks can only be disabled or revoked by it, never rotated, re-enabled or changed. Either refusal is a `403` `scope_not_held`.
* **Environment:** a key works inside its own organization and environment. A test key manages the sandbox's keys, a live key the live ones (`environment_mismatch` otherwise).
* **Secrets:** a key's secret is in the answer that creates or rotates it, as `secret`, and nowhere else. To tell keys apart, every key shows `key_hint`: the prefix and the last four characters.
* **Expiry:** `expires_at` is a timestamp up to five years ahead, or `null` for none. Keys created before 2026-11-21 do not expire.
* **Rotation:** `overlap_seconds` (0 to 604,800, seven days) keeps the old secret working until the window ends. The default is 0: the old secret stops at once.
* **Last used:** `last_used_at` is kept to the minute.
* **Apps connected with your account** are not keys: these routes do not list them, and they have no secret to rotate.
* **Audit:** every change is in your audit trail, with the key that made it. At most 30 changes per caller per hour.

### Example: create a key, then rotate it with a 24-hour overlap

```bash theme={null}
curl -X POST "https://api.insightchain.ai/v1/api_keys" \
  -H "Authorization: Bearer YOUR_KEYS_KEY" -H "Content-Type: application/json" \
  -d '{ "name": "reporting", "scopes": ["read"], "expires_at": "2027-01-01T00:00:00Z" }'
# → 201 { "key": { "id": "…", "name": "reporting", "environment": "live", "scopes": ["read"],
#                  "key_hint": "ic_live_...a1B2", "expires_at": "2027-01-01T00:00:00.000Z", "last_used_at": null, … },
#         "secret": "ic_live_…" }
# The secret is shown here and on rotate only. Store it; no route returns it again.

curl -X POST "https://api.insightchain.ai/v1/api_keys/KEY_ID/rotate" \
  -H "Authorization: Bearer YOUR_KEYS_KEY" -H "Content-Type: application/json" \
  -d '{ "overlap_seconds": 86400 }'
# → { "key": { … }, "secret": "ic_live_…", "previous_secret_expires_at": "…" }
```

## Request log and usage

Two reads: `GET /v1/request_logs` lists the calls made with your organization's keys in the last 30 days, and `GET /v1/usage` says how much of each key's daily quota is used. Both take the `read` scope. The API requests page of the app shows the same data.

### What an entry holds

Our `request_id`, your own `client_request_id` when you sent an `X-Request-ID` header, the key, the method, the route as a template (`/recommendations/{id}`), the status, the error code, the latency and whether the call came over `http` or `mcp`. Never a body, a query value or an id from the path. A call made without a valid key is not logged. An entry appears a moment after its answer has left.

Filter with `request_id`, `client_request_id`, `api_key_id`, `status`, `outcome`, `method`, and a time range with `since` and `until`. Page with `limit` and `cursor`.

### Example: find a call by your own id

```bash theme={null}
curl "https://api.insightchain.ai/v1/recommendations?limit=1" \
  -H "Authorization: Bearer YOUR_API_KEY" -H "X-Request-ID: checkout-7f3a"
# the answer carries X-Request-ID (ours) and X-Client-Request-ID: checkout-7f3a

curl "https://api.insightchain.ai/v1/request_logs?client_request_id=checkout-7f3a" \
  -H "Authorization: Bearer YOUR_API_KEY"
# → { "object": "list", "data": [ { "request_id": "…", "client_request_id": "checkout-7f3a", "api_key_id": "…",
#       "method": "GET", "route": "/recommendations", "status": 200, "error_code": null,
#       "latency_ms": 84, "via": "http", "created_at": "…" } ], "has_more": false, "next_cursor": null }
```

### Example: usage

```bash theme={null}
curl "https://api.insightchain.ai/v1/usage?days=7" \
  -H "Authorization: Bearer YOUR_API_KEY"
# → { "keys":  [ { "id": "…", "name": "reporting", "daily_limit": 1000, "requests_today": 212, "remaining_today": 788, "last_used_at": "…", … } ],
#     "daily": [ { "day": "2026-11-21", "api_key_id": "…", "requests": 212, "client_errors": 3, "rate_limited": 0, "server_errors": 0, … } ], … }
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.