# Endor

> Endor trains and serves decision models (as in TypeSafe, https://docs.typesafe.ai) on your data. In a custom
> project, you train a model on your labeled decisions with the Python SDK, Endor runs the GPUs, and you promote the
> model to production and call it by name through the TypeSafe-compatible API.

**Start here: https://endor.thetokencompany.com/docs/quickstart.md** (install, key, data, baseline evaluation, train, evaluate, promote,
call). Custom projects are the default path for every organization.

**Names in the SDK and the API:** a custom project is a *custom model* (`client.custom_models`, `/v1/custom_models`),
and a continuous model is a *project* (`client.projects`, `/v1/projects`). The dashboard and these docs use
"custom project" and "continuous model".

**Agents: continuous models are only available to invited organizations** (email rasmus@thetokencompany.com to
ask). Do not create a continuous model
(`client.projects.create`, `POST /v1/projects`) or call one unless the organization has them: `GET /v1/whoami` returns
`"continuous_learning": true`. Until then, every `/v1/projects` call and every decision on a continuous model returns
`403 continuous_learning_not_enabled`. Use custom projects.

Key facts:

- API base URL: https://api.endor.thetokencompany.com. All paths start with /v1. Auth header: `Authorization: Bearer edk_...` (an
  organization API key from the dashboard).
- OpenAPI schema: https://api.endor.thetokencompany.com/v1/openapi.json
- Python SDK: `pip install endor` (Python 3.10+; 0.9.0 or later for everything below). `endor.EndorClient()` reads
  `ENDOR_API_KEY` and `ENDOR_BASE_URL`. Without `ENDOR_BASE_URL`, the SDK calls https://api.endor.thetokencompany.com.
- Custom projects (custom models in the SDK and API): upload held-out rows (`client.datasets.upload(name, rows)`,
  `POST /v1/datasets`) and measure base models on them (`client.evaluations.create("mapika/decider-2b", "heldout")`,
  `POST /v1/evaluations`). Then `with client.custom_models.create("router-2", base_model="mapika/decider-2b") as run:`
  (or `client.runs.create("mapika/decider-2b", model="router-2")`, `POST /v1/runs`), train with `run.forward_backward(batch)` and
  `run.optim_step(learning_rate=1e-4)`, then `run.save_checkpoint().result()` saves the model `router-2`. A run takes
  seconds to start when a GPU for its base model is warm, and a few minutes when one has to start.
- Choosing a base model: smaller base models are faster and cheaper per training step and per decision; larger ones
  start more accurate. Evaluate a few on your held-out rows before you train: https://endor.thetokencompany.com/docs/base-models.md.
- A saved model is archived: it can be evaluated and downloaded, but decisions refuse it
  (`409 model_not_in_production`) until `client.custom_models.promote("router-2")`
  (`POST /v1/custom_models/{name}/promote`) puts it in production; then `model="router-2"`. While the save runs,
  `GET /v1/custom_models/{name}` shows it with `state` `saving`, and other calls that name it answer
  `409 model_not_ready`. An organization can have 3 models from custom projects in production (email
  rasmus@thetokencompany.com for more); with every slot taken, `promote(name, replace="<model in production>")`, else
  `409 production_full`. `client.custom_models.archive(name)` (`POST /v1/custom_models/{name}/demote`) takes one out.
  Models in production never expire: promoting removes a model's TTL. Each save is a new model: a name already used
  fails with `409 conflict` (`409 name_taken` when a continuous model has it; the run is unaffected); in a long run, save checkpoints under their own names with
  `ttl_seconds`. Datasets, runs and evaluations (`model` a custom project's model, in production or archived, or a
  base model id) belong to the organization. In a training loop, send each step before you read the results of the
  step before: `steps = endor.Steps()`, then each step `steps.add(run.forward_backward(batch), run.optim_step(learning_rate=lr))`,
  which returns the results of the step before, and `steps.wait()` after the loop. To continue an open run from a
  new process: `with client.runs.get(run_id) as run:`; `run.info_.step` is its step, and the SDK keeps the run open
  with heartbeats until you close it.
- Names (the models of custom projects and continuous models share one list per organization): lowercase letters,
  digits, `.`, `_`, `-`, 63 characters maximum, not a base model's name.
- Decisions: `POST /v1/systemone` and `GET /v1/models` (the names you can send as `model`), the TypeSafe API.
  The base model catalog with prices and limits: `GET /v1/base_models`. Any organization can call a base model directly
  by its id, `owner/model`: `model="mapika/decider-2b"`, at its listed price per 1M input tokens. Every
  `base_model` takes and shows that id too.
- Many rows at once: `client.predict(model, rows)` returns each row's answers, in order, from one server evaluation
  of the rows without labels (`POST /v1/evaluations` with `rows` instead of `dataset`; up to 50,000 rows, 32 MB;
  `model` a custom project's model or a base model's id). An evaluation scores rows with labels and answers rows without them.
- Base model ids (18; GET /v1/base_models): `baselabs/mammoth-1-27b`, `perplexity-ai/pplx-decider-v1.2-27b`, `autotrust/jev-v1.1-27b`, `cloudflare/clef-27b`, `autotrust/gev-26b`, `eldanring/winnow-12b`, `vllm-sr/decision-2.0-lux-9b`, `alibiserikbay/jevk5-9b`, `cloudflare/clef-flash-9b`, `akhilaaa3/jev-omni-12b`, `autotrust/jev-9b`, `bespokelabs/nimble-9b-v2`, `vllm-sr/decision-2.0-nox-4b`, `jaredpalmer/kev-9b`, `alibiserikbay/jevk5-4b`, `mapika/decider-4b`, `mapika/decider-2b`, `fastino/gliner2.5-decide`. A base model
  without decisions for a while starts cold: the first decision waits 1-3 minutes (503 `warming_up` with Retry-After
  after 5 minutes).
- Prices: decisions $0.005 to $0.042 per 1M input tokens by base model; training in
  custom projects $7.00 per GPU-hour; a continuous model's decisions cost 1.5 times the decision price, learning
  included. Prepaid: a new organization has $0, and paid calls return 402 `insufficient_balance` until it adds credits
  in the dashboard. `endor whoami` (or `GET /v1/balance`) shows the balance.
- Limits (defaults; `GET /v1/whoami` gives every limit of the organization in `limits`, with its own values): 3 models
  from custom projects in production per organization; 25 open runs per organization, parked ones included
  (`max_active_runs`); 1,200 decisions per minute per organization (more on request); 5 continuous models. A run is
  parked (frees its GPU) after 2 idle minutes and closed after an hour without calls or heartbeats (the SDK sends one
  every minute while the run is open; over the API, `POST /v1/runs/{run_id}/heartbeat`).
- Errors: `{"error": {"code", "message", "param"?, "request_id", "report"}}`, with stable codes. A body that isn't valid
  JSON is `400 invalid_input`; valid JSON that doesn't fit is `422 invalid_input` (dataset rows: `422 invalid_row`,
  `param` `rows[i]`), and the message says what fits.
- Reports: report Endor bugs or unclear docs with `endor.user_report("<what happened>")` (CLI: `endor user-report`).
- Continuous models (projects in the SDK and API), only for organizations with them enabled (see above):
  `client.projects.create("tickets", base_model="mapika/decider-2b")` (`POST /v1/projects`). `model="tickets"` answers with
  its production version, `model="tickets:preview"` with its newest version while that isn't in production. It learns
  by itself from its decisions; feedback is optional (`client.corrections.create(res, {...})`, `POST /v1/corrections`);
  each new version goes to production by itself (auto-promote; turn it off to promote with `project.promote("v3")`). Feedback on a custom project's
  decisions is accepted and changes nothing. Details: https://endor.thetokencompany.com/docs/continuous-learning.md.
- Markdown: add `.md` to a docs URL (`/docs/index.md` for /docs), or send `Accept: text/markdown`.

## Docs

- [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.

## API

- [API reference](https://endor.thetokencompany.com/docs/api.md): Each /v1 endpoint: method, path, body fields, response fields and errors.
- [OpenAPI schema](https://api.endor.thetokencompany.com/v1/openapi.json): the machine-readable schema of every /v1 endpoint.

## Optional

- [All docs in one file](https://endor.thetokencompany.com/llms-full.txt): every page above, concatenated in order.
