# API overview and authentication

> The flockvm REST API at flockvm.com/api/v1: create an API key, send it as a Bearer token, read errors, and see what the API does not cover yet.

- URL: https://flockvm.com/docs/api/overview
- Section: API
- Last updated: 2026-11-07

The flockvm API lets a script, a CI job or an agent do what you do in the dashboard: create VMs, start, stop, pause, resume and delete them, read their console, manage your SSH keys, your organization's environments and API keys. It follows the same rules as the dashboard, with the same roles, the same billing checks and the same audit log.

It is a JSON API over HTTPS. The [`flockvm` command-line tool](https://flockvm.com/docs/cli) is built on it, and the [flockvm MCP server](https://flockvm.com/docs/mcp) takes the same API keys and follows the same rules.

## Base URL

```text
https://flockvm.com/api/v1
```

Every path on this page and in the reference is relative to it: `GET /vms` is `GET https://flockvm.com/api/v1/vms`.

## Authentication

Every request carries an API key in the `Authorization` header:

```bash
curl https://flockvm.com/api/v1/me \
  -H "Authorization: Bearer $FLOCKVM_API_KEY"
```

```json
{
  "user": { "id": "usr_ada", "email": "ada@acme.dev", "name": "Ada Martin" },
  "organization": { "id": "org_acme", "slug": "acme", "name": "Acme" },
  "role": "owner",
  "api_key": {
    "id": "ak_717jfgkcbs63",
    "name": "laptop",
    "prefix": "flk_deknvy",
    "expires_at": "2027-02-05T09:12:40.118Z",
    "lane": "scoped-v1",
    "grandfathered": false,
    "scope": { "actions": ["*"], "environments": "*", "vms": "*", "ip_allowlist": [] }
  }
}
```

`GET /me` · Action: `account.read`

`GET /me` tells you who the key acts as: the user, the organization, the role, and the key itself with its [scope](https://flockvm.com/docs/api/api-keys): the actions it may take, the environments and VMs it reaches, the IP addresses it may be used from. Use it to check a key. `grandfathered` is `true` for a key created before scopes (full access, `"lane": "legacy"`).

Only that header counts. A key in the query string, in a cookie or in another header is ignored, and the request is refused with `401`.

### Create an API key

1. **Open API keys**

   Go to **Settings → API keys**, [flockvm.com/dashboard/settings/api-keys](https://flockvm.com/dashboard/settings/api-keys), in the organization the key is for.

2. **Name it and pick an expiry**

   Give it a **Name** that says what uses it (`laptop`, `ci-deploy`, `agent-batch`), up to 60 characters, and a description if you want. Pick when it **Expires**: in 1 day, 7 days, 30 days, 90 days (the default), 1 year, at a date up to a year ahead, or never.

3. **Pick what it can do**

   A preset (**Read only**, **Use existing VMs**, **Create and use VMs**, **Full access**) or **Custom** actions, and if you want, the environments or VMs it reaches and the IP addresses it may be used from. See [API keys and scopes](https://flockvm.com/docs/api/api-keys).

4. **Create and copy it**

   Click **Create key**. The key is shown once, with a `curl` line to try it. Copy it and store it like a password, in a password manager or your CI's secrets. Then click **Done, I copied it**.

![Settings → API keys, with a key just created](https://flockvm.com/docs/screenshots/api-key-created.webp "The key is shown once: flockvm keeps only a hash of it.")

A key looks like `flk_` followed by 40 lowercase letters and digits. flockvm stores only its SHA-256 hash, its first characters and its last four: nobody, flockvm included, can show it again. If you lose it, revoke it and create another.

Every member can create keys for themselves, unless the organization's [key policy](https://flockvm.com/docs/api/api-keys#organization-key-policy) keeps that to owners and admins. An organization can have 50 live keys at most; expired keys don't count.

### What a key can do

A key belongs to one organization and to the user who created it. It acts as that user, and can do what **both** its scope and that user's role in that organization allow, **at the time of each request**:

- Its scope: the [actions](https://flockvm.com/docs/api/api-keys#actions) it was created with (a preset such as **Create and use VMs**, or actions one by one), the environments and VMs it reaches, the IP addresses it may be used from. A route its actions do not cover answers `403 insufficient_scope`.
- Its user's role: an owner's or admin's full-access key can do what an owner or admin can do in the dashboard. A member's key can do what a member can do: create and drive VMs, read environments, but not change environments or reveal their values, whatever its actions. See [Members and roles](https://flockvm.com/docs/team/members#permissions).
- If your role changes, your keys follow at once: an admin made member gets a member's key.
- If you leave the organization or are removed from it, your keys in it stop working. If you delete your account, all your keys do.
- A key reaches one organization only. To script several organizations, create a key in each.

Your saved SSH keys belong to your account: a key reads and changes yours, whatever the organization.

### Expiry and revocation

An expired or revoked key is refused with `401` from the next request on. Its user gets a mail 7 to 8 days and 24 to 48 hours before it expires (a little later if the daily send is delayed). To revoke a key, open **Settings → API keys** and click **Revoke**, then **Revoke key**. To change a key's secret without changing anything else, rotate it, with a grace period for the old secret if you want: see [Rotate a key](https://flockvm.com/docs/api/api-keys#rotate-a-key).

![The API keys page with the keys of the organization](https://flockvm.com/docs/screenshots/api-keys.webp "Owners and admins see every key of the organization, with who created it, when it was last used and when it expires.")

| Role                 | Sees and revokes                                    |
| -------------------- | --------------------------------------------------- |
| **Owner**, **Admin** | Every key of the organization, with who created it. |
| **Member**           | Their own keys.                                     |

Each key shows its scope, when it was created, when it was last used and from which IP address (updated at most every 10 minutes), and when it expires. Expired keys stay listed, greyed, until someone revokes them or 30 days pass. 30 days after it was revoked or expired, a key is deleted: from then on it is refused as "not a valid flockvm API key", like a key that never existed.

When a member leaves or is removed from the organization, deletes their account, or the organization is deleted, their keys in it are deleted at once: they are refused as not valid too.

A key with the `api_key.read` and `api_key.write` actions can list, create, rotate and revoke keys over the API, within what it has itself: see [Manage keys over the API](https://flockvm.com/docs/api/api-keys#manage-keys-over-the-api).

> **Warning: A key in a VM can drive your whole organization's VMs.** Anyone or anything that reads a key can act as you: list, create, stop and delete every VM of the organization, and, with an owner's or admin's key, read and change its environments and reveal their values. A coding agent running without permission prompts in a VM can read any file and environment variable of that VM.
>
> - Don't put an API key in an [environment](https://flockvm.com/docs/vms/environments) or a VM unless the agent there really needs to create or drive VMs.
> - When it does, create a key for that job only, with the least it needs: **Create and use VMs** deletes only the VMs it created, and a key can be restricted to one environment, to its own VMs and to some IP addresses. Use a member's account if possible (a member's key cannot reveal environment values), a short expiry, and revoke it when the job is done.
> - Never commit a key to a repository. Revoke it at once if it leaks: requests with it stop working immediately.

## Requests and responses

- Request and response bodies are JSON. Send `Content-Type: application/json` with a body. A body must be a JSON object; an empty body counts as `{}`.
- A field the API does not know is refused with `400` and `field` set to that field, so a typo never goes unnoticed.
- Fields are `snake_case`. Times are ISO 8601 strings in UTC, such as `2026-11-01T06:18:42.918Z`. A value that is absent is `null`, never left out.
- Ids carry a prefix: `vm_…` for VMs, `env_…` for environments, `key_…` for SSH keys, `ak_…` for API keys.
- Lists come whole, without pagination, in an object: `{"vms": […]}`.
- A thing of another organization (or another user's SSH key) answers `404`, exactly like a thing that does not exist.
- Every answer has `Cache-Control: no-store`.
- A method a path does not take answers `405` with an `Allow` header; `OPTIONS` answers `204` with the same header. `HEAD` works wherever `GET` does.

There is no rate limit yet, except on starts during the [free trial](https://flockvm.com/docs/billing/trial): 5 creates, starts and resumes a minute, 25 an hour and 75 a day (`429 trial_rate_limited`). Don't poll faster than you need: once every few seconds is plenty to wait for a VM.

## Errors

An error is an HTTP status and a JSON body:

```json
{
  "error": {
    "code": "bad_request",
    "message": "Name: 1 to 40 characters, lowercase letters, digits and dashes.",
    "field": "name"
  }
}
```

`message` is written for people: show it as it is. `field`, when present, names the body field, path part or query parameter the error is about. Write your code against the status and `code`, never against `message`, which may change.

| Status | `code`                        | When                                                                                                                                                                                                                                                 |
| ------ | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 400    | `bad_request`                 | The body or the query is invalid: not JSON, not an object, too large, an unknown field, a wrong type, or a rule of the dashboard (a name, a size, a path).                                                                                           |
| 401    | `unauthorized`                | No key, a malformed or unknown key, a revoked or expired key, a rotated key's old secret after its grace period, or a key deleted because its user left the organization. The answer has `WWW-Authenticate: Bearer realm="flockvm"`.                 |
| 403    | `insufficient_scope`          | The key's actions do not cover this route. `field` is the action it needs, as in `WWW-Authenticate: Bearer realm="flockvm", error="insufficient_scope", scope="vm.create"`. See [API keys and scopes](https://flockvm.com/docs/api/api-keys#errors). |
| 403    | `ip_not_allowed`              | The request comes from an IP address the key's allowlist, or the organization's, does not include.                                                                                                                                                   |
| 403    | `forbidden`                   | Your role does not allow it, the organization is suspended, or billing stops it (create, start and resume need the free trial started or the plan in order).                                                                                         |
| 403    | `trial_size_not_allowed`      | During the free trial: a `large` or `xlarge` VM. The trial gives `small` and `default`.                                                                                                                                                              |
| 404    | `not_found`                   | No such VM, environment, key or path, or one of another organization.                                                                                                                                                                                |
| 405    | `method_not_allowed`          | The path does not take this method. See the `Allow` header.                                                                                                                                                                                          |
| 409    | `conflict`                    | The state does not allow it: pause a stopped VM, drive a GitHub Actions runner VM, delete the default environment, a name already taken, 50 API keys already.                                                                                        |
| 409    | `api_key_expired`             | Rotating an API key that has expired. Create a new one.                                                                                                                                                                                              |
| 409    | `capacity`                    | The host has no room right now. On create, for this size (`field` is `size`); on start, resume or pause, for this VM or its memory snapshot (no `field`).                                                                                            |
| 429    | `trial_vm_limit`              | During the free trial: 2 VMs are already running or starting, CI runner VMs included. Pause or stop one.                                                                                                                                             |
| 429    | `trial_rate_limited`          | During the free trial: more than 5 creates, starts and resumes in a minute, 25 in an hour or 75 in a day. Wait, then try again.                                                                                                                      |
| 429    | `trial_compute_limit_reached` | During the free trial: its 25 hours of VM time are used. Start the paid plan in **Settings → Billing**.                                                                                                                                              |
| 500    | `internal`                    | Something failed on flockvm's side. Try again; write to <hello@flockvm.com> if it lasts.                                                                                                                                                             |
| 503    | `unavailable`                 | A flockvm host or the billing did not answer. Try again in a moment.                                                                                                                                                                                 |
| 503    | `not_configured`              | The API, or the feature you called, is not set up on this deployment.                                                                                                                                                                                |

The `trial_…` codes end with the trial: once the plan is paid, none of them applies. The fifth trial code, `trial_not_eligible`, never comes from the API: it shows in **Settings → Billing** when the organization, its owner or the card already had a trial. See [Free trial](https://flockvm.com/docs/billing/trial#when-a-limit-is-reached).

What each `401` says:

| Case                                                                                                                                     | `message`                                                                               |
| ---------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
| No `Authorization` header                                                                                                                | "Send your API key as Authorization: Bearer flk\_…. Create one in Settings › API keys." |
| Not a flockvm key, an unknown one, or a deleted one (its user left the organization, or it was revoked or expired more than 30 days ago) | "This is not a valid flockvm API key."                                                  |
| Revoked                                                                                                                                  | "This API key was revoked."                                                             |
| Expired                                                                                                                                  | "This API key has expired. Create a new one in Settings › API keys."                    |

And each `403` of a key's scope:

| Case                                                            | `message`                                                                      |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| A route the key's actions do not cover                          | "This API key cannot create VMs: it needs vm.create.", with the route's action |
| An address outside the key's or the organization's IP allowlist | "This API key cannot be used from this IP address."                            |

```bash
curl -i https://flockvm.com/api/v1/me
```

```text
HTTP/1.1 401 Unauthorized
www-authenticate: Bearer realm="flockvm"

{"error":{"code":"unauthorized","message":"Send your API key as Authorization: Bearer flk_…. Create one in Settings › API keys."}}
```

A path the API does not have is a JSON `404` too:

```json
{ "error": { "code": "not_found", "message": "No such API path: GET /api/v1/nothing." } }
```

## Audit log

Every change made with a key is recorded in the organization's [audit log](https://flockvm.com/docs/team/audit-log) exactly as the same change in the dashboard: same event, the key's user as the actor, and the key in the event's details (`via: "api_key"`, `apiKeyId`, `apiKeyName`). The log adds "via the API key laptop" after the event, for example "Ada Martin created VM web-1 · via the API key laptop". Changes made through the MCP server read "via MCP with the API key …".

Changes to keys are recorded too: `api_key.created`, `api_key.updated`, `api_key.rotated`, `api_key.revoked`, and `api_key.policy_updated` for the organization's key policy. Reads are not recorded, except revealing an environment's values, nor are requests a key's scope refused.

## Endpoints

Each route needs one [action](https://flockvm.com/docs/api/api-keys#actions) of the key, in the same order as the methods.

| Method                   | Path                                            | Action                                                       | What it does                                                                                                         |
| ------------------------ | ----------------------------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------- |
| `GET`                    | `/me`                                           | `account.read`                                               | The user, organization, role and key the request acts as.                                                            |
| `GET`                    | `/regions`, `/sizes`, `/images`                 | `account.read`                                               | What you can create. See [Catalog](https://flockvm.com/docs/api/catalog).                                            |
| `GET`, `POST`            | `/vms`                                          | `vm.read`, `vm.create`                                       | List and create VMs. See [VMs](https://flockvm.com/docs/api/vms).                                                    |
| `GET`, `DELETE`          | `/vms/{id}`                                     | `vm.read`, `vm.delete-own` (or `vm.delete`)                  | Get or delete a VM.                                                                                                  |
| `POST`                   | `/vms/{id}/start`, `/stop`, `/pause`, `/resume` | `vm.power`                                                   | Drive a VM.                                                                                                          |
| `GET`                    | `/vms/{id}/logs`                                | `vm.logs`                                                    | A VM's console log.                                                                                                  |
| `GET`, `POST`            | `/ssh-keys`                                     | `ssh_key.read`, `ssh_key.write`                              | Your account's SSH keys. See [SSH keys](https://flockvm.com/docs/api/ssh-keys).                                      |
| `DELETE`                 | `/ssh-keys/{id}`                                | `ssh_key.write`                                              | Remove one.                                                                                                          |
| `GET`, `POST`            | `/environments`                                 | `environment.read`, `environment.write`                      | List and create environments. See [Environments](https://flockvm.com/docs/api/environments).                         |
| `GET`, `PATCH`, `DELETE` | `/environments/{ref}`                           | `environment.read`, `environment.write`, `environment.write` | Get, change or delete one.                                                                                           |
| `PUT`, `DELETE`          | `/environments/{ref}/vars/{KEY}`                | `environment.write`                                          | Set or delete a variable.                                                                                            |
| `PUT`, `DELETE`          | `/environments/{ref}/files/{path}`              | `environment.write`                                          | Set or delete a secret file.                                                                                         |
| `POST`                   | `/environments/{ref}/reveal`                    | `environment.reveal`                                         | Read the values (owners and admins).                                                                                 |
| `GET`, `POST`            | `/api-keys`                                     | `api_key.read`, `api_key.write`                              | List and create API keys. See [API keys and scopes](https://flockvm.com/docs/api/api-keys#manage-keys-over-the-api). |
| `GET`, `PATCH`, `DELETE` | `/api-keys/{id}`                                | `api_key.read`, `api_key.write`, `api_key.write`             | Get, rename or revoke one.                                                                                           |
| `POST`                   | `/api-keys/{id}/rotate`                         | `api_key.write`                                              | Give it a new secret.                                                                                                |

## Not in the API yet

These stay in the dashboard for now:

- The organization's API key policy: set it in **Settings → API keys** (Enterprise).
- Members and invitations, organization settings, the audit log.
- Billing: the plan, the card, the wallet, usage and invoices.
- GitHub Actions runners and the GitHub connection. Runner VMs show up in `GET /vms`, but they can't be driven: flockvm creates and deletes them for each job.
- The organization's Anthropic API key for agent credentials.

## Next steps

- [API keys and scopes](https://flockvm.com/docs/api/api-keys): Give each key only what it needs.
- [VMs](https://flockvm.com/docs/api/vms): Create a VM, wait for it, SSH in, delete it.
- [Catalog](https://flockvm.com/docs/api/catalog): Regions, sizes and images you can use.
- [Environments](https://flockvm.com/docs/api/environments): Variables and secret files for new VMs.
- [SSH keys](https://flockvm.com/docs/api/ssh-keys): Save the keys new VMs get.
