# API reference

> Every endpoint of the Cases API, its authentication and its errors.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://cases.docs.sypnia.com/api/

For agents: Base https://cases.api.sypnia.com/v1 (self-hosted: your host /v1). Contract: spec/openapi.yaml of the sypnia-cases repository. Auth: Authorization: Bearer <token> (session JWT, OAuth token, PAT `syp_pat_…` checked at the issuer's userinfo and kept a minute, or a Cases project token `syp_cpt_…` for one map); a key-bound token (CLI login, agent session) comes as Authorization: DPoP <token> with its DPoP proof. In Sypnia Cloud the server calls the Data control plane as Authorization: Service <shared key> + x-sypnia-user of the person it verified (every token kind works, DPoP-bound included; the control plane accepts it only on GET /v1/me, GET /v1/projects/{ref}, PUT|DELETE /v1/projects/{ref}/cases-map and the linked project's sql/v1/schema and sql/v1/query, and checks the person's role); the control plane calls Cases the same way to forward a map uploaded to Data. Self-hosted without CASES_SERVICE_KEY, the caller's own token is presented, so a DPoP-bound session cannot read other products. Scopes cases:read, cases:write, cases:approve, cases:operate, cases:* (only enforced on a token that carries a cases: scope; any cases: scope also reads; a plain session is decided by its role). Roles: owner, editor, approver, reviewer (plain level only). Resources: me, workspaces and members, maps (PATCH name, required_approvals, repository), versions, diff, export (members), Data and Telemetry links, uploads, cases (search, get, links, comments), navigation, places, find, event graph, deliveries and dead letters (members; replay and drop need cases:operate), proposals (list, get, open, approve, reviewers, close, comments), checks (run, last), project tokens, audit. Lists answer { items, next_cursor } with limit (≤ 200) and cursor. Errors JSON {error:{code,message,errors?}}: 401 unauthenticated, 403 not_allowed, 404 not_found (also when you may not see it), 409 version_conflict | conflict | no_app_database | no_runtime, 422 invalid_map (errors[]) | invalid_input, 429 rate_limited (Retry-After; 600 a minute per credential by default), 503 unavailable. Run-time endpoints of external starts live on the app itself: POST /hooks/<case-id> (200 { ok, outcome, data }; 202 { run_id } with respond: accepted; 401 bad signature or case key; 422 invalid input or a declared failure; 500 with a reference; a resend with the same idempotency key waits for the first and gets its answer, header idempotent-replayed).

**Base address:** `https://cases.api.sypnia.com/v1` in Sypnia Cloud; `https://<your host>/v1` when you run the server. The whole API is also written as an OpenAPI 3.1 file, `spec/openapi.yaml` in the Cases repository, which the server's tests keep equal to its routes.

## Authentication

Send a token in the `Authorization` header:

| Token                                                         | Header                                                                       | Notes                                                                                                                                        |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| A Sypnia session or OAuth token                               | `Authorization: Bearer <token>`                                              | signed by the sign-in service (Sypnia's, or the issuer your server trusts)                                                                   |
| A personal access token, `syp_pat_…`                          | `Authorization: Bearer syp_pat_…`                                            | checked at the issuer's user endpoint and kept a minute; its scopes come from that answer                                                    |
| A session bound to a key: the CLI's `login`, an agent session | `Authorization: DPoP <token>` and a `DPoP` proof for this method and address | sent as Bearer, it is refused, so a copied token is useless                                                                                  |
| A Cases project token, `syp_cpt_…`                            | `Authorization: Bearer syp_cpt_…`                                            | one map only; acts as an editor and never approves ([Project tokens](#project-tokens))                                                       |
| A call between Sypnia Cloud products                          | `Authorization: Service <key>` and `x-sypnia-user`                           | only Sypnia Data's control plane, with the key the two share, on behalf of a person it verified (it forwards maps uploaded to Data this way) |

**Scopes:** `cases:read`, `cases:write` (drafts and proposals), `cases:approve`, `cases:operate` (send dead letters again, or drop them), and `cases:*` for all of them. They limit a token that carries at least one `cases:` scope; any `cases:` scope also reads. A plain session carries none, so what it may do is decided by the person's role alone.

**Roles**, per workspace: owner, editor, approver, reviewer ([Who can do what](https://cases.docs.sypnia.com/contract/versions-and-reviews#who-can-do-what)). Reviewers read the plain level only: no tables, no code, no production data. `operate` is for owners, editors and approvers. In Sypnia Cloud a workspace is a Sypnia organization, and its roles map onto these ([Security](https://cases.docs.sypnia.com/security)).

In Sypnia Cloud, the server reads your organization's roles, your Data project and its deliveries on your behalf. It calls Sypnia Data's control plane with a key the two services share, `Authorization: Service <key>` with the id of the person it verified (`x-sypnia-user`), so every kind of token works here, sessions bound to a key included. The control plane takes such a call only on the routes Cases needs (who you are, the Data project, its link to the map, its schema and the SQL that reads deliveries), and still checks your role in the Data project. A server you run yourself without `CASES_SERVICE_KEY` presents your own token to the other product instead, as a Bearer token; a session bound to a key cannot be presented, since it can be used only at the address it was made for.

**Lists** answer `{ items, next_cursor }`. Pass `limit` (at most 200, 50 by default) and, for the next page, `cursor` with the last `next_cursor`.

## Me and workspaces

### Who am I`GET /v1/me` \[Engine, Cloud]Who the token is (`user_id`, `email`, `name`, `kind`: account or project), its scopes, the directory (`self` or `sypnia`) and the workspaces with your role. For a project token, its map.**Authentication:** any token
### List workspaces`GET /v1/workspaces` \[Engine, Cloud]The caller's workspaces and their roles.**Authentication:** any token
### Create a workspace`POST /v1/workspaces` \[Engine]`{ name, slug? }`; you become its owner. In Sypnia Cloud a workspace is a Sypnia organization, so this answers 422.**Authentication:** cases:write
### Members`GET /v1/workspaces/{ws}/members` \[Engine, Cloud]Members, reviewers and open invitations.**Authentication:** cases:read
### Invite someone`POST /v1/workspaces/{ws}/members` \[Engine, Cloud]`{ email, role }`. Someone who already signed in is added at once; anyone else when they first sign in. In Sypnia Cloud only reviewers are invited here: members are managed in the organization.**Authentication:** cases:write, owners
### Change a role`PATCH /v1/workspaces/{ws}/members/{user}` \[Engine]`{ role }`.**Authentication:** cases:write, owners
### Remove a member`DELETE /v1/workspaces/{ws}/members/{user}` \[Engine, Cloud]Removes a member or a reviewer.**Authentication:** owners, or yourself

## Maps and versions

### List maps`GET /v1/maps` \[Engine, Cloud]The maps of the caller's workspaces (a project token: its own map); `?workspace=` for one.**Authentication:** cases:read
### Create a map`POST /v1/maps` \[Engine, Cloud]A Cases project: one app's map, with version 1. `{ name, slug?, workspace?, files?, data_project? }`: from a name, or from the files of the format (`files: [{ path, content }]`); `data_project` links it at once, both ways. Without `workspace`, your only workspace.**Authentication:** cases:write
### Get a map`GET /v1/maps/{map}` \[Engine, Cloud]The latest approved version; `?version=4` for another one; `?draft=1` applies your own draft and open proposals, oldest first, on top of the latest version; `?level=plain|working|technical`.**Authentication:** cases:read
### Change a map`PATCH /v1/maps/{map}` \[Engine, Cloud]`{ name?, required_approvals?, repository? }`. `required_approvals` is `{ count }` (or a number): how many approvals a proposal needs, 1 by default.**Authentication:** cases:write, owners
### List versions`GET /v1/maps/{map}/versions` \[Engine, Cloud]Every version, newest first, with its author, approvers, date and summary.**Authentication:** cases:read
### Diff two versions`GET /v1/maps/{map}/diff?from=3&to=4` \[Engine, Cloud]Cases added, removed and changed, field by field; without `to`, the latest. Reviewers do not see technical fields.**Authentication:** cases:read
### Export`GET /v1/maps/{map}/export?format=files` \[Engine, Cloud]The map as the files of the format (a zip of `cases/map.yaml`, `cases/navigation.yaml` and `cases/<area>/<id>.case.yaml`, each starting with its `$schema` line), the default; or `format=json`. `?version=` for another version.**Authentication:** cases:read, members
### Audit`GET /v1/maps/{map}/audit` \[Engine, Cloud]Every change to the map, newest first.**Authentication:** cases:write, owners

## Links

### Link a Data project`PUT /v1/maps/{map}/data-project` \[Cloud]`{ data_project: "<ref>" }`. Checks with your token that you can open the Data project, then stores the link on both sides; the answer's `reverse_link` says whether the Data side took it. A Data project links to one map (409 otherwise). `DELETE` unlinks.**Authentication:** cases:write
### Link a Telemetry project`PUT /v1/maps/{map}/telemetry` \[Engine, Cloud]`{ project, token, api? }`: a Telemetry read token for this map, kept encrypted and used to read each case's production health. `DELETE` unlinks.**Authentication:** cases:write, owners
### Upload a map from code`POST /v1/maps/{map}/uploads` \[Engine, Cloud]The output of `npx @sypnia/cases map --json`, the document `map --upload` sends, or `{ files }`. It becomes a **draft proposal** of what the code owns (each case's tables and allowed actors; a skeleton for a use case the map does not have) and never changes an approved version. With a code side, the check runs too ([From code](https://cases.docs.sypnia.com/format/from-code)).**Authentication:** cases:write

## Cases

### Search cases`GET /v1/maps/{map}/cases` \[Engine, Cloud]Cases matching words (`q`), an `actor`, a `table` (members only) or a `status`; `?version=`, `?limit=`.**Authentication:** cases:read
### Get a case`GET /v1/maps/{map}/cases/{case}` \[Engine, Cloud]One case; `?level=plain|working|technical`, `?version=`.**Authentication:** cases:read
### Links of a case`GET /v1/maps/{map}/cases/{case}/links` \[Cloud]Tables and their policies (the linked Data project), production health (Telemetry), commits and pull requests (Git), agent tasks (Agent), each read as you within 2 seconds; one that does not answer is `not_available` ([Links](https://cases.docs.sypnia.com/links)).**Authentication:** cases:read, members
### Comments on a case`GET /v1/maps/{map}/cases/{case}/comments` \[Engine, Cloud]The comments on a case outside any proposal.**Authentication:** cases:read
### Comment on a case`POST /v1/maps/{map}/cases/{case}/comments` \[Engine, Cloud]`{ body, field? }`. Reviewers comment too.**Authentication:** cases:read

## Navigation and events

### Navigation tree`GET /v1/maps/{map}/navigation` \[Engine, Cloud]Roots, places with their paths, shortcuts and the cases on each place, and the `in_app` cases with no place; `?root=shop`, `?version=4`. With Telemetry linked, each place carries its findings.**Authentication:** cases:read

### One place`GET /v1/maps/{map}/places/{place}` \[Engine, Cloud]The place, its path, its route and permission, the actionable that opens it, its shortcuts and its cases.**Authentication:** cases:read

### Where is it?`GET /v1/maps/{map}/find?q=` \[Engine, Cloud]From words, a case id or a route, the best places with their path, route and cases, and, for members, the files behind them: the case files and the code files of the last upload.**Authentication:** cases:read

### Event graph`GET /v1/maps/{map}/events` \[Engine, Cloud]Every case with the outcomes it emits and listens to, public and internal outcomes per area, cycles and bounded loops; `?from=<event name>` follows one chain.**Authentication:** cases:read

## Deliveries and dead letters

These read your app's database, where the runtime keeps them: on a self-hosted server, the database in `CASES_APP_DATABASE_URL`; in Sypnia Cloud, the map's linked Data project, with your token (so a Data viewer cannot replay). Members only; reviewers see none of it. Without an app database: 409 `no_app_database`; with one where no area service has started: 409 `no_runtime`.

### Deliveries`GET /v1/maps/{map}/listeners/{listener}/deliveries` \[Engine, Cloud]Recent deliveries to one listening case: event id, state (`pending`, `running`, `done`, `dead`), attempts, wait, last error, trace; `?state=`. The listener is a case of the latest version that starts on an event.**Authentication:** cases:read, members

### Dead letters`GET /v1/maps/{map}/dead-letters` \[Engine, Cloud]Every listener with dead letters and how many; `?listener=` adds that listener's dead letters with their errors and traces.**Authentication:** cases:read, members

### Send dead letters again`POST /v1/maps/{map}/listeners/{listener}/dead-letters/replay` \[Engine, Cloud]`{ events?: [id] }`, all of them when left out. Safe to repeat: a listener ignores an event it already handled. Kept in the audit.**Authentication:** cases:operate

### Drop a dead letter`DELETE /v1/maps/{map}/listeners/{listener}/dead-letters/{event}` \[Engine, Cloud]`{ reason }` (in the body or the query), required; kept in the audit and on the delivery.**Authentication:** cases:operate

## Proposals and comments

### List proposals`GET /v1/maps/{map}/proposals` \[Engine, Cloud]`?status=draft|open|merged|closed`.**Authentication:** cases:read
### Open a proposal`POST /v1/maps/{map}/proposals` \[Engine, Cloud]`{ title, reason?, changes: [{ op: add|change|retire, case }], map?, navigation?, reviewers? }`. A `change` replaces only the fields it gives (`null` removes one); `retire` keeps the case with `status: retired`; `map` and `navigation` bring a new `map.yaml` or `navigation.yaml`; `reviewers` asks for reviews at once. The changes are validated against the latest version: what they would break answers 422 `invalid_map` with `errors[]` ([Versions and reviews](https://cases.docs.sypnia.com/contract/versions-and-reviews)).**Authentication:** cases:write
### Get a proposal`GET /v1/proposals/{id}` \[Engine, Cloud]The proposal, its review state (approvals, required reviewers, what is missing) and its diff.**Authentication:** cases:read
### Ask for reviews`POST /v1/proposals/{id}/reviewers` \[Engine, Cloud]`{ reviewers: [email], required? }` (required by default). Each one is named on the proposal, invited to the workspace as a reviewer when they are not a member, and gets an e-mail. A draft becomes open.**Authentication:** cases:write
### Approve`POST /v1/proposals/{id}/approve` \[Engine, Cloud]Owners, approvers and the reviewers named on the proposal. When every required approval is in, one transaction creates the new version and marks the proposal merged.**Authentication:** cases:approve
### Close`POST /v1/proposals/{id}/close` \[Engine, Cloud]Closes a proposal without merging it: its author, owners and approvers.**Authentication:** cases:write
### Comments on a proposal`GET /v1/proposals/{id}/comments` \[Engine, Cloud]Every comment on the proposal and on its cases.**Authentication:** cases:read
### Comment`POST /v1/proposals/{id}/comments` \[Engine, Cloud]`{ body, case?, field? }`: on the proposal, or on one case of it. Reviewers comment too.**Authentication:** cases:read

## Checks

### Run the check`POST /v1/maps/{map}/checks` \[Engine, Cloud]Body: the code side (`useCases` and `app` from `cases map --json`, `{ code }`, or the document `map --upload` sends), or `caseIds` alone (from commit trailers: the map is checked by itself and an id it does not have is reported as `unmapped`); optional `contract`, `version`. Returns the findings, as `cases check --json`, and keeps the last result per map and version.**Authentication:** cases:read, members
### The last check`GET /v1/maps/{map}/checks` \[Engine, Cloud]The last result: version, findings, summary, who ran it and when.**Authentication:** cases:read, members

## Project tokens

A project token lets MCP clients and CI work on one map without a person's session. It acts as an editor of that map with `cases:read cases:write` (and `cases:operate` when you give it), and never approves. It is `syp_cpt_` followed by 40 characters, shown once, and kept only as a SHA-256 hash and its last 4 characters.

### List project tokens`GET /v1/maps/{map}/tokens` \[Engine, Cloud]Name, scopes, last 4 characters, last use, expiry; never the tokens themselves.**Authentication:** cases:write, owners
### Create a project token`POST /v1/maps/{map}/tokens` \[Engine, Cloud]`{ name, scopes?, expires_at? }`; `scopes` defaults to `cases:read cases:write`, and `cases:approve` is refused. The answer carries the token once.**Authentication:** cases:write, owners
### Revoke a project token`DELETE /v1/maps/{map}/tokens/{id}` \[Engine, Cloud]It stops working at once.**Authentication:** cases:write, owners

## Errors

Errors are JSON: `{ "error": { "code", "message", "errors"? } }`.

| Status | Code                            | When                                                                                                                   |
| ------ | ------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| 401    | `unauthenticated`               | no token, it expired, or a key-bound token came without its DPoP proof; `WWW-Authenticate` names the resource metadata |
| 403    | `not_allowed`                   | your role or the token's scopes cannot do it (e.g. approve)                                                            |
| 404    | `not_found`                     | it does not exist, or you may not see it (so a map's existence does not leak)                                          |
| 409    | `version_conflict`              | another approval won the race for the version, or the proposal touches a case that changed since its base; rebase it   |
| 409    | `conflict`                      | already merged or closed, a slug already taken, a Data project already linked to another map                           |
| 409    | `no_app_database`, `no_runtime` | deliveries need the app's database, or no area service has started on it                                               |
| 422    | `invalid_map`                   | the files or the proposal do not validate; `errors[]` says where                                                       |
| 422    | `invalid_input`                 | the request is not valid; the message says which field                                                                 |
| 429    | `rate_limited`                  | too many requests (600 a minute per credential by default); `Retry-After` says when to try again                       |
| 503    | `unavailable`                   | the database or another Sypnia product did not answer; nothing was changed, try again                                  |

## The endpoints of `external` starts

These live on **your app's** address, not on the Cases API: the runtime serves one for every case that starts `external` ([How a case starts](https://cases.docs.sypnia.com/map/starts#external)).

### Start an external case`POST /hooks/{case}` \[Engine, Cloud]The body is the case's `input`. Optional header `Idempotency-Key` for `api` starts.**Authentication:** the case's signature, or its case key syp_rck\_…

| Status | When                                                                                                                                                                |
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `200`  | `respond: outcome`, and the case ended in an outcome: `{ ok: true, outcome, data }`                                                                                 |
| `202`  | `respond: accepted`: `{ run_id }`; the case runs from its queue                                                                                                     |
| `401`  | the signature or the key does not check                                                                                                                             |
| `422`  | the input does not match (`invalid_input`, with the field), or, with `respond: outcome`, the case ended in a declared failure: `{ ok: false, outcome, tell, data }` |
| `500`  | an error nobody declared; the body carries a `reference`, the run's id, to find it in Telemetry                                                                     |

A resend with an idempotency key answers the first response again, with the header `idempotent-replayed: true`, and runs nothing. A resend that arrives while the first is still running waits for it and gets the same answer.
