> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# HTTP API

> The central server's endpoints, who may call each, and what they take and return.

The CLI and the dashboard use this API; you can too. The hosted server is `https://api.ephemera.run`. Bodies are JSON. Errors come back with a 4xx or 5xx status and a body like:

```json theme={"theme":"css-variables"}
{ "error": "invalid token; run ephemera login" }
```

## Authentication

| How | Header | Who uses it |
| - | - | - |
| Token | `Authorization: Bearer eph_...` | The CLI, CI, scripts. Any device or API token |
| Session | The `ephemera_session` cookie from GitHub sign-in | The dashboard |

Requests with a session that change something (`POST`, `DELETE`) must come from the dashboard's own site: they need its `Origin` header. Browsers on other sites get no CORS headers, so they can't read the API with your cookie.

A token or a session sees only its own account's sandboxes and hosts. Another account's sandbox or host is "not found", not "forbidden", so ids can't be probed.

## Endpoints

| Method and path | Auth | Does |
| - | - | - |
| `GET /healthz` | none | Answers `ok` |
| `GET /v1/whoami` | token | The token's name and account |
| `POST /v1/sandboxes` | token | Make a sandbox |
| `GET /v1/sandboxes` | token or session | The account's running sandboxes |
| `DELETE /v1/sandboxes/{id}` | token or session | Destroy a sandbox, by its id or its name |
| `GET /v1/runs` | token or session | The account's sandboxes, running and finished, newest first |
| `GET /v1/usage` | token or session | Sandbox-minutes today, and limits |
| `GET /v1/hosts` | token or session | The account's hosts |
| `DELETE /v1/hosts/{id}` | token or session | Remove a host and destroy its sandboxes |
| `GET /v1/me` | session | Who is signed in |
| `GET /v1/tokens` | session | The account's tokens, never their secrets |
| `POST /v1/tokens` | session | Make an API token |
| `DELETE /v1/tokens/{id}` | session | Revoke a token |
| `POST /v1/join-codes` | session | Make a one-time code to join a host |
| `GET /auth/github` | none | Start GitHub sign-in. `?next=/path` returns to that path afterwards |
| `POST /auth/logout` | session | End the session |
| `POST /v1/device/codes`, `POST /v1/device/token` | none | `ephemera login`'s browser sign-in |
| `GET /v1/device`, `POST /v1/device/approve` | session | The approval page |
| `POST /v1/hosts/join`, `GET /v1/hosts/connect` | join code, host key | For hosts |

`/v1/runs` needs Postgres; a server keeping its state in files has no run history. The `/v1/me`, `/v1/tokens`, `/v1/join-codes` and device endpoints exist only when GitHub sign-in is set up.

## Sandboxes

### `POST /v1/sandboxes`

```json theme={"theme":"css-variables"}
{
  "name": "api-tests",
  "spec": {
    "image": "",
    "cpus": 2,
    "memory_mb": 2048,
    "network": "allow",
    "allow": ["registry.npmjs.org"],
    "max_lifetime_seconds": 600
  },
  "token_hash": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
}
```

`token_hash` is the hex SHA-256 of an access token you make and keep; the host checks requests for the sandbox against it. `name` is optional: lowercase letters, digits and hyphens, up to 40 characters, starting and ending with a letter or digit. Leave it out and the server makes one up, like `amber-dune-42`. A bad name gets `400`; a name one of the account's running sandboxes already has gets `409`. Every `spec` field is optional. `network` is `none`, `allow` or `open`; with `allow` entries, it defaults to `allow`.

It answers `201` with the sandbox:

```json theme={"theme":"css-variables"}
{
  "id": "sbx_09459d27f28c808c",
  "name": "api-tests",
  "host": "lab-1",
  "host_id": "host_0b275ef1",
  "host_url": "https://10.0.0.12:7701",
  "host_key": "KTSv0bKYrAe5r4LFcTHw0mbqU55ZJIZu0j658LB5JKs=",
  "spec": { "network": "allow", "allow": ["registry.npmjs.org"] },
  "created_at": "2026-11-13T04:34:20.611Z",
  "owner": "ci",
  "account": "gh-147967875"
}
```

Then talk to the host at `host_url` over TLS, checking that its certificate carries `host_key`. A token over its limits gets `429` with a message saying which limit.

### `GET /v1/runs`

The newest 100, newest first. `?before=<RFC 3339 time>` returns the 100 before that time, for paging back.

```json theme={"theme":"css-variables"}
[
  {
    "id": "sbx_09459d27f28c808c",
    "name": "api-tests",
    "host": "lab-1",
    "host_id": "host_0b275ef1",
    "owner": "ci",
    "spec": { "network": "allow", "allow": ["registry.npmjs.org"] },
    "created_at": "2026-11-13T04:34:20.611Z",
    "ended_at": "2026-11-13T04:35:02.108Z",
    "end_reason": "destroyed",
    "exit_code": 0,
    "connections_allowed": 14,
    "connections_blocked": 1
  }
]
```

`ended_at` is missing while a sandbox runs. `name` is empty for sandboxes made before names. `end_reason` is `destroyed` (the CLI or someone destroyed it), `limit` (its token ran out of minutes), `gone` (its host stopped reporting it), `failed` (the host couldn't make it) or `expired` (it reached its maximum lifetime; it ends as soon as its host says so, and `DELETE /v1/sandboxes/{id}` still returns its signed record while the host keeps it, for an hour).

The host sends the last three when the sandbox ends. `exit_code` is the last command's exit code, 124 if its timeout stopped it. It's missing if no command ran or the last one couldn't finish. `connections_allowed` and `connections_blocked` count the connections its egress proxy let through and refused. All three are missing while a sandbox runs, for one that never started, and for one whose host is older than the server.

### `GET /v1/usage`

With a token, that token's day; with a session, the whole account's, without limits.

```json theme={"theme":"css-variables"}
{ "name": "ci", "day": "2026-11-13", "minutes_today": 41.5, "max_minutes_per_day": 600, "running": 1, "max_sandboxes": 2 }
```

## Hosts

### `GET /v1/hosts`

```json theme={"theme":"css-variables"}
[
  {
    "id": "host_0b275ef1",
    "name": "lab-1",
    "public_key": "KTSv0bKYrAe5r4LFcTHw0mbqU55ZJIZu0j658LB5JKs=",
    "fingerprint": "SHA256:qL3HdSf8UZXKjpVRma/Eo9jyxni9zZ8p6aDu+FxTJhA",
    "last_seen": "2026-11-13T04:40:02Z",
    "url": "https://10.0.0.12:7701",
    "online": true,
    "capacity": 20,
    "version": "v0.2.0",
    "running": 1,
    "joined": "2026-11-12T22:01:47Z"
  }
]
```

A host that joined but hasn't connected since the server started is listed with `online: false`.

### `POST /v1/join-codes`

```json theme={"theme":"css-variables"}
{ "code": "ej_k3v7q2mxa5t4wd6yr3bn5hc2pe", "expires": "2026-11-13T04:55:02Z" }
```

The code works once, for 15 minutes: `ephemera-host join --server URL CODE`.

## Tokens

### `GET /v1/tokens`

```json theme={"theme":"css-variables"}
[
  {
    "id": "tok_8c2e0b71",
    "name": "github-actions",
    "kind": "api",
    "created": "2026-11-13T04:41:00Z",
    "max_sandboxes": 4,
    "max_minutes_per_day": 600,
    "last_used": "2026-11-13T05:02:17Z"
  }
]
```

`last_used` is when the token last made a request. The server writes it at most once a minute per token, so it can be up to a minute behind. It's missing for a token that was never used.

### `POST /v1/tokens`

```json theme={"theme":"css-variables"}
{ "name": "github-actions", "max_sandboxes": 4, "max_minutes_per_day": 600 }
```

It answers `201` with the token, and its `secret`, which is never shown again:

```json theme={"theme":"css-variables"}
{ "id": "tok_8c2e0b71", "name": "github-actions", "kind": "api", "created": "2026-11-13T04:41:00Z", "max_sandboxes": 4, "max_minutes_per_day": 600, "secret": "eph_..." }
```

A limit of 0, or a missing one, means none. Names must be unique within the account.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.