# Reservations API

> The reservations endpoints, each in TypeScript, Python, the CLI and curl.

The reservations endpoints, each in TypeScript, Python, the CLI and curl.

## Set up

* TypeScript

  ```bash
  npm install @limitry/sdk
  export LIMITRY_API_KEY="lim_test_…"
  ```

* Python

  ```bash
  pip install limitry
  export LIMITRY_API_KEY="lim_test_…"
  ```

* CLI

  ```bash
  npm install -g @limitry/cli
  limitry login
  ```

* curl

  ```bash
  export LIMITRY_API_KEY="lim_test_…"
  ```

To pass the key yourself, use `createClient({ apiKey: key })` in TypeScript or `Limitry(api_key=key)` in Python.

## Get a reservation

`GET /v1/reservations/{reservationId}`[ Try it in the API playground (opens in a new tab)](https://api.limitry.com/v1/docs#tag/reservations/GET/reservations/{reservationId})

Scope: `checks:write`.

Returns a reservation as it stands: held, committed, released or expired, with what it reserved and what it finally used.

* TypeScript

  ```ts
  import { createClient } from "@limitry/sdk";

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  const reservation = await limitry.reservations.get("<reservation-id>");
  console.log(reservation);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  reservation = limitry.reservations.get("<reservation-id>")
  print(reservation)
  ```

* CLI

  ```bash
  limitry reservations get '<reservation-id>'
  ```

* curl

  ```bash
  curl -X GET "https://api.limitry.com/v1/reservations/<reservation-id>" \
    -H "Authorization: Bearer $LIMITRY_API_KEY"
  ```

**Returns:**

```json
{
  "id": "rsv_WyJ1c2VyIiwidXNlcl8xMjMiXQ_9f2c4e1a7b3d4c8e9a0f1b2c3d4e5f6a",
  "status": "committed",
  "reserved": 5,
  "cost": 3,
  "expiresAt": "2026-11-06T12:05:00.000Z"
}
```

| Field                                  | Description           |
| -------------------------------------- | --------------------- |
| `reservationId` string, path, required | The reservation's ID. |

More about this endpoint

A reservation past its expiry that nobody committed or released reads as expired. Reading it changes nothing.

## Extend a reservation

`POST /v1/reservations/{reservationId}/extend`[ Try it in the API playground (opens in a new tab)](https://api.limitry.com/v1/docs#tag/reservations/POST/reservations/{reservationId}/extend)

Scope: `checks:write`.

Keeps a reservation open for longer work, so it expires `ttlSeconds` from now.

* TypeScript

  ```ts
  import { createClient } from "@limitry/sdk";

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  const result = await limitry.reservations.extend("<reservation-id>", {
    ttlSeconds: 600,
  });
  console.log(result);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  result = limitry.reservations.extend("<reservation-id>", ttl_seconds=600)
  print(result)
  ```

* CLI

  ```bash
  limitry reservations extend '<reservation-id>' --ttl-seconds 600
  ```

* curl

  ```bash
  curl -X POST "https://api.limitry.com/v1/reservations/<reservation-id>/extend" \
    -H "Authorization: Bearer $LIMITRY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"ttlSeconds":600}'
  ```

**Returns:**

```json
{
  "id": "rsv_WyJ1c2VyIiwidXNlcl8xMjMiXQ_9f2c4e1a7b3d4c8e9a0f1b2c3d4e5f6a",
  "status": "committed",
  "reserved": 5,
  "cost": 3,
  "expiresAt": "2026-11-06T12:05:00.000Z"
}
```

| Field                                  | Description                                                                 |
| -------------------------------------- | --------------------------------------------------------------------------- |
| `reservationId` string, path, required | The reservation's ID.                                                       |
| `ttlSeconds` number                    | Seconds from now until the reservation expires. Default: 300. At most 3600. |

More about this endpoint

Call it again as a heartbeat while the work runs. You can only extend a reservation that’s still held. We cache its API key check briefly for speed. A revoked key can keep working here for up to 60 seconds.

## Commit a reservation

`POST /v1/reservations/{reservationId}/commit`[ Try it in the API playground (opens in a new tab)](https://api.limitry.com/v1/docs#tag/reservations/POST/reservations/{reservationId}/commit)

Scope: `checks:write`.

Commits a reservation with the amount actually used (`cost`).

* TypeScript

  ```ts
  import { createClient } from "@limitry/sdk";

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  const result = await limitry.reservations.commit("<reservation-id>", {
    cost: 3,
  });
  console.log(result);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  result = limitry.reservations.commit("<reservation-id>", cost=3)
  print(result)
  ```

* CLI

  ```bash
  limitry reservations commit '<reservation-id>' --cost 3
  ```

* curl

  ```bash
  curl -X POST "https://api.limitry.com/v1/reservations/<reservation-id>/commit" \
    -H "Authorization: Bearer $LIMITRY_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"cost":3}'
  ```

**Returns:**

```json
{
  "id": "rsv_WyJ1c2VyIiwidXNlcl8xMjMiXQ_9f2c4e1a7b3d4c8e9a0f1b2c3d4e5f6a",
  "status": "committed",
  "reserved": 5,
  "cost": 3,
  "expiresAt": "2026-11-06T12:05:00.000Z"
}
```

| Field                                  | Description               |
| -------------------------------------- | ------------------------- |
| `reservationId` string, path, required | The reservation's ID.     |
| `cost` number, required                | The amount actually used. |

More about this endpoint

If `cost` is less than the amount reserved, the rest goes back at once. If it’s more, Limitry charges the whole `cost`, since the work happened. A commit up to 24 hours after the reservation expired still charges `cost`. Repeating a commit with the same `cost` returns the same result, and a different `cost` gets a 400. Committing a released reservation gets a 409. We cache its API key check briefly for speed. A revoked key can keep working here for up to 60 seconds.

## Release a reservation

`POST /v1/reservations/{reservationId}/release`[ Try it in the API playground (opens in a new tab)](https://api.limitry.com/v1/docs#tag/reservations/POST/reservations/{reservationId}/release)

Scope: `checks:write`.

Gives the whole reservation back, because the work didn’t happen.

* TypeScript

  ```ts
  import { createClient } from "@limitry/sdk";

  // Uses the LIMITRY_API_KEY environment variable.
  const limitry = createClient();
  const result = await limitry.reservations.release("<reservation-id>");
  console.log(result);
  ```

* Python

  ```python
  from limitry import Limitry

  # Uses the LIMITRY_API_KEY environment variable.
  limitry = Limitry()
  result = limitry.reservations.release("<reservation-id>")
  print(result)
  ```

* CLI

  ```bash
  limitry reservations release '<reservation-id>'
  ```

* curl

  ```bash
  curl -X POST "https://api.limitry.com/v1/reservations/<reservation-id>/release" \
    -H "Authorization: Bearer $LIMITRY_API_KEY"
  ```

**Returns:**

```json
{
  "id": "rsv_WyJ1c2VyIiwidXNlcl8xMjMiXQ_9f2c4e1a7b3d4c8e9a0f1b2c3d4e5f6a",
  "status": "committed",
  "reserved": 5,
  "cost": 3,
  "expiresAt": "2026-11-06T12:05:00.000Z"
}
```

| Field                                  | Description           |
| -------------------------------------- | --------------------- |
| `reservationId` string, path, required | The reservation's ID. |

More about this endpoint

Repeating a release within 24 hours returns the same result. You can’t release a reservation you’ve already committed. We cache its API key check briefly for speed. A revoked key can keep working here for up to 60 seconds.
