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

# API Overview

> Authenticate against the Vers /api/v2 REST API, work with durable operations, stream NDJSON events, and handle errors.

The Vers REST API exposes `/api/v2` endpoints for creating, executing commands
in, checkpointing, branching, sleeping, waking, and deleting computers and
projects. Every endpoint reference in the sidebar is generated directly from
the server's OpenAPI specification.

## Base URL

```text theme={"theme":{"light":"min-light","dark":"min-dark"}}
https://api.vers.sh
```

All paths begin with `/api/v2`. For ready-to-run client wrappers, see the
[Python & TypeScript cookbook](https://docs.vers.sh/guides/python-and-typescript.md).

## Authentication

Pass your API key as a Bearer token in the `Authorization` header:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
curl -fsSL https://api.vers.sh/api/v2/whoami \
  -H "Authorization: Bearer $VERS_API_KEY"
```

Create a key from the [Vers dashboard](https://docs.vers.sh/get-api-key.md). All endpoints require a
Bearer token except the unauthenticated liveness check
(`GET /api/v2/system/health`) and public repository reads
(`GET /api/v2/public/repositories*`).

## Durable operations and idempotency

Long-running lifecycle mutations execute asynchronously and require a
caller-generated UUID in the `Idempotency-Key` header:

| Pattern | Endpoints | Response |
| - | - | - |
| **Async (requires `Idempotency-Key`)** | Create/restore computer, checkpoint computer, delete computer, import/upload image, restore project stack | `202 Accepted` + `Location` header + `Operation` |
| **Synchronous** | Branch computers, bounded `exec`, file read/write, sleep, wake | Final result returned directly (`200`, `201`, or `204`) |

For asynchronous mutations:

![Durable operation lifecycle: POST with Idempotency-Key returns 202 Accepted pending, observed by polling or streaming /events until succeeded or failed.](https://mintcdn.com/vers/mkK48e0NywTcvNla/images/diagrams/durable-operations-light.svg?fit=max\&auto=format\&n=mkK48e0NywTcvNla\&q=85\&s=ba794c57c76316ffe78bb3f54e4241f2)

1. Send a caller-generated UUID in the `Idempotency-Key` header.
2. Receive `202 Accepted` with an `Operation` payload (or one `Operation` per
   checkpoint on project restores).
3. Poll `GET /api/v2/operations/{operation_id}` or stream events from
   `/events` until `status` reaches `succeeded`, `failed`, or `quarantined`.

Replaying the exact same request with the same `Idempotency-Key` converges on
the original operation rather than creating duplicate resources.

## Streaming operation events (NDJSON)

To follow an operation without polling, stream newline-delimited JSON
(`application/x-ndjson`) from `/events`:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
curl -fsSL -N \
  "https://api.vers.sh/api/v2/operations/$OPERATION_ID/events?cursor=0&follow=true" \
  -H "Authorization: Bearer $VERS_API_KEY"
```

Each line is one `OperationEvent`:

* `{"type": "snapshot", "operation": {...}}` — durable operation state at `operation.cursor`.
* `{"type": "gap", "requested_cursor": ..., "available_cursor": ...}` — emitted if intermediate stages were compacted before your cursor.
* `{"type": "end", "cursor": ..., "terminal": true|false}` — stream ended (`terminal: true` means the operation reached a final state).

If your connection drops, reconnect with `cursor=<last_seen_cursor>&follow=true`.

## Error codes and retry guidance

Failed asynchronous operations carry a structured `failure` object:
`{"code": "<machine_code>", "message": "<human_detail>"}`.

| HTTP Status | Meaning | Caller action |
| - | - | - |
| `400` | Invalid request body, parameter, or cursor ahead of durable progress | Fix the request payload or parameters; do not retry unchanged. |
| `401` | Missing or invalid Bearer API key | Verify `Authorization: Bearer $VERS_API_KEY`. |
| `403` | Key lacks access to the target organization, project, or resource | Use an org-scoped key or a key granted access to that project. |
| `404` | Resource does not exist or is outside the caller's scope | Confirm the UUID and project/org scope. |
| `408` | Guest process exceeded `timeout_secs` | Increase `timeout_secs` (up to `3600`) or use streaming exec. |
| `409` | State or idempotency conflict (e.g. reused `Idempotency-Key` with a different body, or concurrent lifecycle mutation) | Wait for the active mutation to finish, or use a fresh UUID for a different payload. |
| `413` | Payload too large (e.g. file write exceeds `16 MiB`) | Split large transfers or bake large assets into an OCI image. |
| `422` | Guest execution or file operation rejected (unreadable/unwritable path, binary not found) | Check guest path permissions and executable path. |
| `502` / `503` | Transient runtime unavailability, capacity exhaustion, or ambiguous admission | Safe to retry with backoff — **reuse the exact same `Idempotency-Key`** on mutations. |


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