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:-
From your project directory, set your workspace API key. Replace
<YOUR_API_KEY>with the key: -
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.
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:
--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:
-
Run the following command to return a structured result after submission:
-
Use
job_idfrom the result to follow the job’s logs:
baseten loops exec has no Loops API equivalent, because it uploads local source; see baseten loops exec for every option.