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

# Download checkpoint files

> Download a Loops checkpoint's files with the Python SDK, or get presigned download URLs from the Baseten CLI or the REST API.

Download a checkpoint's files to evaluate them locally, load them into your own code, or keep a copy before you [delete the checkpoint](https://docs.baseten.co/loops/delete-checkpoints.md). The Baseten CLI and the REST API take the checkpoint's `id` from [List checkpoints](https://docs.baseten.co/loops/save-checkpoints.md#list-checkpoints). The Python SDK takes that `id`, or the name you saved the checkpoint under together with the run's ID.

A checkpoint's files are stored in S3 or in a Baseten volume, and recent checkpoints are usually in volumes. The Python SDK downloads from either. The Baseten CLI and the REST API return presigned URLs only for checkpoints stored in S3. For a checkpoint stored in a volume, they fail with a `Checkpoint <checkpoint_id> has no presigned URLs` error; use the Python SDK instead. To check where a checkpoint is stored, send a [Get checkpoint source](https://docs.baseten.co/reference/loops-api/checkpoints/get-checkpoint-source.md) request.

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"
```

> [tab] Python SDK
>
> **To download a checkpoint's files**:
>
> Call [`download_checkpoint()`](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 `id` and a `dest_dir` that doesn't exist yet or is empty. The run doesn't need to be active. Replace `<checkpoint_id>` with the `id`, then run:
>
> ```python theme={"system"}
> from baseten.loops import ServiceClient
>
> download = ServiceClient().download_checkpoint("<checkpoint_id>", dest_dir="./checkpoint")
> print(download.dest_dir, download.file_count)
> ```
>
> To identify the checkpoint by the name you saved it under, pass `name` and the run's ID instead of `checkpoint_id`:
>
> ```python theme={"system"}
> download = ServiceClient().download_checkpoint(
>     name="step-100",
>     run_id="<run_id>",
>     dest_dir="./checkpoint-100",
> )
> ```
>
> The script prints the directory that holds the files and how many it wrote. A sampler checkpoint with two files prints:
>
> ```output theme={"system"}
> checkpoint 2
> ```
>
> During a run, `training_client.download_checkpoint()` takes the same arguments except `run_id`, which it resolves from the client's run.

> [tab] Baseten CLI
>
> **To download a checkpoint's files**:
>
> 1. Save the presigned URLs for the checkpoint's files, replacing `<checkpoint_id>` with the checkpoint's `id`:
>
>    ```bash theme={"system"}
>    baseten loops checkpoint files --checkpoint-id "<checkpoint_id>" --output json > checkpoint-files.json
>    ```
>
>    Each record has the file's `relative_file_name` and its `url`. The URLs are short-lived, so download the files right away. For a checkpoint stored in a volume, the command exits with status `5` and `checkpoint-files.json` holds `[]`.
>
> 2. Download each file into `./checkpoint`, keeping its relative path:
>
>    ```bash theme={"system"}
>    jq -r '.[] | [.url, .relative_file_name] | @tsv' checkpoint-files.json |
>      while IFS=$'\t' read -r url name; do
>        mkdir -p "checkpoint/$(dirname "$name")"
>        curl -sSfL -o "checkpoint/$name" "$url"
>      done
>    ```
>
> 3. Confirm that every file arrived:
>
>    ```bash theme={"system"}
>    find checkpoint -type f | wc -l
>    jq length checkpoint-files.json
>    ```
>
>    Both commands print the same count.

> [tab] REST API
>
> **To get a checkpoint's download URLs**:
>
> Send a request to [Get checkpoint files](https://docs.baseten.co/reference/loops-api/checkpoints/get-checkpoint-files.md), replacing `<checkpoint_id>` with the checkpoint's `id`:
>
> ```bash theme={"system"}
> curl --url "https://api.baseten.co/v1/loops/checkpoints/<checkpoint_id>/files" \
>   --header "Authorization: Bearer $BASETEN_API_KEY"
> ```
>
> Each item in `presigned_urls` has the file's `relative_file_name`, its `size_bytes`, and its `url`. The response is paginated: when `next_page_token` is set, send the request again with a `page_token` query parameter set to that value. The last page has `next_page_token` set to `null`, and `total_count` is the number of files in the checkpoint.

## Next steps

* [Delete a checkpoint](https://docs.baseten.co/loops/delete-checkpoints.md): Remove the checkpoint after you keep a copy.
* [Load a checkpoint into a new job](https://docs.baseten.co/training/loading.md#from-a-loops-run): Load a Loops checkpoint into your own training code.
