# API reference

> The Learn API: addresses, authentication, errors and limits.

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

For agents: Learn API at https://learn.api.sypnia.com/v1 (Cloud) or <engine>/v1. Auth: Authorization: Bearer <Sypnia session token | personal access token | engine root token>. Every record belongs to a person; no app secret keys. Scopes for PATs: learn (own lessons, exercises, progress, explain), read (courses), admin (publish/remove courses; org owners/admins in Cloud). Agent tokens (OAuth clients acting for a person) can do learner actions except questions, done, progress deletion, level, publishing → 403 person_required. Error shape {error {code, message}}. Codes: 400 invalid_request/invalid_lesson, 401 unauthorized, 402 insufficient_credits, 403 forbidden/person_required, 404 not_found/lesson_not_found/project_not_found, 409 exercise_exists/check_running, 413 too_large, 422 no_match (uses selector found nothing and the sample is off)/repository_unreachable, 429 rate_limited (retry-after), 503 runner_unavailable.

API: `https://learn.api.sypnia.com/v1` **\[Cloud]**, or your engine's address followed by `/v1` **\[Engine]**.

## Authentication

`Authorization: Bearer <token>`. Every record in Learn belongs to a person, so there are no secret keys for apps. The token is one of:

| Token                   | Who                                  | Can                                                                                                                           |
| ----------------------- | ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------- |
| your Sypnia session     | you, in App or a Sypnia command line | everything you can do                                                                                                         |
| a personal access token | you, from a script                   | its scopes: `learn` (your lessons, exercises, progress, explanations), `read` (courses), `admin` (publish and remove courses) |
| an agent's token        | an agent acting for you              | learner actions, except those reserved to people                                                                              |
| the engine's root token | the engine's operator **\[Engine]**  | everything, on that engine                                                                                                    |

**Reserved to people**: answering questions, deleting progress, changing the level and publishing courses. An agent's token gets `403 person_required`. No one can mark a lesson as done by hand: only passing checks do.

## Errors

```json
{ "error": { "code": "check_running", "message": "The checks of this exercise are already running. Wait for them, or follow them at GET /v1/exercises/ex_7Hq2/checks." } }
```

| Status | Codes                                                |
| ------ | ---------------------------------------------------- |
| 400    | `invalid_request`, `invalid_lesson`                  |
| 401    | `unauthorized`                                       |
| 402    | `insufficient_credits`                               |
| 403    | `forbidden`, `person_required`                       |
| 404    | `not_found`, `lesson_not_found`, `project_not_found` |
| 409    | `exercise_exists`, `check_running`                   |
| 413    | `too_large`                                          |
| 422    | `no_match`, `repository_unreachable`                 |
| 429    | `rate_limited` (with `retry-after`)                  |
| 503    | `runner_unavailable`                                 |

A failed check is not an error: `POST /exercises/{id}/check` answers `202`, and the result says which checks failed.

Limits are in [Limits](https://learn.docs.sypnia.com/reference/limits).

- [Endpoints](/api/endpoints/): Courses, lessons, exercises and checks, progress, explanations, offers and settings.
