# AuraOS plugin API

Plugins are apps that track into AuraOS: a music practice app logging sessions, a reading app logging pages, a script importing a fitness export. What a plugin sends lands in the person's time log like anything they log themselves, so it counts toward their habits, skill levels and classes, and Claude sees it too.

This guide is complete: a developer, or an AI assistant building a plugin, needs nothing else. The machine-readable version is the OpenAPI document at [https://auraos.app/api/v1/openapi.json](https://auraos.app/api/v1/openapi.json), and this page as plain Markdown is at [https://auraos.app/developers/guide.md](https://auraos.app/developers/guide.md).

## How it fits together

- **Activities** are the kinds of thing your plugin tracks, e.g. `sound-design`, `mixing`, `ear-training`. You declare them; you never need to know the person's habits or skills.
- **The person decides where each activity counts.** The first time one appears, AuraOS asks them: it can check off a habit, belong to a project, and train skills, stats or classes by a share. Until they choose, your entries are kept and simply wait; they count from the moment the activity is mapped.
- **Entries** are time: an activity, a start (or a day) and a length in minutes. Only *growth* and *work* time earns XP.
- **Counts** are numbers beside time: tracks finished, pages read, a best BPM.
- **Your ids.** Every entry and count carries an id you choose. Sending the same id again updates it instead of adding another, so retries are always safe.
- **Versions.** Every entry and count has a `version` that goes up with each change, wherever it was made: your plugin, the app, Claude or another plugin. Send it back to make sure you don't overwrite a newer edit.
- **The changes feed** tells you everything that changed since you last asked, including edits and deletions made in AuraOS, so your plugin can stay in sync both ways.

## Quick start

1. In AuraOS, open **Settings → Developer** and choose **Register an app**. A name is enough for now.
2. Choose **New token**, keep the permissions `activity` and `summary`, and copy the token (it starts with `aura_pat_` and is shown once).
3. Try it:

```bash
export AURAOS_TOKEN=aura_pat_...

# Who am I?
curl https://auraos.app/api/v1/me -H "Authorization: Bearer $AURAOS_TOKEN"

# Declare what you track (safe to send every time your app starts)
curl -X PUT https://auraos.app/api/v1/activities \
  -H "Authorization: Bearer $AURAOS_TOKEN" -H "Content-Type: application/json" \
  -d '{"activities":[{"key":"sound-design","label":"Sound design","kind":"growth","unit":"patches"}]}'

# Log a session
curl -X POST https://auraos.app/api/v1/entries \
  -H "Authorization: Bearer $AURAOS_TOKEN" -H "Content-Type: application/json" \
  -d '{"entries":[{"id":"session-8f2c","activity":"sound-design","startedAt":"2026-11-09T21:10:00+01:00","durationMinutes":45,"note":"Resampled the pad for Track 4"}]}'

# What has it added up to?
curl https://auraos.app/api/v1/summary -H "Authorization: Bearer $AURAOS_TOKEN"
```

4. Open AuraOS: **Settings → Connected apps** shows your app and its activity, waiting for you to choose where it counts.

A personal token acts as you, for your app. Use one for your own tools and scripts. Anything other people will use must sign them in with OAuth (below), so each person connects their own account and can disconnect it.

## Authentication

Every request sends a token in the `Authorization` header:

```
Authorization: Bearer <token>
```

The API never reads cookies. Tokens are:

| Prefix | What | Lifetime |
|---|---|---|
| `aura_pat_` | Personal token, made in Settings → Developer | 30 days, 90 days, a year or never, as chosen |
| `aura_at_` | OAuth access token | 1 hour |
| `aura_rt_` | OAuth refresh token (never sent to the API, only to the token endpoint) | 60 days, renewed on every use |

### Scopes

| Scope | Lets the plugin |
|---|---|
| `activity` | Log time and counts for its own activities, and change or delete what it logged |
| `summary` | See the levels, XP and habits its activities feed |
| `record:read` | Read your whole time log, including time from the app and other apps |
| `record:write` | Change or delete any entry in your time log |

Ask for the fewest you need; most plugins want `activity summary`. A plugin can always read and change what it wrote itself; `record:read` and `record:write` reach the rest of the person's time log.

### OAuth 2.1 (for apps other people use)

AuraOS is the authorization server. Plugins are public clients: there is no client secret, and **PKCE (S256) is required**. Your client id is your app's id from Settings → Developer (`app_…`), and every redirect URI must be registered there exactly.

Allowed redirect URIs: `https://` anywhere; `http://` only on `localhost`, `127.0.0.1` or `[::1]` (any port you register); or your app's own scheme in reverse-domain form, e.g. `com.example.studio:/callback`, for desktop and mobile apps.

**1. Send the person to the consent screen.** Make a random `code_verifier` (43–128 characters of `A–Z a–z 0–9 - . _ ~`), its `code_challenge` = base64url(SHA-256(verifier)) without padding, and a random `state`.

```
https://auraos.app/oauth/authorize
  ?response_type=code
  &client_id=app_XXXXXXXXXXXXXXXX
  &redirect_uri=https%3A%2F%2Fexample.com%2Fcallback
  &scope=activity%20summary
  &state=RANDOM_STATE
  &code_challenge=CHALLENGE
  &code_challenge_method=S256
```

They sign in if needed, see your app's name and exactly what it asks for, and choose Allow or Cancel.

**2. They come back** to `redirect_uri?code=…&state=…` (or `?error=access_denied&state=…`). Check `state` matches. The code works once, for 5 minutes.

**3. Exchange the code** (form-encoded or JSON):

```bash
curl -X POST https://auraos.app/api/oauth/token \
  -d grant_type=authorization_code \
  -d code=aura_code_... \
  -d redirect_uri=https://example.com/callback \
  -d client_id=app_XXXXXXXXXXXXXXXX \
  -d code_verifier=THE_VERIFIER
```

```json
{ "access_token": "aura_at_...", "token_type": "Bearer", "expires_in": 3600,
  "refresh_token": "aura_rt_...", "scope": "activity summary" }
```

**4. Refresh** before or when the access token expires (a `401` with `invalid_token`):

```bash
curl -X POST https://auraos.app/api/oauth/token \
  -d grant_type=refresh_token -d refresh_token=aura_rt_... -d client_id=app_XXXXXXXXXXXXXXXX
```

You get a **new refresh token every time; store it and drop the old one.** The old one stops working. Sending an old refresh token again more than a few seconds later looks like theft, so AuraOS signs that session out and the person has to connect again. If two parts of your app might refresh at once, make them share one refresh.

**5. Sign out** by revoking the refresh token (it takes its access tokens with it):

```bash
curl -X POST https://auraos.app/api/oauth/revoke -d token=aura_rt_...
```

The person can also disconnect your app any time in **Settings → Connected apps**; after that every token fails with `401`. Discovery metadata (RFC 8414) is at `https://auraos.app/.well-known/oauth-authorization-server`.

## Conventions

- **Base URL:** `https://auraos.app/api/v1`. Send and receive JSON (`Content-Type: application/json`), at most 1 MB per request.
- **Errors** always look like this, with a stable `code` to branch on and a `message` written for people:

```json
{ "error": { "code": "validation_failed", "message": "Some fields are missing or invalid.",
             "details": [{ "path": "entries[0].durationMinutes", "message": "Too big: expected number to be <=1440" }] } }
```

| Status | code | Meaning |
|---|---|---|
| 400 | `validation_failed`, `invalid_json`, `invalid_request`, `invalid_cursor`, `unknown_activity` | Fix the request; `details` says where |
| 401 | `invalid_token` | Missing, expired or revoked token: refresh, or connect again |
| 403 | `insufficient_scope`, `forbidden` | The token may not do this |
| 404 | `not_found` | No such item (or not yours) |
| 409 | `version_mismatch` | Changed since you last saw it; `details.current` is how it is now |
| 410 | `cursor_expired` | Your changes cursor is over 90 days old: sync from the start |
| 413 | `payload_too_large` | Over 1 MB: send fewer items per request |
| 415 | `unsupported_media_type` | Send JSON |
| 429 | `rate_limited` | Wait `Retry-After` seconds |
| 500 | `internal` | Our fault: retry with backoff |

- **Rate limit:** 300 requests a minute per connection (`X-RateLimit-Remaining` tells you what's left). The token endpoint allows 30 a minute per address. Batch your writes: up to 500 items a request.
- **Dry runs:** add `?dryRun=true` to any write to check it without saving anything. Useful while you build against a real account.
- **Your ids:** 1–128 letters, digits, `.`, `_`, `:` or `-`. Activity keys: 1–64 lowercase letters, digits, `.`, `_` or `-`.
- **Time and habit days.** Send real instants with an offset (`2026-11-09T21:10:00+01:00` or `…Z`), never local times without one. AuraOS files each entry under the habit day it **started** on, on the person's own clock: with their day starting at 4am (the default; `/me` tells you theirs), a session at 00:30 counts for the day before, exactly like the app's own timer. When you only know the day, send `date` (`YYYY-MM-DD`) instead. Nothing may be more than a day in the future, or before 2000. One entry is at most 1440 minutes.
- **Versions and conflicts.** Reads return `version` (and an `ETag` header for single items). To change something only if nobody else has since, send `If-Match: "<version>"` on PATCH and DELETE, or `expectedVersion` per item in a batch (`0` means "only if it doesn't exist yet"). Without them, your write simply wins.

## Endpoints

### GET /me

Who the token acts for. Any scope.

```json
{ "user": { "id": "a per-connection id" }, "app": { "id": "app_…", "name": "Studio Practice" },
  "scopes": ["activity", "summary"], "timeZone": "Europe/Amsterdam", "dayStartHour": 4, "today": "2026-11-09" }
```

`user.id` is stable for this person and your app, but different for every app, so apps can't match people up. `timeZone` can be null if the person's device never reported one.

### GET /activities · PUT /activities

`PUT` declares your activities (scope `activity`): new keys are added, known ones get your new label, description, kind and unit. Send your full list on every start; it's idempotent. Keys you leave out are kept. Up to 50 per request and 200 per app.

```json
{ "activities": [
  { "key": "sound-design", "label": "Sound design", "description": "Designing patches and textures", "kind": "growth", "unit": "patches" },
  { "key": "mixing", "label": "Mixing", "kind": "work" }
] }
```

| Field | | |
|---|---|---|
| `key` | required | Your stable key |
| `label` | required | 1–60 characters, what people see |
| `description` | optional | Up to 300 characters, shown when they choose where it counts |
| `kind` | optional | `growth` (default), `work`, `maintenance`, `rest` or `drain` |
| `unit` | optional | The default unit of its counts |

Both return `{ "activities": [{ "key", "label", "description", "kind", "unit", "mapped" }] }`. `mapped` is false until the person has chosen where it counts.

### POST /entries

Creates or updates up to 500 entries by your ids (scope `activity`). **Sending an item replaces it:** optional fields you leave out go back to their defaults.

```json
{ "entries": [
  { "id": "session-8f2c", "activity": "sound-design", "startedAt": "2026-11-09T21:10:00+01:00", "durationMinutes": 45,
    "title": "Pad resampling", "note": "For Track 4", "details": { "project": "Track 4", "bpm": 128 }, "expectedVersion": 0 },
  { "id": "session-8f2d", "activity": "mixing", "date": "2026-11-08", "durationMinutes": 30 }
] }
```

| Field | | |
|---|---|---|
| `id` | required | Your id |
| `activity` | required | One of your activity keys |
| `startedAt` *or* `date` | one required | An instant with offset, or a habit day |
| `durationMinutes` | required | Whole minutes, 1–1440 |
| `title` | optional | Shown in the time log; defaults to the activity's label |
| `note` | optional | Up to 1000 characters |
| `kind` | optional | Defaults to the activity's kind |
| `details` | optional | Any JSON object up to 4 KB, kept and shown, never interpreted |
| `expectedVersion` | optional | Write only if it's at this version (0: only if new) |

Every item gets its own result, in order, and one bad item never stops the rest. The response is `200` even when some items failed, so check each `status`:

```json
{ "dryRun": false, "results": [
  { "id": "session-8f2c", "status": "created", "entry": { "…": "the entry as saved" } },
  { "id": "session-8f2d", "status": "invalid", "error": { "code": "unknown_activity", "message": "No activity \"mixing\". Declare it first with PUT /api/v1/activities." } }
] }
```

`status` is `created`, `updated`, `unchanged` (nothing differed), `conflict` (`expectedVersion` didn't match; `entry` is how it is now) or `invalid` (see `error`).

An entry looks like this:

```json
{ "id": "session-8f2c", "auraId": "6f1c…", "app": "Studio Practice", "activity": "sound-design",
  "date": "2026-11-09", "start": "21:10", "durationMinutes": 45, "title": "Pad resampling",
  "note": "For Track 4", "kind": "growth", "details": { "project": "Track 4", "bpm": 128 },
  "version": 1, "createdAt": "2026-11-09T20:56:02.114Z", "updatedAt": "2026-11-09T20:56:02.114Z" }
```

`start` is the local time on the person's clock. `id` is null on entries that aren't yours (made in AuraOS or by another app, readable with `record:read`).

When an activity counts as a habit, a new entry also checks that habit off for its day (if it isn't marked already).

### GET /entries

Your entries in a range of habit days, oldest first: `?from=2026-11-01&to=2026-11-30` (both required, at most 366 days apart). Optional: `activity=<key>`, `limit` (1–1000, default 500), `cursor` (from the previous page's `next`), and `all=true` for every entry in the person's log (needs `record:read`).

```json
{ "entries": [ { "…": "…" } ], "next": "cursor for the next page, or null" }
```

### GET · PATCH · DELETE /entries/{id}

`{id}` is your id. To reach an entry that isn't yours, use `aura:<auraId>` (reading needs `record:read`, changing needs `record:write`).

- `GET` returns the entry with an `ETag`.
- `PATCH` changes only the fields you send: `activity`, `startedAt` or `date`, `durationMinutes`, `title`, `note`, `kind`, `details` (`activity` and `details` only on your own entries). Send `null` to clear `note` or `details`. Returns the entry.
- `DELETE` returns `204`.

Both take `If-Match: "<version>"` and answer `409 version_mismatch` if it has changed since.

### Counts: POST /counts · GET /counts · GET · PATCH · DELETE /counts/{id}

The same as entries, for numbers (scope `activity`):

```json
{ "counts": [ { "id": "track-4-finished", "activity": "sound-design", "value": 1, "unit": "tracks", "at": "2026-11-09T23:40:00+01:00" } ] }
```

| Field | | |
|---|---|---|
| `id`, `activity` | required | As for entries |
| `value` | required | Any number |
| `unit` | optional | Defaults to the activity's unit |
| `at` *or* `date` | optional | When; now if neither |
| `note`, `details`, `expectedVersion` | optional | As for entries |

Counts appear in the summary. Only the app that made a count can change it.

### GET /changes

Everything that changed since your cursor, oldest first: your entries and counts (or, with `?all=true` and `record:read`, every entry in the log), whoever changed them, including deletions.

```json
{ "changes": [
    { "type": "entry", "op": "upsert", "id": "session-8f2c", "auraId": "6f1c…", "entry": { "…": "…", "version": 3 } },
    { "type": "entry", "op": "delete", "id": "session-77aa", "auraId": "91be…" }
  ],
  "cursor": "opaque", "hasMore": false }
```

Start without a cursor for a full sync. Keep calling with the returned `cursor` while `hasMore` is true, and save the last cursor for next time. The same change can come twice, so keep the highest `version` you've seen of each item. Deletions are remembered for 90 days; an older cursor gets `410 cursor_expired`, and you sync from the start.

### GET /summary

What your activities have added up to (scope `summary`):

```json
{ "today": "2026-11-09",
  "activities": [ {
    "key": "sound-design", "label": "Sound design", "mapped": true,
    "minutes": { "today": 45, "last7Days": 210, "last30Days": 760, "allTime": 5400 }, "sessions": 96,
    "counts": { "unit": "patches", "today": 1, "last7Days": 4, "last30Days": 11, "allTime": 52 },
    "habit": { "name": "Make music", "doneToday": true },
    "feeds": [ { "type": "skill", "name": "Sound design", "share": 100, "level": 9, "title": "Apprentice", "xpMinutes": 5460, "progress": 0.53 } ]
  } ] }
```

`feeds` lists the skills, stats (`attribute`) and classes (`identity`) the activity trains, with the person's current level in each. Levels go by hours practised: level² hours reaches a level, so level 10 is 100 hours.

## Keeping in sync: the recipe

1. **On start:** `PUT /activities` with your full list.
2. **When something happens:** save it locally with your own id and push it with `POST /entries` (batch whatever's queued, up to 500). Retry on network errors, `429` and `5xx` with backoff; your ids make retries safe.
3. **To pull:** call `GET /changes` with your saved cursor until `hasMore` is false. For each `upsert`, overwrite your copy if its `version` is higher than yours. For each `delete`, remove it locally. Save the cursor.
4. **Don't undo the person's edits.** If they change or delete one of your entries in AuraOS, the feed tells you. Apply that before pushing again; otherwise your next push of the same id puts your old version back (and re-creates a deleted entry). For extra safety, send `expectedVersion` with the version you last saw and handle `conflict` results by taking theirs.

## Example client (TypeScript)

Runs in Node 18+ or a browser. Replace the token with your OAuth access token in an app other people use.

```ts
const API = 'https://auraos.app/api/v1';
const TOKEN = process.env.AURAOS_TOKEN!;

const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

async function call<T>(path: string, init: RequestInit = {}): Promise<T> {
  for (let attempt = 0; ; attempt++) {
    const res = await fetch(API + path, {
      ...init,
      headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json', ...init.headers },
    });
    if ((res.status === 429 || res.status >= 500) && attempt < 4) {
      await sleep(Number(res.headers.get('Retry-After')) * 1000 || 2 ** attempt * 1000);
      continue;
    }
    const body = res.status === 204 ? null : await res.json();
    if (!res.ok) throw Object.assign(new Error(body.error.message), { status: res.status, code: body.error.code, body });
    return body as T;
  }
}

// 1. On start: what this app tracks.
await call('/activities', {
  method: 'PUT',
  body: JSON.stringify({ activities: [{ key: 'sound-design', label: 'Sound design', kind: 'growth' }] }),
});

// 2. A finished session.
const { results } = await call<{ results: { id: string; status: string; error?: { message: string } }[] }>('/entries', {
  method: 'POST',
  body: JSON.stringify({
    entries: [{ id: 'session-8f2c', activity: 'sound-design', startedAt: new Date(Date.now() - 45 * 60_000).toISOString(), durationMinutes: 45 }],
  }),
});
for (const r of results) if (r.status === 'invalid') console.warn(r.id, r.error?.message);

// 3. Pull what changed in AuraOS (save the cursor between runs).
let cursor: string | null = null;
for (;;) {
  const page: { changes: { op: string; id: string | null; entry?: { version: number } }[]; cursor: string; hasMore: boolean } = await call(
    `/changes${cursor ? `?cursor=${encodeURIComponent(cursor)}` : ''}`
  );
  for (const c of page.changes) console.log(c.op, c.id, c.entry?.version); // apply to your local store
  cursor = page.cursor;
  if (!page.hasMore) break;
}
```

## Security checklist

- Never put a personal token in an app you give to other people, or in code you publish. Use OAuth, so each person signs in themselves.
- Store tokens where your platform keeps secrets (the OS keychain, encrypted storage, a server-side session), never in plain files or URLs.
- Always use PKCE and check `state` on the way back.
- Ask for the fewest scopes you need.
- Treat `details` as data you show, not code: AuraOS never runs or renders it as HTML, and neither should you.
