---
title: API
description: "The HTTP API outside programs can call: API keys, Sign in with Hindsight, your own time, and the Review API."
sidebar:
  order: 4
---

Everything here is on the server, under whatever address it runs at. For the hosted one that's `https://hindsight.mixidthesilly.dev`. Replies are JSON.

## Ways to authenticate

| What you hold | Looks like | Sent as | Good for |
|---|---|---|---|
| A website session | an encrypted `hs_session` cookie | the cookie | The dashboard itself, and managing API keys and OAuth apps. |
| An API key | `hsk_` and 64 hex characters | `Authorization: Bearer <key>` | Reading your own time. An admin can promote one to read other people's. |
| An OAuth access token | `hso_` and 64 hex characters | `Authorization: Bearer <token>` | An app a person connected to their account, with only what they allowed. |
| A device key | issued once by the device-login flow | `Authorization: Bearer <key>` | The daemon's own uploads. Not for outside use. |

Keys and tokens are stored as blake3 hashes. Nothing can show you one again after you first see it.

Errors come back as `{"error": "a sentence"}` with a fitting status: 400, 401, 403, 404, 409 or 429. On the endpoints that take a key or token, each one gets 120 requests a minute. Over that, you get a 429 with a `Retry-After` header counting seconds. The count is kept in memory, so a server restart resets it.

## Read your own time

With an API key that has `self:read`, or an OAuth token with `projects:read` or `time:read`:

| Method and path | Scope | Returns |
|---|---|---|
| `GET /api/v1/my/projects` | `self:read` or `projects:read` | Every project, all time, with first and last minute. |
| `GET /api/v1/my/time` | `self:read` or `time:read` | Totals and per-project figures for a window. |
| `GET /api/v1/my/spans` | `self:read` or `time:read` | Runs of credited minutes, per project. |
| `GET /api/v1/my/days` | `self:read` or `time:read` | Time per day or per hour. |

```bash
curl -H "Authorization: Bearer hsk_..." \
  "https://hindsight.example.com/api/v1/my/time?start=2026-11-01&end=2026-11-30&projects=hindsight"
```

These take the same query parameters as the Review API's matching endpoints, and answer in the same shapes without `user_id` and `held`. The [parameters are listed below](#query-parameters).

## Make an API key

Open Settings, then the API keys tab, on the website. Behind the button is this API, which needs the website session. A key can't make or revoke keys.

| Method and path | What it does |
|---|---|
| `GET /api/v1/api-keys` | Your keys that still work. |
| `POST /api/v1/api-keys` | Make one. The key itself is in the reply once. |
| `DELETE /api/v1/api-keys/{id}` | Revoke one. Answers 204. |

The body of `POST` is `{"name": "...", "expires_in_days": 90, "scopes": ["self:read"]}`. The name is required and up to 64 characters. `expires_in_days` is 1 to 3650, or leave it out for a key that never expires. Leave `scopes` out and you get `self:read`. You can have 20 keys at once, each with its own name.

An owner can only give a key `self:read`. These scopes exist, and an admin adds the rest by promoting the key in the review panel:

| Scope | Lets the key |
|---|---|
| `self:read` | Read your own projects, time, spans and days (`/api/v1/my/*`). |
| `users:lookup` | Find any account by email, Hack Club id, Slack id or username. |
| `review:time` | Read anyone's projects and credited time. |
| `review:timeline` | Read anyone's spans, per-day and per-hour time, and commit markers. |
| `review:flags` | See whether an account is held and how many flags it has by category. |
| `review:claims` | Freeze a ship's time into a signed claim, and read claims back. |
| `review:events` | Read anyone's event-level timeline, without any text. |

While the key's owner is on hold, the elevated scopes stop working. The key itself stays as it is.

## Sign in with Hindsight

Hindsight is also an OAuth 2.0 provider. A program site can let someone connect their Hindsight account and read the projects they pick, the same way programs read Hackatime.

### Register an app

On the website: Settings, then the OAuth apps tab. You can have 10 apps. Each one has:

- a name of up to 64 characters;
- 1 to 10 redirect URIs. They must be `https://`, or `http://` on `localhost`, `127.0.0.1` or `[::1]` while you develop. No fragment, at most 512 characters each, and the match is exact;
- an optional homepage and logo URL, and a logo picture of up to 256 KiB;
- confidential (default, with a client secret) or public (no secret, for browsers and phones, and it must use PKCE).

You get a client id (`hsc_...`) and, for a confidential app, a client secret (`hss_...`) shown once. Apps you make can ask for `profile`, `email`, `projects:read` and `time:read`.

| Scope | What the person sees on the consent page |
|---|---|
| `profile` | Your username, display name and picture |
| `email` | The one on your Hack Club account |
| `projects:read` | Their names and the total time on each |
| `time:read` | Work sessions and time per day |
| `admin` | As a Hack Club reviewer: anyone's projects, time and commits |

`admin` is not for apps people make. An admin can add it to a confidential app after verifying it, and the token then gets the review scopes the admin chose.

### The flow

Send the person to the authorize endpoint:

```text
GET /oauth/authorize
  ?client_id=hsc_...
  &redirect_uri=https://app.example.com/callback
  &response_type=code
  &scope=profile%20projects:read
  &state=...
  &code_challenge=...
  &code_challenge_method=S256
```

Leave `scope` out and you get `profile`. `code_challenge` is the base64url SHA-256 of a verifier of 43 to 128 characters. Public apps must send one. For confidential apps it's optional, but if you send one it has to be `S256`.

The person approves (or has already approved those scopes), and they come back to your redirect URI with `code` and `state`. The code works once and lasts 60 seconds. Trade it:

```bash
curl -X POST https://hindsight.example.com/oauth/token \
  -d grant_type=authorization_code \
  -d code=... \
  -d redirect_uri=https://app.example.com/callback \
  -d client_id=hsc_... \
  -d client_secret=hss_... \
  -d code_verifier=...
```

The answer has `access_token`, `token_type` (`Bearer`), `expires_in`, `refresh_token` and `scope`. Access tokens last an hour and refresh tokens 90 days. A confidential app authenticates with HTTP Basic or with `client_id` and `client_secret` in the form. A public app sends just `client_id`.

To refresh, post `grant_type=refresh_token` and the `refresh_token`. Every refresh gives you a new refresh token and retires the old one. Use an old one a second time and the server revokes the whole family, on the theory that somebody else has a copy. You can pass `scope` to ask for fewer scopes, never more.

| Method and path | What it does |
|---|---|
| `GET /oauth/authorize`, `POST /oauth/authorize` | The consent page, and the person's answer. |
| `POST /oauth/token` | Codes and refresh tokens for access tokens. |
| `POST /oauth/revoke` | Revoke a token and everything it led to. Always 200, whether or not the token was known. |
| `GET /oauth/userinfo` | Needs `profile` or `email`. Returns `sub`, and with `profile`: `id`, `username`, `preferred_username`, `name`, `picture`. With `email`: `email`. |
| `GET /.well-known/oauth-authorization-server` | Server metadata (RFC 8414) for libraries that discover endpoints. |

Adding `&test=1` to the authorize URL shows an app's maker what the consent page looks like and what the app would receive. Nothing is granted and nothing goes to the app.

## The Review API

The Review API is how programs like Sidekick check how much time went into a ship. It needs a key (or a verified admin app's token) with the right scopes, and every read of a person's data is logged for admins.

A user can be named in the path by Hindsight's own id, a Hack Club id (`ident!...`), a Slack id like `U062UG485EE`, or a username. Not by email, because addresses would end up in URLs and logs. To find someone by email, use `lookup`.

| Method and path | Scope | Returns |
|---|---|---|
| `GET /api/review/v1/check` | any key | What this key is: `kind`, `name`, `owner`, `scopes`, `expires_at`, `owner_held`, `rate_limit_per_minute`. |
| `POST /api/review/v1/users/lookup` | `users:lookup` | An account found by exactly one of `email`, `hca_id`, `slack_id` or `username` in the body. |
| `GET /api/review/v1/users/{id}/projects` | `review:time` | Every project, all time. |
| `GET /api/review/v1/users/{id}/time` | `review:time` | Totals and per-project figures for a window. |
| `GET /api/review/v1/users/{id}/spans` | `review:timeline` | Runs of credited minutes. |
| `GET /api/review/v1/users/{id}/days` | `review:timeline` | Time per day or hour. |
| `GET /api/review/v1/users/{id}/commits` | `review:timeline` | Commit markers: time, project, branch, short hash, files and lines changed, lines typed by hand, and whether an agent made it. Never a message or a diff. |
| `GET /api/review/v1/users/{id}/flags` | `review:flags` | Open and resolved flag counts by category. |
| `GET /api/review/v1/users/{id}/timeline?date=2026-11-30` | `review:events` | One UTC day of events without any text. `limit` 1 to 2000 (default 500) and `offset` page through it. |

Every answer about a person carries `user_id` and `held`. A held account is read like any other and marked `held: true`.

### Query parameters

These work on the time endpoints, here and under `/api/v1/my`.

| Parameter | Used by | Meaning |
|---|---|---|
| `start`, `end` | all windows | RFC 3339 (`2026-11-30T14:00:00Z`) or a day (`2026-11-30`). A bare `end` day includes that day. A window is at most 366 days. |
| `projects` | `time`, `days` | Comma-separated names, up to 50, each up to 100 characters. Matched ignoring case. |
| `project` | `spans`, `commits` | One project name. |
| `granularity` | `days` | `day` (default) or `hour`. |
| `tz` | `days` | An IANA zone like `Europe/Berlin`. Default `UTC`. |

Without `start`, `time` looks back 366 days and `spans`, `days` and `commits` look back 7.

A `time` answer has `start`, `end`, `rules_version`, `computed_at`, `final`, a `total` and a list of `projects`. Each carries `hands_on_s`, `watching_s`, `effort_s` (the two added up, which is what counts), `unattended_s` (shown, never counted) and `checkins`, plus how the work went: `code_by_you_pct`, `lines_typed`, `lines_not_typed`, `rework_rounds`, `failures_steered`, `ai_code_kept`, `languages` and `commits`.

`final` turns true once every one of the person's devices has an upload receipt late enough that no event can still change that window. Final answers can be cached for a day, and every `time` answer has an `ETag`, so send `If-None-Match` and you'll get a 304 when nothing changed.

### Claims

A claim freezes the time behind a ship, so a program can keep proof of what it was when it approved. It needs `review:claims`.

```bash
curl -X POST https://hindsight.example.com/api/review/v1/claims \
  -H "Authorization: Bearer hsk_..." -H "Content-Type: application/json" \
  -d '{"user": "orpheus", "external_ref": "ship-1234", "projects": ["hindsight"],
       "start": "2026-11-01", "end": "2026-11-30", "hours_claimed": 24.5}'
```

`projects`, `start` and `end` are required. `external_ref` (up to 200 characters) is your own id for the ship, and a second claim with the same one for the same person is a 409. `hours_claimed` is 0 to 10000.

The answer is 201 with the `claim`, the exact `payload` that was signed (the claim as JSON with keys sorted and no spaces), a base64 ed25519 `signature` over those bytes, and a `public_key_url`. `GET /api/review/v1/claims/{id}` reads one back and adds `still_matches`: whether working the time out again today gives the same figures.

The public key is at `GET /.well-known/hindsight-claims.pub`, as PEM.

## Other endpoints

**Public stats.** `GET /api/v1/users/{username}/stats` returns Hackatime and WakaTime-compatible stats, plus `human_seconds` (Hands-on), `ai_assisted_seconds` (Watching), `unattended_seconds` and `checkin_count`. Its `total_seconds` is the effort that counts. It takes `start_date` and `end_date` (`YYYY-MM-DD`, inclusive) and defaults to the last 7 days, 366 at most. A private profile or a held account answers 404 to everyone but its owner.

**Live updates.** `GET /ws?username=<name>` upgrades to a WebSocket. It sends `{"type":"hello"}`, then a small JSON notice each time that person's devices upload events. Leave out `username` and you get your own, if you have a session cookie.

**Health.** `GET /health` returns `{"status":"ok","version":"..."}`, or a 503 when the database is down.

**The endpoints the daemon uses**

These are for the daemon, and they can change with it. They're listed so you can read the server's logs.

| Method and path | What for |
|---|---|
| `POST /device/code`, `POST /device/token` | The device-code login. The code looks like `ABCD-EFGH`, lasts 15 minutes, and the daemon polls every 5 seconds. |
| `GET /device`, `POST /device/approve` | The page where the person approves a code. |
| `POST /api/v1/device/revoke` | A device ending its own key. |
| `GET /api/v1/batches/head` | The newest batch the server holds for this device, plus the crediting rules. |
| `POST /api/v1/batches` | Upload batches. Up to 500 batches and 50,000 events per request. The daemon aims for about 2,000 events per request. |
| `GET /api/v1/recap`, `/checkins`, `/history`, `/rollups` | What the desktop app shows. |
| `PUT /api/v1/extras` | Kept-code counts, day summaries and dashboard settings. |
| `GET`, `PUT`, `DELETE` under `/api/v1/snapshots` | Snapshot pictures, readable only by their owner. |
| `POST /api/v1/evidence/reveal` | Proving a picture you kept private matches its commitment. |
| `GET /api/v1/me`, `PATCH /api/v1/me`, `GET /api/v1/devices` | Profile and device list. |
