Skip to main content
Run a Loops script on your laptop to start. Your laptop runs the Python loop, which submits training operations, waits for results, and requests samples. Baseten runs the trainer and sampler. For long or unattended runs, use baseten loops exec to run the same script on Baseten. You don’t need to change the SDK client when you move the script. Start with the project and train_loops.py from the Loops quickstart. Keep the same ServiceClient setup in the script for either location:
train_loops.py
ServiceClient() reads BASETEN_API_KEY and connects to https://api.baseten.co by default.

Run the Python script on your own machine

To run the script locally:
  1. From your project directory, set your workspace API key. Replace <YOUR_API_KEY> with the key:
  2. Run your training script:
    The quickstart script prints the session and run IDs, training loss, sampled text, and checkpoint paths. Compare its output with Inspect the results.
Keep your laptop or third-party host awake while the script runs. Its proxy, VPN, firewall, DNS, and idle-connection policies must permit sustained traffic to Baseten. A sandbox or hosted notebook can restrict outbound traffic even when the process stays running. Check DNS resolution and outbound HTTPS access from the environment that runs your script, not only from your laptop. Also check whether the host suspends idle processes or its proxy closes long-lived connections. A successful first API request doesn’t show that the environment can sustain a training run. The SDK retries transient connection failures, but it can’t keep a run going from a host or network that’s persistently unstable. Closing the training client doesn’t deactivate the Loops run. See Deactivate a run to end it and its paired sampler, and to stop a dedicated run’s GPU billing.

Run the Python script on Baseten

baseten loops exec packages a project directory and runs your script as a Training Job, using your active Baseten CLI profile. The job supplies BASETEN_API_KEY from a team secret, which Truss creates on first use unless you supply your own credential. Use a CLI profile for the same workspace as your local API key. To run the script on Baseten: From your project directory, run the same train_loops.py with its uv dependencies and stream its logs:
By default, the job opens an SSH session you can connect to, which requires Training SSH for your workspace. This command disables SSH with --no-ssh. Omit it if you want an SSH session and your workspace has Training SSH enabled. Always pass --dir. Use . for the current project directory or pass another project path. The remote command runs from the uploaded directory. With --tail, the command writes the submission result to stdout and streams logs to stderr until the job finishes. It returns a nonzero exit code if the job fails. Press Ctrl+C to stop watching; the remote job keeps running. To submit the script and check it later:
  1. Run the following command to return a structured result after submission:
  2. Use job_id from the result to follow the job’s logs:
The Training Job runs only your script and bills as a Training Job. The Loops run bills separately, by its availability mode. baseten loops exec has no Loops API equivalent, because it uploads local source; see baseten loops exec for every option.