# API reference

This reference is generated from the OpenAPI document. [API conventions](../api.md) explains what every operation shares: auth, IDs, lists, errors and idempotency.

| Page | What it covers |
|---|---|
| [auth](auth.md) | Sign in by emailed code or GitHub, sign out, and sign the CLI in from a browser. |
| [account](account.md) | The signed-in user and their org. |
| [catalog](catalog.md) | The sizes, regions, images and plans available on the platform. |
| [machines](machines.md) | Machines and everything done to one, including exec, files, the terminal, endpoints and usage. |
| [snapshots](snapshots.md) | Saved copies of a machine's disk. A paid add-on, billed per GiB-month from the same balance. |
| [ssh-keys](ssh-keys.md) | The org's SSH public keys. Any of them signs in to any of the org's machines through the gateway. |
| [api-keys](api-keys.md) | Keys for programs. The secret is shown once, when the key is created. |
| [billing](billing.md) | The plan, the prepaid balance, and what was used. |
| [Schemas](schemas.md) | The shape of every request and response body. |

## Every operation

| Operation | Request | Operation ID |
|---|---|---|
| [Email a sign-in code](auth.md#email-a-sign-in-code) | `POST /v1/auth/email/start` | `startEmailLogin` |
| [Exchange an emailed code for a session](auth.md#exchange-an-emailed-code-for-a-session) | `POST /v1/auth/email/verify` | `verifyEmailLogin` |
| [Start GitHub sign-in](auth.md#start-github-sign-in) | `GET /v1/auth/github/start` | `startGithubLogin` |
| [Finish GitHub sign-in](auth.md#finish-github-sign-in) | `GET /v1/auth/github/callback` | `completeGithubLogin` |
| [End the session](auth.md#end-the-session) | `POST /v1/auth/logout` | `logout` |
| [Start signing the CLI in](auth.md#start-signing-the-cli-in) | `POST /v1/auth/device/start` | `startDeviceLogin` |
| [Poll for the CLI's API key](auth.md#poll-for-the-clis-api-key) | `POST /v1/auth/device/token` | `pollDeviceLogin` |
| [Approve a CLI sign-in from the browser](auth.md#approve-a-cli-sign-in-from-the-browser) | `POST /v1/auth/device/approve` | `approveDeviceLogin` |
| [Who is signed in](account.md#who-is-signed-in) | `GET /v1/me` | `getMe` |
| [Get the org](account.md#get-the-org) | `GET /v1/org` | `getOrg` |
| [Rename the org](account.md#rename-the-org) | `PATCH /v1/org` | `updateOrg` |
| [Submit product feedback](account.md#submit-product-feedback) | `POST /v1/feedback` | `submitFeedback` |
| [List sizes](catalog.md#list-sizes) | `GET /v1/sizes` | `listSizes` |
| [List regions](catalog.md#list-regions) | `GET /v1/regions` | `listRegions` |
| [List images](catalog.md#list-images) | `GET /v1/images` | `listImages` |
| [List plans](catalog.md#list-plans) | `GET /v1/plans` | `listPlans` |
| [Create a machine](machines.md#create-a-machine) | `POST /v1/machines` | `createMachine` |
| [List machines](machines.md#list-machines) | `GET /v1/machines` | `listMachines` |
| [Get a machine](machines.md#get-a-machine) | `GET /v1/machines/{machine}` | `getMachine` |
| [Change a machine](machines.md#change-a-machine) | `PATCH /v1/machines/{machine}` | `updateMachine` |
| [Delete a machine](machines.md#delete-a-machine) | `DELETE /v1/machines/{machine}` | `deleteMachine` |
| [Start a machine](machines.md#start-a-machine) | `POST /v1/machines/{machine}/start` | `startMachine` |
| [Stop a machine](machines.md#stop-a-machine) | `POST /v1/machines/{machine}/stop` | `stopMachine` |
| [Restart a machine](machines.md#restart-a-machine) | `POST /v1/machines/{machine}/restart` | `restartMachine` |
| [List or follow a machine's events](machines.md#list-or-follow-a-machines-events) | `GET /v1/machines/{machine}/events` | `listMachineEvents` |
| [Get a machine's metrics](machines.md#get-a-machines-metrics) | `GET /v1/machines/{machine}/metrics` | `getMachineMetrics` |
| [Run a command in a machine](machines.md#run-a-command-in-a-machine) | `POST /v1/machines/{machine}/exec` | `execMachine` |
| [Read a file](machines.md#read-a-file) | `GET /v1/machines/{machine}/files` | `readMachineFile` |
| [Write a file](machines.md#write-a-file) | `PUT /v1/machines/{machine}/files` | `writeMachineFile` |
| [Delete a file or directory](machines.md#delete-a-file-or-directory) | `DELETE /v1/machines/{machine}/files` | `deleteMachineFile` |
| [List a directory](machines.md#list-a-directory) | `GET /v1/machines/{machine}/files/list` | `listMachineFiles` |
| [Open a terminal](machines.md#open-a-terminal) | `GET /v1/machines/{machine}/terminal` | `openMachineTerminal` |
| [List a machine's endpoints](machines.md#list-a-machines-endpoints) | `GET /v1/machines/{machine}/endpoints` | `listMachineEndpoints` |
| [Expose a port](machines.md#expose-a-port) | `PUT /v1/machines/{machine}/endpoints/{port}` | `putMachineEndpoint` |
| [Stop exposing a port](machines.md#stop-exposing-a-port) | `DELETE /v1/machines/{machine}/endpoints/{port}` | `deleteMachineEndpoint` |
| [Get what a machine used](machines.md#get-what-a-machine-used) | `GET /v1/machines/{machine}/usage` | `getMachineUsage` |
| [Snapshot a machine's disk](snapshots.md#snapshot-a-machines-disk) | `POST /v1/snapshots` | `createSnapshot` |
| [List snapshots](snapshots.md#list-snapshots) | `GET /v1/snapshots` | `listSnapshots` |
| [Get a snapshot](snapshots.md#get-a-snapshot) | `GET /v1/snapshots/{snapshot}` | `getSnapshot` |
| [Delete a snapshot](snapshots.md#delete-a-snapshot) | `DELETE /v1/snapshots/{snapshot}` | `deleteSnapshot` |
| [Add an SSH public key](ssh-keys.md#add-an-ssh-public-key) | `POST /v1/ssh-keys` | `createSshKey` |
| [List SSH keys](ssh-keys.md#list-ssh-keys) | `GET /v1/ssh-keys` | `listSshKeys` |
| [Remove an SSH key](ssh-keys.md#remove-an-ssh-key) | `DELETE /v1/ssh-keys/{ssh_key}` | `deleteSshKey` |
| [Create an API key](api-keys.md#create-an-api-key) | `POST /v1/api-keys` | `createApiKey` |
| [List API keys](api-keys.md#list-api-keys) | `GET /v1/api-keys` | `listApiKeys` |
| [Revoke an API key](api-keys.md#revoke-an-api-key) | `DELETE /v1/api-keys/{api_key}` | `deleteApiKey` |
| [Get the plan and the balance](billing.md#get-the-plan-and-the-balance) | `GET /v1/billing` | `getBilling` |
| [Claim the free trial](billing.md#claim-the-free-trial) | `POST /v1/trial/claim` | `claimTrial` |
| [Start the subscription checkout](billing.md#start-the-subscription-checkout) | `POST /v1/billing/checkout` | `startCheckout` |
| [Start a top-up](billing.md#start-a-top-up) | `POST /v1/billing/top-ups` | `startTopUp` |
| [Show auto top-up](billing.md#show-auto-top-up) | `GET /v1/billing/auto-top-up` | `getAutoTopUp` |
| [Turn auto top-up on, or change it](billing.md#turn-auto-top-up-on-or-change-it) | `PUT /v1/billing/auto-top-up` | `setAutoTopUp` |
| [Turn auto top-up off](billing.md#turn-auto-top-up-off) | `DELETE /v1/billing/auto-top-up` | `turnOffAutoTopUp` |
| [Open the Stripe customer portal](billing.md#open-the-stripe-customer-portal) | `POST /v1/billing/portal` | `openBillingPortal` |
| [List ledger entries](billing.md#list-ledger-entries) | `GET /v1/billing/ledger` | `listLedgerEntries` |
| [List usage by day](billing.md#list-usage-by-day) | `GET /v1/billing/usage` | `listUsage` |

## Error responses

Every error has a [Problem](schemas.md#problem) body. Switch on its `code`, never on its text. The table shows the example that each shared response carries in the OpenAPI document. One status can carry other codes, and the description of each operation names them.

| Status | Example `code` | Meaning |
|---|---|---|
| 400 | `invalid_request` | The request is malformed or a field is not valid. `errors` names each field. |
| 401 | `unauthenticated` | No API key or session, or it is not valid any more. |
| 402 | `insufficient_balance` | The org's balance does not cover this (`insufficient_balance`), or its subscription ended (`subscription_required`). |
| 403 | `limit_exceeded` | The caller is known but may not do this, for example because a plan limit is reached, the org is suspended, or the API key is read-only and the operation needs a full one (`read_only_key`). |
| 404 | `not_found` | There is no such resource in the caller's org. |
| 409 | `machine_not_running` | The request cannot be applied to the resource as it is now. |
| 411 | `length_required` | The request streams a body of unknown length, where the operation needs its `Content-Length`. |
| 413 | `payload_too_large` | The request body exceeds the maximum byte size allowed for this operation. |
| 429 | `rate_limited` | The rate limit for this API key, session or address is used up. |
| 503 | `no_capacity` | The platform cannot do this right now, for example because no host has room, the machine's host does not answer, or the machine's disk cannot be reached. |
| 500 | `internal` | Any other error. A 5xx is the platform's fault and is safe to retry with the same `Idempotency-Key`, except for an exec. There only the API's own problem document says that nothing ran, and `exec_outcome_unknown` (502) says that the command may have run. An answer to an exec that the API did not write (a 502 or 504 from a proxy or the gateway, whose body is not a problem document), or a connection that ends with no answer, says nothing about the command, so treat it as `exec_outcome_unknown`. |
