baseten loops exec to run the same script on Baseten.
Prerequisites
- The project and
train_loops.pyfrom the Loops quickstart. - uv and Python 3.12 or later.
- A workspace API key to run the script locally.
- The Baseten CLI with an active profile to run the script on Baseten.
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 local machine
To run the script locally:-
From your project directory, export your workspace API key as
BASETEN_API_KEY. ReplaceYOUR_API_KEYwith your key: -
Run your training script:
The quickstart script prints the session and run IDs, the reward of each step, 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.
Baseten bills for the Training Job that runs your script. The Loops run bills separately according to its availability mode.
To run the script on Baseten:
From your project directory, run the same train_loops.py with its uv dependencies and stream its logs:
Output
--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 zero if the job completes successfully and a nonzero exit code if it 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:
Output
-
Use
job_idfrom the result to follow the job’s logs withbaseten train job logs: -
Check that the job completed with
baseten train job describe:Output
baseten loops exec has no Loops API equivalent because it uploads local source. For more information, see the baseten loops exec reference.