# Set the monthly cloud spend cap.

> Defaults to 10 US dollars a month.
> https://koi.dog/docs/api/cloud/set-cloud-spend-cap/

`PUT /api/v1/cloud/spend-cap` · Scopes: `config`, `approve`

Spend above the cap is refused before a VM is created. The timeline records the key ID, action and outcome.

## Headers.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Retry the same request with the same key. [Retry rules](https://koi.dog/docs/api/#retries). |

## Body.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `capUsd` | `number` | no | The most the workspace may spend on cloud VMs in a calendar month (UTC), in US dollars. A launch that would go over it is refused before a VM is created. > 0. ≤ 1000000. Default `10`. |
| `period` | `"month"` | no | How often the cap starts again. Only `month` today. Default `month`. |

## Response.

200 OK · JSON object

- **422 validation_failed**: Each schema error appears in `details`.

## Request.

```sh
curl -X PUT https://api.koi.dog/api/v1/cloud/spend-cap \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{}'
```

```js
const res = await fetch("https://api.koi.dog/api/v1/cloud/spend-cap", {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({}),
});
console.log(await res.json());
```

```python
import os

import requests

r = requests.put(
    "https://api.koi.dog/api/v1/cloud/spend-cap",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
    },
    json={},
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "state": "unset",
  "capUsd": 0,
  "period": "month",
  "setAt": "string",
  "periodStart": "string",
  "spentUsd": 0,
  "reservedUsd": 0
}
```
