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

# Loops

> Stop a Loops run after a script interruption and check its status with the Baseten CLI or REST API.

Find and stop a Loops run when your script exits before cleanup. Deactivating a run stops its trainer and paired sampler while keeping saved checkpoints.

## Stop a run after an interruption

An SDK timeout stops the client from waiting; it doesn't stop the work on Baseten. If your script or machine stops before cleanup, deactivate the run before retrying.

Use the `run_id` saved by your script. If you only have a `session_id`, [find the run](#find-a-run-from-its-session-id) first.

Set your [API key](/organization/api-keys) and run ID:

```bash theme={"system"}
export BASETEN_API_KEY="YOUR_API_KEY"
export RUN_ID="YOUR_RUN_ID"
```

<Tabs>
  <Tab title="Baseten CLI">
    Use the [Baseten CLI](/reference/cli/baseten/overview#install) to [deactivate the run](/reference/cli/baseten/loops-run#deactivate). `--yes` skips the confirmation prompt:

    ```bash theme={"system"}
    baseten loops run deactivate --run-id "$RUN_ID" --yes
    ```

    Then [check the run's status](/reference/cli/baseten/loops-run#describe):

    ```bash theme={"system"}
    baseten loops run describe --run-id "$RUN_ID" \
      --jq '{run: .status.name, sampler: .sampler.status.name}'
    ```
  </Tab>

  <Tab title="REST API">
    Call [Deactivate a run](/reference/loops-api/runs/deactivate-a-run):

    ```bash theme={"system"}
    curl --fail-with-body --request POST \
      "https://api.baseten.co/v1/loops/runs/$RUN_ID/deactivate" \
      --header "Authorization: Bearer $BASETEN_API_KEY"
    ```

    Then call [Get a run](/reference/loops-api/runs/get-a-run) and check `run.status.name` and `run.sampler.status.name` in the response:

    ```bash theme={"system"}
    curl --fail-with-body \
      "https://api.baseten.co/v1/loops/runs/$RUN_ID" \
      --header "Authorization: Bearer $BASETEN_API_KEY"
    ```
  </Tab>
</Tabs>

Confirm that the run and sampler report `INACTIVE`. If the run never created a sampler, `sampler` is `null`.

## Find a run from its session ID

The training client can time out before returning a run ID. If your script saved a `session_id`, list your runs and find the matching session.

<Tabs>
  <Tab title="Baseten CLI">
    [List your runs](/reference/cli/baseten/loops-run#list) and filter by the saved session ID. Replace `YOUR_SESSION_ID` with that value. `--all` includes inactive runs:

    ```bash theme={"system"}
    baseten loops run list --all \
      --jq '.runs[] | select(.session_id == "YOUR_SESSION_ID") | {id, status}'
    ```
  </Tab>

  <Tab title="REST API">
    Call [List runs](/reference/loops-api/runs/list-runs):

    ```bash theme={"system"}
    curl --fail-with-body \
      "https://api.baseten.co/v1/loops/runs" \
      --header "Authorization: Bearer $BASETEN_API_KEY"
    ```

    In the response's `runs` array, find the entry whose `session_id` matches your saved value.
  </Tab>
</Tabs>

Use the matching run's `id` as `RUN_ID` in the deactivation command. If its status is already `INACTIVE`, it doesn't need deactivation.
