> ## 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.

# Save a checkpoint

> Save Loops training state and sampler weights during a run, and list a run's checkpoints.

A Loops checkpoint holds either training state or sampler weights. Training state lets a new run [continue training](https://docs.baseten.co/loops/continue-training.md) where a run stopped. Sampler weights feed a [sampler](https://docs.baseten.co/loops/sample-from-a-run.md), and you can [deploy them as a model](https://docs.baseten.co/loops/deploy-checkpoints.md).

The Python SDK, the Baseten CLI, 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"
```

## Save training state or sampler weights

Save from the training client:

* [`save_state()`](https://docs.baseten.co/reference/sdk/loops/training-client) saves the adapter and optimizer state, so a new run can continue training from it.
* [`save_weights_for_sampler()`](https://docs.baseten.co/reference/sdk/loops/training-client) publishes the adapter weights for sampling and inference deployment, without optimizer state.

Both return a future whose result has the checkpoint's `path`. To save both kinds and print their paths, run:

```python theme={"system"}
state = training_client.save_state(name="step-100-state").result(timeout=600.0)
weights = training_client.save_weights_for_sampler(name="step-100").result(timeout=600.0)
print(state.path, weights.path)
```

The script prints both paths, one for the training state and one for the sampler weights.

Sampler weights are saved at [`bt://loops:<run_id>/sampler_weights/<checkpoint_name>`](https://docs.baseten.co/loops/concepts#checkpoints). Use the path that the SDK returns instead of constructing it. In the serverless mode, each sampler save needs a name the run hasn't used, and the server refuses a repeated name. `save_weights_for_sampler()` requires a name; [`save_weights_and_get_sampling_client()`](https://docs.baseten.co/reference/sdk/loops/training-client) picks a unique one when you leave it out.

To have a checkpoint expire, pass `ttl_seconds` when you save it. See [Set a checkpoint expiry](https://docs.baseten.co/loops/checkpoint-expiry.md).

Loops doesn't restart a preempted run, such as a run on [spot capacity](https://docs.baseten.co/loops/availability-modes/dedicated.md#spot-capacity) that Baseten reclaims. Save training state during the run so you can continue from the latest save.

## List checkpoints

Downloading, expiring, and deleting a checkpoint through the API take its `id`. The name you saved it under is a separate field, `checkpoint_name` in API responses and `checkpoint_id` in the SDK.

> [tab] Python SDK
>
> **To list a run's checkpoints**:
>
> Call [`list_checkpoints()`](https://docs.baseten.co/reference/sdk/loops/training-client) on the training client:
>
> ```python theme={"system"}
> for ckpt in training_client.list_checkpoints():
>     print(ckpt.id, ckpt.target, ckpt.checkpoint_id, ckpt.created_at)
> ```
>
> Each line has the checkpoint's `id`, its `target`, the name it was saved under, and when it was created.
>
> After the run ends, list its checkpoints with a [`ServiceClient`](https://docs.baseten.co/reference/sdk/loops/service-client) instead, replacing `<run_id>` with the run ID:
>
> ```python theme={"system"}
> from baseten.loops import ServiceClient
>
> for ckpt in ServiceClient().list_checkpoints(run_id="<run_id>"):
>     print(ckpt.id, ckpt.target, ckpt.checkpoint_id, ckpt.created_at)
> ```
>
> `target` is `trainer` for training state and `sampler` for sampler weights.

> [tab] Baseten CLI
>
> **To list a run's checkpoints**:
>
> Run the following command, replacing `<run_id>` with your run ID:
>
> ```bash theme={"system"}
> baseten loops checkpoint list --run-id "<run_id>"
> ```
>
> The table lists each checkpoint's `ID`, `NAME`, `RUN`, `TARGET`, `TYPE`, `SIZE`, and `CREATED` time.

> [tab] REST API
>
> **To list a run's checkpoints**:
>
> Send a request to [List checkpoints](https://docs.baseten.co/reference/loops-api/checkpoints/list-checkpoints.md), replacing `<run_id>` with your run ID:
>
> ```bash theme={"system"}
> curl --url "https://api.baseten.co/v1/loops/checkpoints?run_id=<run_id>" \
>   --header "Authorization: Bearer $BASETEN_API_KEY"
> ```
>
> Each checkpoint in the response has its `id`, `checkpoint_name`, `target`, and `created_at`. Check that the response includes the checkpoint you saved.

## Next steps

* [Continue training from a checkpoint](https://docs.baseten.co/loops/continue-training.md): Start a new run from saved training state.
* [Deploy a checkpoint](https://docs.baseten.co/loops/deploy-checkpoints.md): Serve sampler weights as a dedicated inference deployment.
* [Download checkpoint files](https://docs.baseten.co/loops/download-checkpoints.md): Keep a local copy of a checkpoint.
