> ## Documentation Index
> Fetch the complete documentation index at: https://docs.baseten.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Set a checkpoint expiry

> Set when a Loops checkpoint expires as you save it, or change or remove the expiry later with the Python SDK or the REST API.

Set an expiry to have Baseten delete a checkpoint after a set time. A checkpoint without one uses your organization's default expiry, if it has one, and otherwise stays until you [delete it](https://docs.baseten.co/loops/delete-checkpoints.md).

> [!WARNING]
>
> Baseten permanently deletes an expired checkpoint within 24 hours. If the checkpoint is in use when it expires, such as by a deployment, Baseten deletes it within 24 hours after that use stops.

The Python SDK and the `curl` examples authenticate with `BASETEN_API_KEY`. Export your [API key](https://docs.baseten.co/organization/api-keys.md) first:

```sh theme={"system"}
export BASETEN_API_KEY="YOUR_API_KEY"
```

## Set an expiry when you save

In your training loop, pass `ttl_seconds` to [`save_state()`](https://docs.baseten.co/reference/sdk/loops/training-client) or [`save_weights_for_sampler()`](https://docs.baseten.co/reference/sdk/loops/training-client): the number of seconds that Baseten keeps the checkpoint, from 3600 (1 hour) to 315360000 (10 years). To keep the training state for 7 days and print when it expires, add these lines to the loop:

```python theme={"system"}
from baseten.loops import ServiceClient

state = training_client.save_state(name="step-100-state", ttl_seconds=604800).result(timeout=600.0)
print(ServiceClient().get_checkpoint(state.path).expires_at)
```

The printed `expires_at` is about 7 days from now.

## Change or remove an expiry

A change counts `ttl_seconds` from now, over the same 3600 to 315360000 range. Pass `ttl_seconds=None`, or `"ttl_seconds": null` in the request body, to remove the expiry so the checkpoint never expires.

> [tab] Python SDK
>
> **To change a checkpoint's expiry**:
>
> Call [`set_checkpoint_ttl_from_path()`](https://docs.baseten.co/reference/sdk/loops/service-client) on a [`ServiceClient`](https://docs.baseten.co/reference/sdk/loops/service-client) with the checkpoint's `bt://` path. To keep the checkpoint for 30 days from now, replace `<checkpoint_path>` and run:
>
> ```python theme={"system"}
> from baseten.loops import ServiceClient
>
> ckpt = ServiceClient().set_checkpoint_ttl_from_path("<checkpoint_path>", ttl_seconds=2592000)
> print(ckpt.expires_at)
> ```
>
> The call returns the updated checkpoint, and the printed `expires_at` is about 30 days from now.

> [tab] REST API
>
> **To change a checkpoint's expiry**:
>
> Send a request to [Set a checkpoint TTL](https://docs.baseten.co/reference/loops-api/checkpoints/set-a-checkpoint-ttl.md), replacing `<checkpoint_id>` with the checkpoint's `id` from [List checkpoints](https://docs.baseten.co/loops/save-checkpoints.md#list-checkpoints):
>
> ```bash theme={"system"}
> curl --request PUT \
>   --url "https://api.baseten.co/v1/loops/checkpoints/<checkpoint_id>/ttl" \
>   --header "Authorization: Bearer $BASETEN_API_KEY" \
>   --header "Content-Type: application/json" \
>   --data '{"ttl_seconds": 2592000}'
> ```
>
> Check that the response's `expires_at` is about 30 days from now.

## Next steps

* [Delete a checkpoint](https://docs.baseten.co/loops/delete-checkpoints.md): Remove a checkpoint now instead of waiting for it to expire.
* [Download checkpoint files](https://docs.baseten.co/loops/download-checkpoints.md): Keep a local copy before the checkpoint expires.
