TOGETHER_API_KEY environment variable instead of running tg login. Pass --non-interactive or --json on CLI commands so they never wait for a prompt. For CLI setup in a pipeline, see Use the CLI in a CI/CD environment.
Create and delete clusters from CI
Create an on-demand cluster for a pipeline run and delete it when the job finishes, so you pay only for the run itself. To set this up in GitHub Actions, store an API key as a secret namedTOGETHER_API_KEY, and add your Kubernetes job manifest to the repository as training-job.yaml. The key must belong to a project admin. With a key from any other role, the API omits the kubeconfig, so get-credentials writes nothing and the kubectl command in the training step fails.
Then add this workflow, which runs the training job on a new cluster for every push:
$GITHUB_ENV as CLUSTER_ID, so later steps can find the cluster. If the cluster never reaches Ready, the job’s timeout-minutes limit ends the wait loop. The Cleanup step runs whenever the create step returned an ID, so the workflow deletes the cluster even when a later step fails.
Create clusters on a schedule
To create a cluster on a schedule, such as for daily batch work, save theclusters create command in a script:
create-daily-batch.sh
TOGETHER_API_KEY in the crontab or the script. Then add the script to your crontab:
Scale on your own signals
To scale a cluster up or down on your own signals, such as job queue length, runtg clusters update with a new GPU count:
Best practices
- Use environment variables for API keys: Store the key as a CI secret and expose it as
TOGETHER_API_KEY. Never hardcode it in scripts or pipeline definitions. - Reference clusters by ID: IDs are generally more reliable than names in scripts. Capture the ID from the
--jsonoutput oftg clusters create, as the CI workflow does. - Check cluster status before submitting jobs: After you create a cluster, wait until its status is
Ready. - Implement retry logic: Handle transient failures with exponential backoff.
- Clean up resources: Delete on-demand clusters when the job completes, including when it fails.
Troubleshooting
- Commands fail with an authentication error: The API key is missing or invalid. Check that it’s set without printing it, for example with
test -n "$TOGETHER_API_KEY" && echo set, and confirm that the key is valid in your account settings. To see which project and organization the CLI is using, runtg whoami. - Commands use the wrong project or credentials on a machine where you ran
tg login: While you’re logged in, the CLI uses your login instead ofTOGETHER_API_KEY. To use the key, runtg logoutor pass--api-key. - Commands fail with rate-limit errors: The script is calling the API too often. Retry with exponential backoff, and batch operations where possible. For higher limits, contact support.
Next steps
Manage GPU clusters
Run every cluster operation from the console, CLI, or SDKs.
Clusters CLI reference
Look up every
tg clusters command and flag.Clusters API reference
Check request and response shapes for the clusters REST API.
SkyPilot
Launch AI workloads on your cluster through SkyPilot task files.