# API reference

> Each /v1 endpoint: method, path, body fields, response fields and errors.

Part of the Endor docs. Index of every page: https://endor.thetokencompany.com/llms.txt. HTML version: https://endor.thetokencompany.com/docs/api.

The machine-readable schema is at [`/v1/openapi.json`](https://api.endor.thetokencompany.com/v1/openapi.json). This page gives the same endpoints in short form.

## Conventions

- Base URL: `https://api.endor.thetokencompany.com`.
- Authentication: `Authorization: Bearer edk_...` on each request.
- Bodies are JSON. The maximum body is 64 MB for dataset uploads, 32 MB for evaluations and `forward` /
  `forward_backward` / `predict`, 8 MB for `POST /v1/corrections/batch`, and 4 MB elsewhere. `/v1/systemone` takes 1 MB plus room for its images in base64: 8 images
  of at most 5 MB each, about 54 MB in all. `Content-Encoding: gzip` is accepted (the limit applies to the inflated body).
- A decision's `state` may be at most 256 KB and each question 64 KB (as JSON); the models read at most 16,384
  tokens per question.
- Each response has an `X-Request-Id` header.
- Something unexpected or unclear? Send a [user report](#user-reports): `POST /v1/user_reports`.
- List endpoints take `limit` (1 to 1,000) and `offset`, and return `{"items": [...], "total": n}`.
- Create endpoints marked "idempotent" accept an `Idempotency-Key` header (200 characters maximum). The same key with the same body within 24 hours returns the first response.
- Names (a continuous model's `name` and `{project}`, a saved model's `name`, a dataset's `name`): `^[a-z0-9][a-z0-9._-]{0,62}$`. Continuous models and the models of custom projects share one list of names in an organization, and a name can't be a base model's name (the part of its id after `owner/`).
- Times are ISO 8601 in UTC. `?` after a field name means "optional".
- All endpoints can return `401 unauthorized`, `400 invalid_input` (a body that isn't valid JSON), `422 invalid_input` (valid JSON that doesn't fit the endpoint) and `500 internal`. The tables below give the other errors.
- An error's `param` names the field: keys with dots, list items in brackets (`rows[1].questions.urgent`, `data[0].target`).

## Decisions

### POST /v1/systemone

Body:

| Field | Type | Required | Description |
|---|---|---|---|
| `model` | string | yes | A continuous model's `<name>` (its production version, or its base model before the first version), `<name>:preview` (its newest version, while that isn't in production: otherwise `404 no_preview`) the name of a model from a custom project, in production, or a base model's `id` (`owner/model`, for example `mapika/decider-2b`). See [Model names](https://endor.thetokencompany.com/docs/decisions#model-names). |
| `state` | string, object or array | yes | The input. |
| `questions` | object | yes | 1 to 64 questions by name. Each has `type` (`noul`, `choice` or `score`), `instructions?` and `criteria?` ([data format](https://endor.thetokencompany.com/docs/data-format)). |
| `exclude_from_training` | bool | no | Keep the decision out of the continuous model's learning. Default `false`. |

Response `200`: `{"id": string, "model": string, "answers": {name: answer}, "usage": {"input_tokens": int, "output_tokens": 0}, "warnings"?: [{"code": "state_truncated", "question": string, "message": string}]}`. `warnings` is there only when there is something to say: `state_truncated` when a base model that reads the start of a long state (clef-27b, clef-flash-9b) cut it to fit `max_question_tokens` for that question. `id` is the decision's id, the same as its `X-Request-Id` header: send it as `request_id` to [correct](#corrections) the decision. `model` is what answered: a continuous model's version (`tickets:v4`, or `tickets` while it answers with its base model) or the custom project's model. Answers:

- noul: `{"type": "noul", "noul": float}` (probability of yes)
- choice: `{"type": "choice", "choice": string, "probabilities": {id: float}, "confidence": float}`
- score: `{"type": "score", "score": float, "probabilities": {id: float}, "legend": {id: any}, "confidence": float}`

Errors: `402 insufficient_balance`, `403 continuous_learning_not_enabled` (a continuous model, while continuous models are not enabled for your organization), `404 unknown_model`, `404 version_not_callable` (`<name>:v3`: only `<name>` and `<name>:preview` can be called), `404 no_preview` (`<name>:preview` while the newest version is in production), `409 model_not_in_production` (an archived model from a custom project), `409 model_not_ready`, `409 no_base_model` (a base model no longer served), `422 invalid_options`, `422 context_too_long` (a question, with the state, is longer than the base model reads: `max_question_tokens`), `429 rate_limited`, `529 overloaded`.

### GET /v1/models

The names that you can send as `model`, in the TypeSafe shape. Response `200`: `{"models": [{"name", "description", "release_date", "endor"}]}`: `<name>` for each continuous model, `<name>:preview` for each one with a preview (both only with continuous models enabled), and each model from a custom project in production. `endor` gives Endor's details, such as the base model; TypeSafe clients ignore it.

### GET /v1/base_models

The base models. Response `200`: `{"base_models": [...]}`. Each item has `id` (`owner/model`: what `model` and `base_model` take), `params` (size), `hf_repo` (the Hugging Face repository of the weights), `hf_revision` (the pinned commit), `contract` and `contract_version` (how a question becomes the model's input and how the probabilities are read), `max_options`, `max_question_tokens` (the most tokens a question may have, state included), `trainable`, `lora_targets`, `default_rank`, `max_rank`, `price_per_mtok_decide`, `price_per_mtok_decide_continuous_learning` (the price in a continuous model) and `price_per_gpu_hour`. You cannot send a base model id alone as `model`: create a continuous model on it, or train a model on it in a custom project.

## Corrections

Feedback on decisions: tell Endor whether a past decision was right. How to use it, with examples: [Give feedback on decisions](https://endor.thetokencompany.com/docs/decisions#give-feedback-on-decisions). Name the decision by the `id` of its response, as `request_id`. Free. Only continuous models learn from corrections: a correction of a decision of a custom project's model is kept, and doesn't change the model.

Correction object: `request_id`, `project` (the continuous model's name), `questions` (by name, each `{"correct", "answer", "served"}`), `comment`, `created_at`.

| Method and path | Body | Response | Errors |
|---|---|---|---|
| `POST /v1/corrections` (idempotent) | `request_id` (required), `questions` (required), `comment?` (1,000 characters maximum) | `200` correction | `404 not_found`, `422 invalid_input` (`param`: `questions.<name>` or `questions.<name>.answer`) |
| `POST /v1/corrections/batch` (idempotent) | `items` (1 to 1,000, required), each a `POST /v1/corrections` body | `200` `{"items": [correction]}`, in the order of `items` | `404 not_found` (`param`: `items[i].request_id`), `422 invalid_input` (`param`: `items[i].questions.<name>`...) |
| `GET /v1/corrections/{request_id}` | | `200` correction | `404 not_found` (also when the decision has no correction) |
| `DELETE /v1/corrections/{request_id}` | | `204` | `404 not_found` (also when there is no correction to withdraw) |

- `questions`: one or more of the decision's questions, by name, each `{"correct": true or false, "answer"?: ...}`. `answer` is one of the question's options exactly as the decision asked it (a choice's option name, `true` or `false` for a yes/no `noul`, a score's level number); with `correct: false` it must differ from what was served. Otherwise `422 invalid_input` (`param`: `questions.<name>.answer`) lists the options.
- In the response, `served` is what Endor answered and `answer` is the right answer: `served` when it was correct; else the answer sent, or the only other option of a `noul` or of a `choice` or `score` of two; else `null` (only known to be wrong).
- A decision has one correction. Sending it again replaces it whole (questions left out are no longer corrected); the same questions and comment again change nothing.
- `POST /v1/corrections/batch` checks every item first. If one fails, it keeps none.
- A decision is a `/v1/systemone` request of your organization that was answered. Endor records it a moment after the answer; a correction sent before that gets `404 not_found`.

## Continuous models

Continuous models are projects in the API: `/v1/projects`. See [Continuous models](https://endor.thetokencompany.com/docs/continuous-learning).

> **Invited organizations only.** Continuous models are only available to invited organizations (email rasmus@thetokencompany.com to ask). `GET /v1/whoami` returns `"continuous_learning": true` once yours has them. Until then, every endpoint below returns `403 continuous_learning_not_enabled`. Use [custom projects](#custom-projects) instead.

Continuous model object: `name`, `description`, `base_model`, `production` (the production version: the one `<name>` answers with; `null` before the first version, when it answers with the base model), `preview` (the newest version while it isn't in production, `<name>:preview`; `null` otherwise), `auto_promote` (each new version goes to production at once), `promoted_at` (when the production version last changed), `versions` (how many it has), `created_at`.

Version object: `name` (`v1`, `v2`, ...), `base_model`, `production`, `preview`, `accuracy` (percent) and `loss` (from the check it passed when it was trained; `null` when it had nothing to check on), `size_bytes`, `created_at`.

| Method and path | Body or query | Response | Errors |
|---|---|---|---|
| `POST /v1/projects` (idempotent) | `name` (required), `base_model` (required: an `id` from `GET /v1/base_models`, such as `mapika/decider-2b`, chosen once), `description?` | `201` continuous model | `409 conflict` (a continuous model has the name), `409 name_taken` (a saved model has it), `409 limit_reached` (5 continuous models), `422 invalid_input` (an unknown base model) |
| `GET /v1/projects` | | `200` list of continuous models | |
| `GET /v1/projects/{project}` | | `200` continuous model | `404 not_found` |
| `PATCH /v1/projects/{project}` | `description?`, `auto_promote?`; omitted fields do not change | `200` continuous model | `404 not_found`, `422 invalid_input` (`base_model`: it never changes) |
| `DELETE /v1/projects/{project}` | | `204` | `404 not_found` |
| `GET /v1/projects/{project}/versions` | | `200` list of versions, newest first | `404 not_found` |
| `POST /v1/projects/{project}/versions/{version}/promote` | | `200` continuous model | `404 not_found` (also a version the continuous model doesn't have) |
| `GET /v1/projects/{project}/versions/{version}/download` | query `include_optimizer?` (bool, default false) | `200` `{"files": [...], "expires_at"}`, as for [custom projects](#downloading-a-model) | `404 not_found`, `429 rate_limited` |
| `GET /v1/projects/{project}/learning` | | `200` `{"status", "progress", "serving", "trained_at", "trainings", "drift"}` | `404 not_found` |

- `auto_promote`: `true` promotes the preview at once and each new version after it; `false` keeps the production version until you promote one.
- Promoting a version older than the preview is a rollback: it sets `auto_promote` to `false`. Promoting the production version changes nothing.
- `learning`: `status` is `learning`, `training`, `waiting`, `up_to_date`, `out_of_credit` or `limit_reached`; `progress` the way to the next version (0 to 1); `serving` what `<name>` answers with; `trainings` the latest 50 training runs, newest first (`at`, `decisions`, `labels`, `kept`, `version`, `accuracy` (agreement with a frontier model's answers on `checked` held-back answers) with its 95% `low` and `high`, `loss`, `against`, `against_accuracy`, `against_loss`, `worse`, `held`: why a kept version stayed the preview instead of going live with auto-promote, because its agreement with the frontier model fell against the live version's or it almost stopped giving an answer the held-back decisions often have, `discarded`: why a run wasn't kept); `drift` per question, whether recent traffic moved away from what the production version was checked on (`question`, `changed`, `answer_shift` 0 to 1, `confidence_change`), reported only.

`DELETE` frees the name at once: `<name>` stops answering. Endor keeps the files for 30 days, then removes them. A continuous model always learns; keep a decision out with `exclude_from_training`.

## Custom projects

Models you train yourself in custom projects, which are custom models in the API: `/v1/custom_models` (see [Custom projects](https://endor.thetokencompany.com/docs/training)). A saved model is archived: decisions refuse it (`409 model_not_in_production`) until it is promoted to production, but it can be downloaded and evaluated.

Model object: `name` (the `model` of a decision while in production), `base_model`, `state` (`production`, `archived`, or `saving` while its `save_checkpoint` runs), `production` (the same as a bool), `promoted_at` (when it last went to production; `null` while archived), `serving` (in production: `deploying` until Endor has loaded the model onto a GPU, then `live`, or `failed` if it could not be loaded; `null` while archived), `serving_error` (why, while `serving` is `failed`), `contract`, `step`, `has_optimizer`, `size_bytes`, `training_run_id`, `parent_model` (the model its run started from), `loss` and `accuracy` (the run's `train/loss` and `train/accuracy` when it was saved; `null` when unknown), `expires_at` (archived models with a TTL only), `user_metadata`, `created_at`. While a model's `save_checkpoint` runs, `GET /v1/custom_models/{name}` returns it with `state` `saving` (it isn't listed yet), and every other call that names it gives `409 model_not_ready`. If the save fails, the model is gone.

| Method and path | Body or query | Response | Errors |
|---|---|---|---|
| `GET /v1/custom_models` | query `production?` (`true` or `false`) | `200` list: the models in production first, then the archived ones | |
| `GET /v1/custom_models/{name}` | | `200` model, also while it saves (`state` `saving`) | `404 not_found` |
| `POST /v1/custom_models/{name}/promote` | `replace?`: a model in production to archive in the same step | `200` model | `404 not_found` (also a `replace` that isn't in production), `409 production_full` (every production slot is taken; the message names the models in production) |
| `POST /v1/custom_models/{name}/demote` | | `200` model, archived | `404 not_found` |
| `PATCH /v1/custom_models/{name}` | `ttl_seconds?` (3,600 to 315,360,000, or `null` = keep) | `200` model | `404 not_found`, `409 model_in_production` (models in production never expire) |
| `GET /v1/custom_models/{name}/download` | query `include_optimizer?` (bool, default false) | `200` `{"files": [{"name", "size_bytes", "sha256"?, "url"}], "expires_at"}` | `404 not_found`, `429 rate_limited` |
| `DELETE /v1/custom_models/{name}` | | `204` | `404 not_found`, `409 model_in_production` (archive it first), `409 run_active` |

- An organization can have 3 models from custom projects in production (`max_production_models_per_org` in `GET /v1/whoami`). Email rasmus@thetokencompany.com for more.
- A promoted model can be called at once. While `serving` is `deploying`, its first decisions may take longer: they wait for the model to load. Read `GET /v1/custom_models/{name}` until `serving` is `live`. If it is `failed`, promote the model again to retry.
- Archiving takes effect at once: the next decision that names the model is refused.
- Promoting a model in production changes nothing, unless its `serving` is `failed`: then it is deployed again. Archiving an archived model changes nothing.
- Promoting a model removes its TTL (`expires_at` becomes `null`): models in production never expire. Archiving it doesn't bring the TTL back; `PATCH` `ttl_seconds` gives it a new one.
- `DELETE` frees the name at once. Endor keeps the files for 30 days, then removes them.

### Downloading a model

A custom project's model, or a continuous model's version, is a LoRA adapter (PEFT) for its `base_model`. `GET .../download` returns one link per file: `adapter_model.safetensors`, `adapter_config.json`, `endor_manifest.json`, `readout.safetensors` if the model has one, and `optimizer.pt` (Adam state, only needed to resume training) with `include_optimizer=true`. Each `url` is a plain HTTPS GET of that one file, straight from storage, served as an attachment named after the file. Send no `Authorization` header with it. The links expire after 10 minutes (`expires_at`), or when the model does if that is sooner; call the endpoint again for fresh ones. Check `size_bytes`, and `sha256` (hex) when it is given. At most 30 calls per minute per org. Links are not stored in Endor's request log. What the files contain, and what you need to run them: [Run a model outside Endor](https://endor.thetokencompany.com/docs/training#run-a-model-outside-endor).

## Datasets

Labeled decision rows of the organization, to evaluate your trained models and base models.

Dataset object: `name`, `n_rows`, `n_labelled_questions`, `question_types` (`{type: count}`), `created_at`.

| Method and path | Body | Response | Errors |
|---|---|---|---|
| `POST /v1/datasets` (idempotent) | `name` (string, required), `rows` (array of [rows](https://endor.thetokencompany.com/docs/data-format), 1 to 50,000, required) | `201` dataset | `402 insufficient_balance`, `409 conflict`, `409 limit_reached` (1,000 datasets, or 200 GB of datasets in the organization), `422 invalid_row` (`param`: `rows[i]`; the message names the field), `429 rate_limited` |
| `GET /v1/datasets` | | `200` list of datasets | |
| `GET /v1/datasets/{name}` | | `200` dataset | `404 not_found` |
| `GET /v1/datasets/{name}/rows` | query `limit`, `offset` | `200` `{"items": [row], "total": int}` | `404 not_found` |
| `DELETE /v1/datasets/{name}` | | `204` | `404 not_found` |

## Runs

A run trains a model in a custom project.

Run object: `id`, `name`, `model` (the model name a save without a name uses), `base_model`, `contract`, `lora` (`rank`, `alpha`, `seed`, `train_attn`, `train_mlp`, `train_readout`), `status` (`provisioning`, `ready`, `idle`, `closing`, `closed`, `failed`), `ready_future_id`, `step`, `total_steps`, `seconds_per_step`, `next_seq_id`, `parent_model`, `wandb`, `wandb_url`, `tags`, `config`, `code_hash`, `user_metadata`, `failure` (`{"code", "message"}` or null), `ready_at`, `closed_at`, `created_at`.

- `step`: the optimizer steps of the run's adapter. With `include_optimizer`, it counts on from the step of `from_model`. A run that ended before it ever had a GPU (`ready_at` `null`) reports 0.
- `closed_at`: when the run was closed, or when it failed.

### POST /v1/runs (idempotent)

| Field | Type | Required | Description |
|---|---|---|---|
| `base_model` | string | yes, unless `from_model` | A base model's `id` from `GET /v1/base_models`, such as `mapika/decider-2b`. |
| `model` | string | no | The model name that `save_checkpoint` saves under when it gets none. It must be free: `409 conflict` here when a saved model has it, `409 name_taken` when a continuous model does. |
| `from_model` | string | no | Start from a saved model's weights. The run trains on that model's base model; another `base_model` fails with `422 invalid_input`. |
| `include_optimizer` | bool | no | With `from_model`: also load the optimizer state and step. Default `false`. |
| `lora` | object | no | `rank` (1 to 256, default 16), `alpha` (default 32), `seed`, `train_attn` (default true), `train_mlp` (default true), `train_readout` (default false). |
| `name` | string | no | The run's own label, 100 characters maximum. |
| `total_steps` | int | no | The optimizer steps you plan, for the dashboard's progress bar and ETA. |
| `wandb` | bool | no | Log the run to Weights & Biases. Default: when the organization has a W&B connection. |
| `tags` | string array | no | |
| `config`, `user_metadata` | object | no | Free data for the dashboard. |
| `code_hash` | string | no | Your git commit. |

Response `201`: the run, with status `provisioning`. The future `ready_future_id` completes when the GPU is ready.
Errors: `402 insufficient_balance`, `404 not_found`, `409 conflict` (`model` is taken), `409 name_taken` (a continuous model has `model`), `409 limit_reached` (the organization's open runs, idle ones included: 25 by default, `max_active_runs` in `GET /v1/whoami`), `409 model_not_ready` (`from_model` is still being saved), `404 unknown_model` (`from_model`), `422 invalid_input` (also an unknown `base_model`), `422 unsupported`, `429 rate_limited` (20 creates a minute per org).

### Training calls

Each call returns `202 {"future_id": string}`. `seq_id` (int, required) must equal the run's `next_seq_id`. The run executes calls in `seq_id` order.

| Method and path | Body | Future result |
|---|---|---|
| `POST /v1/runs/{run_id}/forward` | `data` (1 to 1,024 [datums](https://endor.thetokencompany.com/docs/data-format#datum), required), `loss_fn?` (`cross_entropy` or `brier`), `seq_id` | `{"outputs": [{"probabilities": {id: float}, "loss": float}], "metrics": {"loss:sum", "weight:sum", "loss:mean", "accuracy", "n"}}` |
| `POST /v1/runs/{run_id}/forward_backward` | as `forward` | as `forward`; also adds gradients |
| `POST /v1/runs/{run_id}/predict` | `rows` (required: decisions `{"state", "questions"}` as in `/v1/systemone`, 1 to 64 questions each and 1,024 in all; `id`, `labels` and `weight` are ignored; no images), `seq_id` | `{"answers": [{name: answer}]}`: one item for each row, in order, as the `answers` of `/v1/systemone` |
| `POST /v1/runs/{run_id}/optim_step` | `adam_params?` (`learning_rate` 1e-4, `beta1` 0.9, `beta2` 0.95, `eps` 1e-12, `weight_decay` 0, `grad_clip_norm` 0), `seq_id` | `{"step": int, "grad_norm": float, "learning_rate": float}` |
| `POST /v1/runs/{run_id}/save_checkpoint` | `name?` (the model's name; default the run's `model`, `422 invalid_input` when it has none; a name that a saved model already has fails with `409 conflict`, one a continuous model has with `409 name_taken`, and neither uses a `seq_id`), `include_optimizer?` (bool), `ttl_seconds?` (3,600 to 315,360,000), `user_metadata?`, `seq_id` | `{"model": "<name>"}`: a new model, archived |

Errors: `402 insufficient_balance`, `404 not_found`, `409 invalid_state`, `409 seq_conflict`, `409 conflict` (the name is taken), `409 name_taken` (a continuous model has it), `409 limit_reached` (500 saved models in the organization), `422 invalid_input` (a reserved name), `422 invalid_datum` (`param`: `data[i]`; also a question that does not fit the base model), `422 invalid_options` (`predict`: a question that does not fit the base model; `param`: `rows[i].questions.<name>`), `429 queue_full`.

`predict` answers with the run's current adapter, before you save it. The answers match a decision on the model saved at that point within the usual difference between training and serving (a few hundredths at most in a probability). It does not change the run, and Endor bills it as training GPU time, like `forward`.

### Other run endpoints

| Method and path | Body or query | Response | Errors |
|---|---|---|---|
| `GET /v1/runs` | query `tag?` | `200` list of runs, newest first | |
| `GET /v1/runs/{run_id}` | | `200` run | `404 not_found` |
| `PATCH /v1/runs/{run_id}` | `total_steps?` (null: unknown) | `200` run | `404 not_found` |
| `POST /v1/runs/{run_id}/close` | | `200` run (`closing` or `closed`) | `404 not_found` |
| `POST /v1/runs/{run_id}/heartbeat` | | `204` | `404 not_found`, `409 invalid_state` (closed) |
| `POST /v1/runs/{run_id}/metrics` | `metrics` (`{key: float}`, 1 to 100 keys, required), `step?` (int) | `204` | `404 not_found` |
| `GET /v1/runs/{run_id}/metrics` | query `keys?` (comma-separated), `since_step?` | `200` `[{"step", "key", "value", "source", "time"}]` | `404 not_found` |
| `GET /v1/runs/{run_id}/events` | header `Last-Event-ID?` | `200` Server-Sent Events: a snapshot, then status, op, metric and model events | `404 not_found` |
| `POST /v1/runs/{run_id}/evaluations` (idempotent) | `model` (required), `results` (object, required), `step?`, `name?` (default `eval`) | `201` evaluation | `404 not_found` |

Send a heartbeat every minute while a run is open. Endor closes a run after an hour without calls or heartbeats. The SDK sends them for you, for a run from `runs.create` and from `runs.get`, until you close it.

## Evaluations

Evaluation object: `id`, `model`, `dataset` (`null` for rows sent with the call), `training_run_id`, `source` (`server` or `client`), `status` (`pending`, `running`, `completed`, `failed`), `results`, `rows_total`, `rows_done`, `started_at`, `created_at`.

A server evaluation decides the rows of a dataset (`dataset`) or the rows you send with the call (`rows`: up to 50,000 [decision rows](https://endor.thetokencompany.com/docs/data-format), 32 MB in all; nothing is stored as a dataset) with a model from a custom project (in production or archived) or a base model. A row with labels is asked its labeled questions and scored on them. A row without labels is asked every question and answered, not scored. So rows without any labels give predictions: the answers are in `rows_url` and the metrics are empty (`n` 0). Every decided row is billed, with or without labels. Inline rows are checked before anything runs, as a dataset upload is (`422 invalid_row`, `param` `rows[i]`), and so that the model reads every question it will ask (`422 invalid_options`, `param` `rows[i].questions.<name>`).

Progress of a server evaluation: `rows_done` of its `rows_total` rows, updated every few seconds while it runs, since `started_at`. Time left: `(rows_total - rows_done) * (now - started_at) / rows_done`. All three are `null` for client evaluations. A decision that fails for a passing reason (`429`, `5xx`, a timeout) is retried up to 3 times before it fails the evaluation. If Endor restarts while an evaluation runs, the evaluation starts again on its own: `status` goes back to `pending`, its future stays `running`, and each row is still billed once. After 3 such restarts it fails with `internal`.

Server `results`:

- `n`: the number of scored (labeled) questions.
- `overall`, `by_type` (`{type: metrics}`), `by_question` (`{question name: metrics}`). The metrics are `n`, `accuracy`, `nll`, `brier`, `ece`, `mean_confidence` and `selective`.
- `accuracy`: the share of questions whose top option is the label (for a soft label, one of its top options). When k options tie exactly for the top, each counts 1/k, as in the SDK's `decision_metrics`.
- `selective`: `{"0.5": {"accuracy", "coverage"}, "0.7": ..., "0.9": ..., "0.95": ...}`. For each threshold, `coverage` is the share of questions where the top option has at least this probability, and `accuracy` is the accuracy on these questions (`null` if there are none).
- `rows_url`: a signed link to a JSONL file with one line for each question asked, in the rows' order: `{"row", "index", "question", "probabilities", "answer", "target"}`. `row` is the row's `id`, `index` its position (from 0), `answer` the answer as `/v1/systemone` gives it, and `target` the label as a distribution (`null` for a row without labels). The link expires after 1 hour; each read of the evaluation gives a new link.

| Method and path | Body or query | Response | Errors |
|---|---|---|---|
| `POST /v1/evaluations` (idempotent) | `model` (required: the name of a model from a custom project, in production or archived, or a base model's id, `owner/model`), `dataset` or `rows` (one of the two), `training_run_id?`, `metrics?` (accepted for compatibility: Endor always calculates all metrics) | `202` `{"future_id", "evaluation_id"}`; the future result is `{"evaluation_id"}` | `402 insufficient_balance`, `404 not_found`, `404 unknown_model`, `409 model_not_ready`, `413 payload_too_large`, `422 invalid_row`, `422 invalid_options`, `429 rate_limited` |
| `GET /v1/evaluations` | query `run_id?`, `model?` | `200` list of evaluations, newest first | |
| `GET /v1/evaluations/{evaluation_id}` | | `200` evaluation | `404 not_found` |

## Futures

Future object: `id`, `kind` (`provision_run`, `forward`, `forward_backward`, `predict`, `optim_step`, `save_checkpoint`, `evaluate`), `status` (`pending`, `running`, `completed`, `failed`, `cancelled`), `result`, `error` (`{"code", "message"}`), `created_at`, `completed_at`.

| Method and path | Body or query | Response | Errors |
|---|---|---|---|
| `GET /v1/futures/{future_id}` | query `wait_s?` (0 to 30): wait for the end | `200` future | `404 not_found` |
| `POST /v1/futures/retrieve` | `ids` (1 to 256, required); query `wait_s?` | `200` list of futures, in request order | `404 not_found` |
| `POST /v1/futures/{future_id}/cancel` | | `200` future | `404 not_found` |

Failure codes in `error.code`: `trainer_lost`, `oom`, `no_gradients`, `cancelled`, `invalid_datum`, `invalid_options` (`predict`: a question the base model can't read), `context_too_long` (a datum or a question renders to more tokens than the base's `max_question_tokens`, as in a decision), `internal`. To cancel `provision_run` closes the run.

## Account

| Method and path | Query | Response |
|---|---|---|
| `GET /v1/whoami` | | `200` `{"org_id", "key_id", "user_id", "limits", "continuous_learning", "zero_data_retention"}` |
| `GET /v1/balance` | | `200` `{"balance_usd"}` |
| `GET /v1/usage` | `starting_on?` (default: 14 days before `ending_before`), `ending_before?` (default: now), `project?`; 14 days maximum | `200` `[{"hour", "kind", "project", "project_deleted", "base_model", "model", "training_run_id", "input_tokens", "gpu_seconds", "continuous_learning", "price_per_mtok", "base_cost_usd", "continuous_learning_cost_usd", "cost_usd"}]` |

`limits` gives each limit of the organization by name, for example, with the defaults, `{"max_projects_per_org": 5, "max_production_models_per_org": 3, "max_active_runs": 25, "max_dataset_rows": 50000, "decisions_per_minute": 1200, ...}`, with your organization's own values. A count limit that is reached gives `409 limit_reached` (`409 production_full` for the production slots); a rate gives `429 rate_limited`. See [Limits](https://endor.thetokencompany.com/docs/billing#limits).

`continuous_learning` says whether your organization has continuous models (`/v1/projects`), which are only available to invited organizations. While it is `false`, calls to continuous models return `403 continuous_learning_not_enabled`.

`zero_data_retention` says whether your organization has [zero data retention](#data-retention).

`balance_usd` is the prepaid balance of the organization in USD: the credits bought or granted, minus the usage so far. At $0 or less, paid calls fail with `402 insufficient_balance`. `GET /v1/balance` takes up to 300 calls a minute per organization (`429 rate_limited`).

In usage rows, a continuous model's decisions have `project` (its name) and `model` (the version that answered); the decisions of a custom project's model have `project` `null` and `model` its name; training has `project` `null` and `training_run_id`. `project_deleted` is true for usage of a deleted continuous model (`project` can then be null).

API keys, credits and billing settings are in the dashboard only.

## Data retention

Endor stores each request's body and JSON response, and keeps them until you ask it to delete them (email rasmus@thetokencompany.com). Endor keeps training data until you delete it.

With **zero data retention**, which Endor turns on for an organization when asked (email rasmus@thetokencompany.com):

- Endor doesn't store request and response bodies or images in its request log. It keeps only each request's id, route, status, duration, model and token count.
- Endor deletes training data (datasets, and the rows of evaluations) 30 days after it was sent. Deleting a dataset removes its files at once. The data sent with a training operation goes 24 hours after the operation finishes, as for every organization.
- Continuous models and corrections aren't available: `403 continuous_learning_not_enabled` and `403 zero_data_retention`.

| Method and path | Response |
|---|---|
| `DELETE /v1/training_data` | `200` `{"datasets", "evaluations"}`: how many were deleted |

`DELETE /v1/training_data` deletes all of your organization's training data now, with or without zero data retention: every dataset, and the stored rows of every evaluation. An evaluation keeps its results, without `rows_url`. An evaluation that is still running fails with `training_data_deleted`. Trained models are kept. It can't be undone. The dashboard does the same under **Settings**.

## User reports

Tell the Endor team when something does not work as you expect, when the docs or an error are unclear, or when your integration works. Coding agents are welcome to send these. Every report is read.

| Method and path | Body | Response | Errors |
|---|---|---|---|
| `POST /v1/user_reports` | `{"kind", "message", "request_id"?, "context"?}` | `201` `{"id", "message"}` | `422 invalid_input`, `429 rate_limited` (20 an hour per organization) |

- `kind`: `bug` (Endor did something you did not expect), `confusing` (the docs, an error or a step was unclear) or `works` (the integration runs).
- `message`: what you did, what happened and what you expected (4,000 characters maximum). Do not include API keys or customer data.
- `request_id`: the request it is about, from an error's `request_id` or the `X-Request-Id` header.
- `context`: other facts that help, such as the SDK version (30 keys maximum).

## Errors

```json
{"error": {"code": "unknown_model", "message": "No model 'tickets-old'.", "param": "model", "request_id": "req_...", "report": "Unexpected, or unclear? Tell the Endor team: POST /v1/user_reports ..."}}
```

Use `code` in your code. `code` does not change. `message` can change. `param` gives the incorrect field, if known. `request_id` is the request's id (also in `X-Request-Id`). `report` says how to [report](#user-reports) the error if it is unexpected or unclear.

| Status | Code | Cause |
|---|---|---|
| 400 | `invalid_input` | Endor cannot read the body: it isn't valid JSON (the message says where), or bad gzip. |
| 401 | `unauthorized` | The API key is missing or not valid; a request with a body gets it before the body is read. A revoked key can keep working for up to a minute. |
| 402 | `insufficient_balance` | The balance is $0 or less. |
| 403 | `continuous_learning_not_enabled` | Continuous models are only available to invited organizations, and yours isn't one yet, or it has [zero data retention](#data-retention): every `/v1/projects` endpoint and every decision on a continuous model returns it. Use [custom projects](https://endor.thetokencompany.com/docs/training), or email rasmus@thetokencompany.com to ask for continuous models. |
| 403 | `zero_data_retention` | A correction, while your organization has [zero data retention](#data-retention): its decisions aren't stored, so they can't be corrected. |
| 404 | `not_found` | The continuous model, version, saved model, dataset, run, evaluation, future, decision or correction does not exist. |
| 404 | `unknown_model` | No continuous model, saved model or base model has this name: a decision's, an evaluation's or a prediction's `model`, or a run's `from_model`. A base model is named `owner/model`. |
| 404 | `version_not_callable` | `<name>:v3` names a version of a continuous model that is neither in production nor the preview. Promote the version first, or call `<name>`. |
| 404 | `no_preview` | `<name>:preview` while the newest version is in production (usually so with auto-promote on). Call `<name>`. |
| 409 | `conflict` | The name exists: one of the same kind (a continuous model, or a saved model) has it. |
| 409 | `name_taken` | The other kind has the name: continuous models and saved models share names, so creating a continuous model called like a saved model (or the reverse) fails. Pick another name. |
| 409 | `limit_reached` | A count limit is reached, for example 5 continuous models. The message gives the limit and its value. See [Limits](https://endor.thetokencompany.com/docs/billing#limits). |
| 409 | `production_full` | Every production slot for models from custom projects is taken. Promote with `replace`, or archive one first. The message names the models in production. |
| 409 | `model_not_in_production` | A decision named an archived model. Promote it first. |
| 409 | `model_in_production` | The call does not apply to a model in production: deleting it, or giving it a TTL. Archive it first. |
| 409 | `model_not_ready` | The model's `save_checkpoint` is not done yet. Wait for its future, then try again. |
| 409 | `no_base_model` | The base model is no longer served (a decision), or a continuous model's base model is no longer served. |
| 409 | `no_base_model` | The base model is no longer served (a decision), or a continuous model's base model is no longer served. |
| 409 | `invalid_state` | The run is closed or failed, or the model has no optimizer state. |
| 409 | `seq_conflict` | `seq_id` is not the run's `next_seq_id`. |
| 409 | `run_active` | A run uses this resource. Try again later. |
| 413 | `payload_too_large` | The body is over the route's limit (64 MB for dataset uploads; 32 MB for evaluations and `forward` / `forward_backward` / `predict`; for decisions 1 MB plus room for 8 images of 5 MB, about 54 MB; 8 MB for `POST /v1/corrections/batch`; 4 MB elsewhere). |
| 422 | `invalid_input` | The body is valid JSON but doesn't fit the endpoint. `param` names the field, and the message says what fits there. |
| 422 | `invalid_row` | A row of a dataset upload or an evaluation is not valid. `param`: `rows[i]`; the message names the field. |
| 422 | `invalid_datum` | A datum is not valid. `param`: `data[i]`. |
| 422 | `invalid_options` | A question does not fit the base model. |
| 422 | `context_too_long` | A decision's question, with the state, is longer than the base model reads (`max_question_tokens` in `GET /v1/base_models`). |
| 422 | `unsupported` | The base model does not support a setting (`train_readout`, `rank`). |
| 429 | `rate_limited` | Too many requests: more than 1,200 decisions a minute per org (or your organization's own limit), more than 5 open event streams per key, more than 60 dataset uploads, 20 run creations, 120 evaluations or 300 balance calls a minute per org, or more than 20 user reports an hour per org. Wait for `Retry-After`. |
| 429 | `queue_full` | 64 calls are pending on the run. |
| 500 | `internal` | An Endor error. Try again. |
| 529 | `overloaded` | The decision servers are busy. Try again. |

## Other pages

- [Overview](https://endor.thetokencompany.com/docs/index.md): What Endor does: you train decision models on your labeled data in custom projects with the SDK, Endor runs the GPUs, and you call them by name. Continuous models are for invited organizations.
- [Quickstart](https://endor.thetokencompany.com/docs/quickstart.md): Start here: install the SDK, measure base models on your data, train a model in a custom project, evaluate it, promote it and call it.
- [Core concepts](https://endor.thetokencompany.com/docs/concepts.md): Organizations, continuous models and their production and preview versions, names, base models, custom projects, datasets, runs, evaluations and futures.
- [Custom projects](https://endor.thetokencompany.com/docs/training.md): Custom projects (custom_models in the SDK and API): train a model with the SDK, save, promote to production, call, download; the training loop in detail.
- [Continuous models](https://endor.thetokencompany.com/docs/continuous-learning.md): Continuous models (projects in the SDK and API), only available to invited organizations: create one, call its production version or its preview, auto-promote, promote and roll back versions, feedback, price.
- [Decisions](https://endor.thetokencompany.com/docs/decisions.md): Decisions with the SDK and over HTTP, model names, giving feedback on them, TypeSafe clients, cold starts, errors.
- [Base models](https://endor.thetokencompany.com/docs/base-models.md): The 18 base models: limits, rules, prices and cold starts.
- [Billing & limits](https://endor.thetokencompany.com/docs/billing.md): Prices, the prepaid balance, usage and limits.
- [Data format](https://endor.thetokencompany.com/docs/data-format.md): Decision rows, question types, hard and soft labels, datums and limits: the data for custom projects.
- [Python SDK](https://endor.thetokencompany.com/docs/sdk.md): The Python SDK (0.9.0): client, continuous models (client.projects) and versions, custom projects (client.custom_models), datasets, runs, evaluations, futures, data helpers, recipes, errors, CLI.
- [Updates](https://endor.thetokencompany.com/docs/updates.md): Changes to the API and SDK, newest first, and when old names and endpoints stop working.
- [Index](https://endor.thetokencompany.com/llms.txt): every page and the API schema.
