# REST API

Source: https://bflops.com/docs/api

Rent GPU machines from your own code over plain HTTP and JSON.



The REST API does everything the site does for machines: list, price, start, watch, extend and stop. Every request needs an [API key](/docs/api-keys).

## Base URL [#base-url]

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

## Authentication [#authentication]

Send your key in the `Authorization` header:

```bash title="On your computer"
curl https://bflops.com/api/v1/balance \
  -H "Authorization: Bearer bf_..."
```

`x-api-key: bf_...` works too. A missing or wrong key gets `401` with the code `unauthorized`.

## Rent a machine in four calls [#rent-a-machine-in-four-calls]

<Steps>
  <Step>
    ### Find a machine [#find-a-machine]

    ```bash
    curl "https://bflops.com/api/v1/machines?model=RTX%204090&limit=1" \
      -H "Authorization: Bearer $BFLOPS_KEY"
    ```

    Take `id` from the first entry of `data`. See [Machines](/docs/api/machines).
  </Step>

  <Step>
    ### Get a quote [#get-a-quote]

    ```bash
    curl https://bflops.com/api/v1/quotes \
      -H "Authorization: Bearer $BFLOPS_KEY" \
      -H "Content-Type: application/json" \
      -d '{"offer_id": "s4821"}'
    ```

    Take `quote.id`. It is good for 60 seconds. See [Quotes](/docs/api/quotes).
  </Step>

  <Step>
    ### Start it [#start-it]

    ```bash
    curl https://bflops.com/api/v1/rentals \
      -H "Authorization: Bearer $BFLOPS_KEY" \
      -H "Content-Type: application/json" \
      -H "Idempotency-Key: first-run-001" \
      -d "{\"quote_id\": \"q_...\", \"ssh_key\": \"$(cat ~/.ssh/id_ed25519.pub)\", \"ttl_hours\": 4}"
    ```

    Take `rental.id`. Its `status` is `starting`. See [Rentals](/docs/api/rentals).
  </Step>

  <Step>
    ### Wait, then connect [#wait-then-connect]

    Read `GET /rentals/{id}` every 10 seconds until `status` is `running`, then run its `ssh` command. Stop it with `POST /rentals/{id}/stop`.
  </Step>
</Steps>

## Conventions [#conventions]

* **JSON** in and out, field names in `snake_case`. Send `Content-Type: application/json` with a body; a body is at most 16 KiB.
* **Money** is a string of US dollars, such as `"0.44"` or `"12.075031"`. Parse it as a decimal, never as a float.
* **Times** are ISO 8601 in UTC, such as `"2026-11-27T09:30:00.000Z"`.
* **Prices** are always yours, with our fee in them.
* Lists come in `data`, newest or cheapest first.

## Rate limits [#rate-limits]

Each key may make 120 reads and 30 changes a minute. Quotes, starts, stops and extends are changes. Over that, you get `429` with a `Retry-After` header in seconds: wait that long, then retry.

## Safe retries [#safe-retries]

`POST /rentals` and `POST /rentals/{id}/extend` take an `Idempotency-Key` header: 8 to 64 letters, digits, `_` or `-`. Send the same key again within 24 hours and you get the first answer back, with the header `Idempotent-Replayed: true`, and nothing starts twice. Use a new key for each new start.

## Endpoints [#endpoints]

| Method | Path                                                        | What it does                        |
| ------ | ----------------------------------------------------------- | ----------------------------------- |
| `GET`  | [`/machines`](/docs/api/machines#list-machines)             | Machines on the list, with filters  |
| `GET`  | [`/machines/{id}`](/docs/api/machines#one-machine)          | One machine                         |
| `GET`  | [`/clusters`](/docs/api/machines#list-clusters)             | Clusters on the list                |
| `GET`  | [`/clusters/{id}`](/docs/api/machines#one-cluster)          | One cluster                         |
| `POST` | [`/quotes`](/docs/api/quotes)                               | Your price, held 60 seconds         |
| `POST` | [`/rentals`](/docs/api/rentals#start-a-rental)              | Start what a quote priced           |
| `GET`  | [`/rentals`](/docs/api/rentals#list-rentals)                | Your rentals                        |
| `GET`  | [`/rentals/{id}`](/docs/api/rentals#one-rental)             | One rental with its events          |
| `POST` | [`/rentals/{id}/stop`](/docs/api/rentals#stop-a-rental)     | Stop it; billing ends at once       |
| `POST` | [`/rentals/{id}/extend`](/docs/api/rentals#extend-a-rental) | More time before it stops by itself |
| `GET`  | [`/balance`](/docs/api/balance)                             | Your balance and how to top it up   |

Errors are listed in [Errors](/docs/api/errors). The whole API is in English.
