# Change how long things are kept.

> Days from 1 to 3650, or `null` to keep until deleted by hand.
> https://koi.dog/docs/api/costs-and-settings/update-retention/

`PATCH /api/v1/settings/retention` · Scope: `config`

The next sweep applies it (see `GET /cleanup`). Turning a setting on or shortening it lets the sweep delete things, so a key needs `approve` for that as well as `config`. 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 |
| --- | --- | --- | --- |
| `workspacesDays` | `1–3650 \| null` | no | Days a run folder on a machine is kept after its last change, or null to keep it until removed by hand. |
| `artifactsDays` | `1–3650 \| null` | no | Days an artifact (and a run bundle of a crew that ended) is kept, or null to keep it until deleted by hand. |
| `endedCrewsDays` | `1–3650 \| null` | no | Days a crew is kept after it ended, or null to keep it until deleted by hand. |

## Response.

200 OK · JSON object

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

## Request.

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

```js
const res = await fetch("https://api.koi.dog/api/v1/settings/retention", {
  method: "PATCH",
  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.patch(
    "https://api.koi.dog/api/v1/settings/retention",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
    },
    json={},
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "workspacesDays": 0,
  "artifactsDays": 0,
  "endedCrewsDays": 0
}
```
