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

# HTTP API

> The JSON API behind the CLI, for building your own tooling.

The CLI is a client of a small JSON API. You can call it directly to build your
own tooling. It is versioned under `/v1` and served from `https://proofpod.dev`.

> [!NOTE]
>
> The API is young. Endpoints listed here are stable enough to script
> against; fields may be added.

## Authentication

Send an API token as a bearer token:

```console theme={null}
$ curl -H "Authorization: Bearer $PROOFPOD_TOKEN" https://proofpod.dev/v1/me
```

Create tokens with `pp token create` or in the dashboard.

## Errors

Failures return a non-200 status and a body of the form:

```json theme={null}
{"error": {"code": "credit_exhausted", "message": "You have used all of your credit for this month. …"}}
```

| Status | Meaning |
| - | - |
| 400 | The request is malformed; `message` says which field. |
| 401 | Missing or invalid token. |
| 402 | No credit left. |
| 404 | No such run, workspace or endpoint. |
| 409 | The workspace is busy. |
| 426 | The client is too old. |
| 429 | Too many concurrent runs, or rate limited. |

## Public endpoints

| Method | Path | Returns |
| - | - | - |
| `GET` | `/v1/health` | `{"ok": true}` |
| `GET` | `/v1/pricing` | Current prices, minimums and limits. |
| `GET` | `/v1/environments` | Prebuilt environments and the default versions. |

## Account

| Method | Path | Returns |
| - | - | - |
| `GET` | `/v1/me` | Account, plan and remaining credit. |
| `GET` | `/v1/usage` | Monthly and daily usage roll-ups. |
| `GET` | `/v1/tokens` | Your API tokens, without secrets. |
| `POST` | `/v1/tokens` | Body `{"name": "…"}`. Returns the new token once. |
| `DELETE` | `/v1/tokens/{id}` | Revokes a token. |

Money is reported in **nano-dollars** (`_nusd` fields): 1,000,000,000 is one
dollar.

## Runs

| Method | Path | Returns |
| - | - | - |
| `GET` | `/v1/runs?limit=20` | Recent runs, newest first. |
| `GET` | `/v1/runs/{id}` | One run. |
| `GET` | `/v1/runs/{id}/events?after=N` | Output batches with sequence number greater than `N`, and the run's current state. |
| `POST` | `/v1/runs/{id}/cancel` | Requests cancellation. |
| `GET` | `/v1/workspaces` | Your workspaces. |
| `DELETE` | `/v1/workspaces/{key}` | Deletes a workspace and its caches. |

### Run object

```json theme={null}
{
  "id": "run-19f3a2c4d5e6f7a",
  "status": "finished",
  "exit_code": 0,
  "reason": null,
  "tool": "lake",
  "args": ["build"],
  "workspace": "formalization-3fa9c21b7e",
  "resources": {"cpu": 4, "memory_mib": 16384, "timeout_s": 3600},
  "environment": {"lean": "v4.36.0", "mathlib": "v4.36.0", "prebuilt_mathlib": true},
  "usage": {"cpu_s": 111.2, "mem_gib_s": 21.9, "wall_s": 41.0, "peak_mem_bytes": 1288490188},
  "billable": {"cpu_s": 111.2, "mem_gib_s": 21.9, "wall_s": 41.0},
  "cost_nusd": 4303000,
  "cost": "$0.0043"
}
```

`status` is one of `queued`, `preparing` (an environment is being built),
`starting`, `running`, `finished`, `cancelled`, `error`. A `finished` run has an
`exit_code`; `reason` is set to `timeout` or `out_of_memory` when ProofPod
stopped it. An `error` run never produced an exit code and has an `error`
message.

### Following output

Poll `events` with the highest sequence number you have seen:

```json theme={null}
{
  "run": {"id": "run-…", "status": "running", "phase": "command"},
  "events": [
    {"seq": 1, "chunks": [["o", "QnVpbHQgRGVtbwo="], ["e", "d2FybmluZwo="]]}
  ]
}
```

Each chunk is `[stream, base64 data]` where stream is `o` (stdout), `e`
(stderr) or `s` (a status message from ProofPod, as JSON). The run is over when
`status` is terminal and a poll returns no further events.

## Starting runs

Starting a run involves uploading a sync archive first, which is what the CLI
is for. If you need to start runs from your own program, invoke the CLI:

```python theme={null}
import subprocess

result = subprocess.run(
    ["pp", "--quiet", "lake", "env", "lean", "Candidate.lean"],
    capture_output=True, text=True,
)
accepted = result.returncode == 0
```


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