# API reference

> The addresses, how to authenticate, the error shape and the limits shared by every endpoint.

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

For agents: API overview: base https://<ref>.data.sypnia.com (self-hosted: your SYPNIA_DATA_PUBLIC_URL). Families: /auth/v1 (users), /auth/v1/oauth (machines), /auth/v1/admin (secret key), /rest/v1 (Data API, transactions, the OpenAPI description at /rest/v1/), /sql/v1 (SQL, transactions, migrations, schema), /mcp, /.well-known (jwks.json, oauth-authorization-server, openid-configuration, oauth-protected-resource), /health. Auth: apikey header (publishable or secret), Authorization: Bearer <access token | PAT | secret key> or DPoP <token> + DPoP proof. Errors: {"error":{"code","message","hint"}}; OAuth endpoints use RFC 6749 {error, error_description}. Rate-limited answers 429 with Retry-After. Every error code and limit: /api/errors-and-limits. The machine-readable contract is spec/openapi.yaml.

Every project has one base address: `https://<ref>.data.sypnia.com` in Sypnia Cloud, or your engine's public address.

| Prefix                                              | What                                                                                          | Page                                                                      |
| --------------------------------------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| `/auth/v1`                                          | users: sign-up, sign-in, sessions, e-mail, providers                                          | [Auth endpoints](https://data.docs.sypnia.com/api/auth-endpoints)         |
| `/auth/v1/admin`                                    | users and settings, with a secret key                                                         | [Auth endpoints](https://data.docs.sypnia.com/api/auth-endpoints)         |
| `/auth/v1/oauth`                                    | machines: tokens, device flow, registration                                                   | [OAuth endpoints](https://data.docs.sypnia.com/api/oauth-endpoints)       |
| `/rest/v1`                                          | the Data API, transactions, the API description                                               | [Data and SQL endpoints](https://data.docs.sypnia.com/api/data-endpoints) |
| `/sql/v1`                                           | SQL, transactions, migrations, schema                                                         | [Data and SQL endpoints](https://data.docs.sypnia.com/api/data-endpoints) |
| `https://mcp.data.sypnia.com` (self-hosted: `/mcp`) | the MCP server, one for every project                                                         | [MCP](https://data.docs.sypnia.com/machines/mcp)                          |
| `/.well-known/…`                                    | `jwks.json`, `oauth-authorization-server`, `openid-configuration`, `oauth-protected-resource` | [OAuth endpoints](https://data.docs.sypnia.com/api/oauth-endpoints)       |
| `/health`                                           | `200 {"status":"ok"}` when the engine and the database answer                                 | —                                                                         |
| every family                                        | error codes and limits                                                                        | [Errors and limits](https://data.docs.sypnia.com/api/errors-and-limits)   |

## Authenticating

| Header                                             | Carries                                                                                                                                                                                  |
| -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `apikey: syp_pk_…` / `syp_sk_…`                    | the project key (needed on `/auth/v1` and `/rest/v1` from apps)                                                                                                                          |
| `Authorization: Bearer <token>`                    | a user's access token, a PAT, or a secret key                                                                                                                                            |
| `Authorization: DPoP <token>` + `DPoP: <proof>`    | a DPoP-bound token                                                                                                                                                                       |
| `X-Sypnia-CSRF: <value of the sypnia-csrf cookie>` | with a cookie session (the refresh token in the `__Secure-sypnia-rt` cookie, [cross-subdomain sessions](https://data.docs.sypnia.com/auth/users-and-your-data#several-apps-one-sign-in)) |

## Errors

```json
{ "error": { "code": "invalid_credentials", "message": "Wrong e-mail or password", "hint": null } }
```

`code` is stable and in `snake_case`; `message` is for people and may change. The OAuth endpoints answer as RFC 6749 requires: `{ "error": "invalid_client", "error_description": "…" }`.

| Status   | Means                                                                                                   |
| -------- | ------------------------------------------------------------------------------------------------------- |
| 202      | an e-mail is being retried (`email_queued_retry`): not an error                                         |
| 400      | the request is malformed (`invalid_query`, `validation_failed`…)                                        |
| 401      | no valid credential (`missing_api_key`, `invalid_token`, `invalid_dpop_proof`, `secret_key_in_browser`) |
| 403      | a valid credential without the right (`insufficient_scope`, `scope_not_allowed`, `person_required`)     |
| 404      | unknown project, table or record (`unknown_project`, `table_not_found`)                                 |
| 405, 406 | a method or a schema the endpoint does not serve                                                        |
| 409      | conflict (`email_exists`, `migration_checksum_mismatch`, `expectation_failed`)                          |
| 422      | valid shape, refused content (`weak_password`, `invalid_email`)                                         |
| 429      | rate limited; `Retry-After` says when                                                                   |
| 503      | the database or a dependency is unavailable; `Retry-After`                                              |

Every code, with what to do about it, is in [Errors and limits](https://data.docs.sypnia.com/api/errors-and-limits).

## The contract

The complete, machine-readable contract is `spec/openapi.yaml` in the repository. These pages and the engine follow it.
