# API reference: endpoints

Inference endpoints: hub-served inference for the skill / planner layer. The hub never serves the reflex layer. `lucen serve` claims an endpoint. A device consumes one only through a signed approval bound to device + model digest + endpoint id. On Lucen cloud the owner pays the tier's hourly rate while the endpoint runs. Sessions are metered, and carry no price.

## GET /v1/endpoints

`listEndpoints` · scope `key:read` · List inference endpoints

Endpoints the caller may see: their own and those billed to an org they belong to. **No endpoint is public.** Newest first; an unknown `owner` or `model_repo` is an empty page, not a 404.

Parameters:

- `status` (query)
- `executor` (query)
- `model_repo` (query): Only endpoints serving this `owner/slug`.
- `owner` (query)
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of endpoints.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `422`: Request failed validation.

## POST /v1/endpoints

`createEndpoint` · scope `key:train` · Create an inference endpoint for a skill-layer model

A model repo becomes a hub-served inference endpoint. **Inference placement is enforced here.** The repo's `ModelMeta.control_class` must be `skill` or `planner`. A `reflex` model (a 50 Hz locomotion controller) answers `409`. This hub serves nothing reflex-rate over a network. A model that has declared no class answers `422` asking for one.

The endpoint is pinned to one ONNX (`onnx_path`, or the repo's single root `*.onnx`) and its **current sha256**. A device approval request is pinned the same way. Every session's approval token is later bound to that sha256.

**Or it is pinned to a checkpoint directory.** A model with no ONNX export (the VLA `smolvla_lora` trains) is published as `policy/` + `lucen_manifest.json`. The endpoint is then pinned to that directory and to its `lucen-checkpoint-v1` digest (`EndpointArtifact`). The directory is named by `policy_path`, or auto-detected when the repo holds no root ONNX. Its `control_class`, contract fingerprint and `params` are read from the manifest, which the digest covers. A manifest that says `reflex` is `409`, whatever `ModelMeta` says.

The hardware tier is chosen by the model's size. The caller does not pick it. The hub sizes the weights from the artifact itself when it can: the ONNX file's bytes, or the weight files under a checkpoint directory. It adds 20 % headroom for activations and picks the smallest tier that fits. A quantised file is sized as the bytes it holds. Some artifacts cannot be sized this way: a PEFT adapter, whose base weights live elsewhere, or a file too small to hold its declared parameters. For those the hub falls back to `params × bytes per parameter`. The dtype comes from the manifest's `weights_dtype`, bf16 otherwise. `params` comes from the repo's `io_contract.json` / manifest, else from the body. With no size at all the call answers `422`. `Endpoint.vram_basis` says which rule applied.

**Idle stop.** A running endpoint with no open session for `idle_stop_minutes` is stopped by the hub, the way `stopEndpoint` stops it, and audited as `endpoint.idle_stop`. The default is 10 minutes on `modal` and never (`0`) on `worker`. `keep_warm: true` disables it. An open session always keeps the endpoint running. Separately, the server closes a session that requested no chunk for `session_idle_seconds` (default 300) with reason `idle`, so its metering ends.

`executor: worker` (the default) records the endpoint `queued` until `lucen serve` on the owner's own GPU box claims it. Such an endpoint is unpriced. `executor: modal` records the endpoint `queued`, and the hub spawns the deployed `endpoint` function on the tier's GPU. That function claims the endpoint with a public `wss://` URL. On a deployment without `MODAL_APP_NAME`, `executor: modal` answers `503` naming that setting and records nothing. No fake `running` endpoint is created. `key:train`: an endpoint spends GPU time. Audited as `endpoint.create`.

**What it costs.** On Lucen cloud the owner pays the tier's hourly rate for the endpoint's uptime (`cost_basis: uptime`). That is every second from the server's claim to the stop, whether or not a robot has a session open. The hub refreshes `cost_usd` on every report and fixes it when the endpoint ends, cutting one ledger row for it. Sessions are metering detail and carry no price. `budget_usd` caps that uptime cost. The hub stops an idle endpoint after `idle_stop_minutes`, so an endpoint nobody uses does not run up a bill. A `worker` endpoint costs nothing.

**Hosted execution.** `executor: modal` serves only owners in the deployment's `HOSTED_OWNERS` (default `lucen`; `*` = everyone). Anyone else gets `403` with `errors[].type: forbidden.hosted_owner`, and nothing is recorded. The error names the setting and `lucen serve`. The estimate answers the same `403`. Lucen cloud's policy server loads ONNX files only, so a checkpoint directory on `executor: modal` is `409` before anything is recorded or priced; serve it with `executor: worker` and `lucen serve`.

Request body: `application/json`, required.

Responses:

- `201`: Endpoint recorded (`queued` for a `worker` executor).
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.
- `429`: The account's spend cap is in `stop` mode, and this job would carry the month past it. The month counts recorded Lucen cloud spend, what queued and running cloud work could still cost, and this job's own most possible cost. `errors[].type` is `quota.spend_cap`. `Retry-After` counts the seconds until the month ends. Nothing was recorded, and work already running keeps running.
- `503`: A service this endpoint needs is not configured in this deployment. The API boots with zero secrets. An endpoint that needs one says so instead of returning a stack trace.

## POST /v1/endpoints/estimate

`estimateEndpoint` · scope `key:train` · Price an endpoint before creating it

Takes the same body as `createEndpoint` plus `hours` and validates it identically (visibility, kind, control class, size). It creates nothing. Answers the tier the model's size selects and `rate_usd_per_hour × hours`: what `hours` of uptime would cost. On Lucen cloud the rate accrues for every second the endpoint is up, with or without a robot connected. A `worker` endpoint is `cost_usd_max: 0, priced: false`. The hub bills nothing for the owner's own GPU. Zero means "not charged". It does not mean the GPU time is free. A `modal` estimate **is** priced at the tier's billed rate.

**Hosted execution.** `executor: modal` serves only owners in the deployment's `HOSTED_OWNERS` (default `lucen`; `*` = everyone). Anyone else gets `403` with `errors[].type: forbidden.hosted_owner`, and nothing is recorded. The error names the setting and `lucen serve`. The estimate answers the same `403`. Lucen cloud's policy server loads ONNX files only, so a checkpoint directory on `executor: modal` is `409` before anything is recorded or priced; serve it with `executor: worker` and `lucen serve`.

Request body: `application/json`, required.

Responses:

- `200`: The estimate.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## GET /v1/endpoints/{endpoint_id}

`getEndpoint` · scope `key:read` · Get an inference endpoint

One endpoint with its live counters (open sessions, chunks served, GPU-seconds, service and round-trip p95) and what it has cost. `cost_usd` and `billed_seconds` are live while it runs: the claim to this instant at the tier's rate. Once it ended they are fixed. An endpoint the caller may not see is `404`. The API does not answer `403` here, because that would confirm the endpoint exists.

Parameters:

- `endpoint_id` (path, required): Endpoint id (`ep_...`).

Responses:

- `200`: The endpoint.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).

## DELETE /v1/endpoints/{endpoint_id}

`stopEndpoint` · scope `key:train` · Stop an inference endpoint

A `queued` endpoint is `stopped` at once (nothing ran, nothing to bill). A `running` endpoint has a server behind it. So the hub sets `stop_requested_at` and answers `202` with the endpoint **still `running`**. `lucen serve` sees the flag on its next report, closes every session and reports `stopped`. Billing stops at that report: the endpoint's cost is fixed and its ledger row is written. Idempotent. A terminal endpoint is `409`. `key:train`, like `cancelRun`. Audited as `endpoint.stop`. The hub takes the same path on its own for an endpoint idle past `idle_stop_minutes` (audited as `endpoint.idle_stop`) and for one whose uptime cost reached `budget_usd`. `Endpoint.stop_reason` says which it was.

Parameters:

- `endpoint_id` (path, required): Endpoint id (`ep_...`).

Responses:

- `202`: Stopped, or stop requested; the endpoint as it now stands.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).

## POST /v1/endpoints/{endpoint_id}/claim

`claimEndpoint` · scope `key:train` · Claim a queued worker endpoint (`lucen serve` protocol)

The run protocol, mirrored: compare-and-set `queued → running` on an endpoint whose `executor` is `worker`. Exactly one caller wins. An endpoint already claimed, terminal, or not a `worker` endpoint answers `409`. The server states the **websocket URL** devices will connect to and the **sha256 of the file it loaded**. That sha256 must equal the endpoint's `model_sha256` (`422` otherwise). A server serving bytes other than the ones approvals are bound to is refused before any device can reach it. Records `claimed_by`, the claiming credential, `claimed_at`, `started_at` and the first `heartbeat_at`. Only the claiming credential may `reportEndpoint` afterwards. Anyone else gets `409`. Audited as `endpoint.claim`. `key:train`: the server spends the owner's GPU on the owner's behalf. On Lucen cloud the bill starts at `claimed_at`.

Parameters:

- `endpoint_id` (path, required): Endpoint id (`ep_...`).

Request body: `application/json`, required.

Responses:

- `200`: Claimed; the endpoint as it now stands.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## POST /v1/endpoints/{endpoint_id}/report

`reportEndpoint` · scope `key:train` · Report sessions, metering and state for a claimed endpoint

The server's one write path after `claimEndpoint`, called every few seconds. The endpoint must be `running` (`409` otherwise). The caller must be the credential that claimed it (`409` otherwise). `sessions[]` carries the server's numbers per session:

- chunks served
- **GPU-seconds attributed as wall time × 1 / concurrent open sessions**. A shared inference GPU is split evenly across the sessions it served, and the row says so.
- service-time p50/p95

A session also carries `state: closed` when the device's link went away. The first close of a session wins. A session already closed keeps its `closed_reason` and `closed_at`. This report then only adds the server's numbers.

Every report refreshes `heartbeat_at` and the bill: on Lucen cloud `cost_usd` becomes the seconds since the claim at the tier's rate, whether or not a session is open. The report whose cost reaches `budget_usd` comes back with `stop_requested_at` set.

`status: stopped | failed` is terminal. Every still-open session is closed as metering detail (`cost_usd` 0, no ledger row). The endpoint's cost is fixed at that instant, its one ledger row is written, and `endpoint.finish` is audited with the cost. A `worker` endpoint's row is `0` / unpriced. Read `stop_requested_at` on the returned endpoint. When it is set, close every session and report `stopped`.

Parameters:

- `endpoint_id` (path, required): Endpoint id (`ep_...`).

Request body: `application/json`, required.

Responses:

- `200`: Recorded; the endpoint as it now stands.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## GET /v1/endpoints/{endpoint_id}/sessions

`listEndpointSessions` · scope `key:read` · List an endpoint's sessions (metering)

Newest first. Each session carries the server's metering (chunks served, GPU-seconds, service p50/p95). It also carries the device's own metering (chunks applied, round-trip p50/p95, deadline misses, degraded count). A session carries no price: the endpoint's uptime is what is billed. (An endpoint created before 16 October 2026 still prices each closed session.) `status` narrows to `open` or `closed`.

Parameters:

- `endpoint_id` (path, required): Endpoint id (`ep_...`).
- `status` (query)
- `limit` (query): Page size.
- `cursor` (query): Opaque cursor from the previous page's `next_cursor`.

Responses:

- `200`: Page of sessions.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `422`: Request failed validation.

## POST /v1/endpoints/{endpoint_id}/sessions

`openEndpointSession` · scope `key:write` · Open a session on an endpoint (a device, with a human's approval)

**Invariant 2**: an endpoint is consumed only through the consent layer. The caller is the robot-side driver (`lucen-device`, a `write` key that can see the device). It must present the EdDSA **approval token** a human minted with `createApproval`. The token must have been minted on a request that named this endpoint (`ApprovalRequestCreate.endpoint_id`). The hub verifies the token against its own signing key. It answers **`403`** in each of these cases:

- the token is missing, unsigned or expired
- the token is bound to another endpoint or another device
- the approval is no longer `issued` / `running`

Every refusal gets the same answer, so a token cannot be probed. The hub then checks the token's `onnx_sha256` against the endpoint's `model_sha256`. It answers `409` when the endpoint was re-created on other bytes. It also checks that a server has claimed the endpoint (`409` while `queued`).

On success it records the session. It returns the server's websocket `url` plus a **short-lived session token** (EdDSA, `typ: lucen-session+jwt`, `exp = min(approval exp, now + ENDPOINT_SESSION_TTL_S)`). The device presents that token to the server as openpi's `api_key` header. The server verifies it offline against `GET /v1/devices/signing-key`. No hub API key can open a session without a signed approval. That is what this invariant guarantees. Audited as `endpoint.session_open`.

Parameters:

- `endpoint_id` (path, required): Endpoint id (`ep_...`).

Request body: `application/json`, required.

Responses:

- `201`: Session opened; connect to `url` with `session_token`.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.

## POST /v1/endpoints/{endpoint_id}/sessions/{session_id}/report

`reportEndpointSession` · scope `key:write` · The device's own metering for a session

Only the device can measure a round trip, so it reports its side. That covers chunks applied, round-trip p50/p95 in milliseconds and how many chunk deadlines were missed. It also covers how many times the local fail-safe fired (`degraded_count`). `closed: true` ends the session from the device's side. `closed_reason` says why: `expired`, `local_cap`, `stopped`, `link_lost`. The caller must be a credential that can see the session's device (`404` otherwise). A session already closed by either side is `409`: the first close wins. Each report **replaces** the device-side numbers. They are percentiles over the whole session. They are not deltas. `key:write`, like the driver's telemetry events.

Parameters:

- `endpoint_id` (path, required): Endpoint id (`ep_...`).
- `session_id` (path, required): Endpoint session id (`esess_...`).

Request body: `application/json`, required.

Responses:

- `200`: Recorded; the session as it now stands.
- `401`: Missing or invalid credentials.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `404`: Resource not found (or hidden from the caller).
- `409`: State conflict (duplicate handle/slug, wrong repo kind, terminal job, ...).
- `422`: Request failed validation.
