Quick start · Install · API key · Python · Bash · CLI · Money safety
A small, dependency-free toolkit for controlling RunPod GPU pods from Python, Bash scripts, and the command line: list, start, stop, restart, create, terminate, and wait for a reachable SSH endpoint.
- Python: standard library only, Python 3.9+.
- Bash: a sourceable library that works on Bash 3.2+, including the macOS system Bash.
- CLI:
runpodkit, which the Bash library wraps.
It targets the RunPod REST v2 API (https://api.runpod.io/v2). The v1 API at rest.runpod.io is retired; to_v1() adds v1-shaped fields for code that still expects them.
Why another client?
Two things bit us in production. This toolkit handles both for you.
Quick start
pipx install "git+https://github.com/kcherry497/runpod-kit.git@v0.2.0" # or pip inside a venv; see Install
export RUNPOD_API_KEY=... # or let an AI agent use it safely: see "Setting your API key"
Python
from runpodkit import RunPod, pod_state
rp = RunPod() # reads RUNPOD_API_KEY
for pod in rp.list_pods():
print(pod["id"], pod["name"], pod_state(pod))
rp.start("POD_ID")
host, port = rp.wait_ssh("POD_ID") # only returns once TCP connects
print(f"ssh -p {port} root@{host}")
CLI
$ runpodkit list | jq -r '.[] | "\(.id) \(.name) \(.status)"'
$ runpodkit start POD_ID >/dev/null && runpodkit wait-ssh POD_ID
203.0.113.10 22088
$ runpodkit stop POD_ID >/dev/null
Bash
. "$(runpodkit bash-lib)"
rp_action "$POD_ID" start >/dev/null
read -r host port < <(rp_wait_ssh "$POD_ID" 320) && ssh -p "$port" "root@$host"
Install
As a command-line tool, with pipx (no dependencies):
pipx install "git+https://github.com/kcherry497/runpod-kit.git@v0.2.0"
runpodkit --version
As a library in your project, inside its virtual environment:
python3 -m pip install "git+https://github.com/kcherry497/runpod-kit.git@v0.2.0"
Plain pip install into a system Python is refused on Ubuntu 23.04+, Debian 12+ and Homebrew Python (PEP 668); use pipx, a venv, or install.sh below.
Or keep a clone and link it into one or more interpreters without pip:
git clone https://github.com/kcherry497/runpod-kit.git
cd runpod-kit
./install.sh python3 # user site + ~/.local/bin/runpodkit
# a root-owned venv (e.g. a service), with the launcher on cron's PATH:
sudo RUNPODKIT_BIN=/usr/local/bin ./install.sh /srv/myapp/venv/bin/python
install.sh writes a runpodkit.pth into each interpreter's site-packages, pointing at the clone. It also writes a runpodkit launcher to ${RUNPODKIT_BIN:-~/.local/bin}. It is idempotent and needs no pip or network. Don't run it under sudo for a system python3: that would write root's user site. The clone must be readable by every user that imports it.
Two things follow from the .pth approach, which make it handy when several programs on one host share the toolkit:
- Updating is
git pullin the clone. Every importer and every bash script picks the new code up immediately. - Rollback is
git checkout <tag>.
Setting your API key
runpodkit reads the key from RUNPOD_API_KEY and nowhere else: there is no key flag, so it never lands in argv or shell history. Pick whichever way of supplying it fits.
Option 1: an environment variable. Simplest, for your own shell or a service unit:
export RUNPOD_API_KEY=... # from the RunPod console (Settings → API Keys)
runpodkit list
Option 2: cred-broker, when an AI coding agent drives runpodkit. The key stays encrypted in pass, and the agent works with the name runpod only. cred exec decrypts the key into RUNPOD_API_KEY for that one command, filters it out of the command's output, and logs the call. Add an entry to ~/.config/cred-broker/manifest.yaml:
runpod:
describes: RunPod API key (list/start/stop/create/terminate pods)
pass_path: agent/runpod
env: RUNPOD_API_KEY
risk: high
note: create starts billing; terminate deletes the pod and its disk.
Store the key once, in your own terminal (! cred set runpod inside Claude Code), then wrap any runpodkit call:
cred set runpod # prompts; the value never passes through the agent
cred exec runpod -- runpodkit list
cred exec runpod -- python3 my_pod_script.py # Python API: RunPod() picks the key up from the env
cred exec runpod -- bash -c '. "$(runpodkit bash-lib)"; rp_wait_ssh "$1" 320' _ "$POD_ID"
A RunPod key can start billing pods, so give the agent a key of its own where you can, and mark it risk: high as above. See cred-broker's threat model for what it does and does not protect against.
Where runpodkit.pth goes
./install.sh [PYTHON ...] defaults to python3. It checks that each interpreter is Python >= 3.9 and writes runpodkit.pth containing the absolute clone directory:
| Interpreter | Destination for runpodkit.pth |
|---|---|
| Venv | That venv's sysconfig purelib directory |
| System Python marked externally managed under PEP 668 | That interpreter's user site |
| Unmanaged system Python with an existing, writable purelib | Its purelib directory |
| Unmanaged system Python with missing or non-writable purelib | Its user site, with a diagnostic |
A non-writable venv purelib is an error. The installer checks imports from a neutral directory and warns if an interpreter does not resolve this clone, for example because its user site is disabled.
Vendored copy (no install)
To ship runpodkit inside another app, copy the runpodkit/ package next to your scripts and point RUNPODKIT_BUNDLE at the directory containing it. Define the CLI as a shell function and source the library:
RUNPODKIT_BUNDLE=/path/to/bundle
runpodkit() {
PYTHONPATH="${RUNPODKIT_BUNDLE}${PYTHONPATH:+:$PYTHONPATH}" python3 -m runpodkit "$@"
}
. "$(runpodkit bash-lib)"
Python usage
from runpodkit import (
BOOTING, RunPod, RunPodError, RunPodTimeoutError,
pod_state, ssh_endpoint, to_v1,
)
rp = RunPod()
RunPod(api_key=None, base_url=None, timeout=30) reads RUNPOD_API_KEY when no key argument is supplied, and RUNPOD_API_URL when no base URL argument is supplied. The URL defaults to https://api.runpod.io/v2, with trailing slashes removed. A missing or empty key raises RunPodError. The HTTP request timeout is in seconds.
| Method | Result |
|---|---|
rp.list_pods() |
List of pod dicts across all cursor pages, including terminated pods |
rp.get_pod(pod_id) |
Pod dict, or None on HTTP 404 |
rp.find_pod(name, include_terminated=False, exclude_ids=()) |
First exact-name, non-terminated match in API order, skipping IDs in exclude_ids; otherwise None. With include_terminated=True, falls back to the first terminated match |
rp.start(pod_id) |
POSTs the start action; returns pod dict |
rp.stop(pod_id) |
POSTs the stop action; returns pod dict |
rp.restart(pod_id) |
POSTs the restart action; returns pod dict |
rp.terminate(pod_id) |
DELETE HTTP status, normally 204; returns 404 when already missing |
rp.network_volumes() |
List of network-volume dicts |
rp.wait_status(pod_id, want, timeout=240, poll=6) |
Pod dict when normalized state matches want, case insensitive; {} for a missing pod when waiting for NOTFOUND |
rp.wait_ssh(pod_id, timeout=320, poll=6, tcp_timeout=5) |
(host, port) after a fresh GET yields an endpoint that accepts TCP |
rp.create(body, gpu_ids=None) |
Created or recovered pod dict. With a list such as gpu_ids=["NVIDIA RTX A5000", "NVIDIA A40"], tries the GPU types in order under the rules below |
Wait durations are seconds. Timeouts, polling intervals, and TCP timeouts must be finite positive numbers. Both wait methods tolerate transport errors, HTTP 429, and HTTP 5xx while polling; other HTTP errors propagate. Deadline expiry raises RunPodTimeoutError. wait_ssh checks TCP reachability, not SSH authentication.
The helpers perform no network requests:
| Helper | Behavior |
|---|---|
pod_state(pod) |
Uppercases status; returns NOTFOUND for non-dicts or missing/invalid status; maps RUNNING with absent or null runtime to STARTING |
ssh_endpoint(pod) |
Returns (host, int_port) from the first valid private-22 TCP entry in a RUNNING pod's runtime.ports, otherwise None; does not probe TCP |
to_v1(pod) |
Deep-copies a pod dict and adds/replaces desiredStatus, publicIp, and portMappings; never mutates the input |
BOOTING |
Frozenset of PROVISIONING, CREATED, STARTING, RESTARTING, INITIALIZING |
to_v1 sets desiredStatus to RUNNING for running or booting states, otherwise to pod_state(pod). It sets publicIp to the SSH host or "", and portMappings to {"22": port} or {}. It requires a dict.
RunPodError is a RuntimeError with .status (HTTP code, or None for transport/local errors) and .body (response text or diagnostic body, truncated to 500 characters). RunPodTimeoutError subclasses it and always has .status is None. Input validation can raise ValueError or TypeError.
Start a pod, wait for its current endpoint, then connect using an existing SSH key:
import os
import subprocess
from runpodkit import RunPod
rp = RunPod() # RUNPOD_API_KEY is already supplied in the environment.
pod_id = os.environ["POD_ID"]
rp.start(pod_id)
host, port = rp.wait_ssh(pod_id)
subprocess.run(["ssh", "-p", str(port), f"root@{host}"], check=True)
create() money-safety rules
bodymust be a dict with a non-empty stringname. If supplied,gpu_idsmust be a non-empty list of distinct, non-empty strings. Invalid inputs raiseValueError. The body is deep-copied; the caller's object is never changed.- Without
gpu_ids, there is one attempt with the body unchanged. With GPU IDs, each attempt replacesgpuwith{"id": gpu_id, "count": count}. Count comes from the originalgpu["count"]when present in a dict, otherwise defaults to1. - Before every attempt after the first,
find_pod(name)checks for an existing non-terminated pod. If found, it is returned without another POST. If the lookup fails, its error propagates and no POST follows. No existing pod is ever returned before the first attempt; the only call before it is the ID snapshot described in rule 6. - A successful POST must return a dict with a non-empty string
id. A malformed success response, including invalid JSON, triggers recovery by name because a pod may already have been created; it never triggers another POST. - Only HTTP 4xx errors other than
401,403, and429allow fallback to the next GPU. Those three codes raise immediately without fallback or recovery lookup. - A transport error, HTTP 5xx, or another uncertain POST result triggers
find_pod(name). A found pod is returned. If absent, aRunPodErrorpreserving the original status/body reportscreate outcome UNKNOWNand warns that a pod may still appear and bill. If the recovery lookup itself fails, the error still reportscreate outcome UNKNOWN(keeping the original POST status/body, with the lookup error as its cause), because a pod may exist even though it could not be checked. Recovery never re-POSTs; checkrunpodkit listbefore manually retrying. Before its first POST,createsnapshots the IDs of pods already carrying that name; the retry guard and the recovery only ever return a pod not in that snapshot, so an older same-name husk is never mistaken for the new (billing) pod. A failed snapshot raises before any POST. - If every GPU attempt is refused by an eligible 4xx, the last refusal error is raised.
Bash usage
set -uo pipefail
. "$(runpodkit bash-lib)"
# RUNPOD_API_KEY is already supplied in the environment.
info=$(rp_get "$POD_ID")
printf '%s\n' "$info" | rp_state
printf '%s\n' "$info" | rp_ssh
rp_action "$POD_ID" start
if endpoint=$(rp_wait_ssh "$POD_ID" 320); then
read -r host port <<< "$endpoint"
ssh -p "$port" "root@$host"
fi
| Function | Standard output | Return code |
|---|---|---|
rp_get ID |
Pod JSON; a missing pod prints a JSON object whose detail is "pod not found" |
0 for found or missing; 1 for other CLI failures; 2 for missing/empty ID |
rp_state |
Reads pod JSON from stdin; prints one state word, or NOTFOUND if the CLI fails or is silent |
Always 0 |
rp_ssh |
Reads pod JSON from stdin; prints ip port and newline, or nothing if unavailable or the CLI fails |
Always 0 |
rp_action ID start|stop|restart |
CLI pod JSON | CLI status unchanged; 2 for missing/empty arguments or an invalid action |
rp_delete ID |
HTTP status: normally 204, 404 if missing, or another HTTP error code; nothing on transport failure |
CLI status unchanged (0 for deleted/missing, 1 for errors); 2 for missing/empty ID |
rp_wait_ssh ID [TIMEOUT] |
ip port and newline on success; default timeout 320 seconds |
0 on success; 1 on any CLI failure, including timeout; 2 for missing/empty ID |
Argument errors write a diagnostic to stderr. These wrappers preserve CLI stderr. Pod JSON uses the CLI's default env stripping.
Each invocation uses a non-empty $RP first, otherwise $RUNPOD_API_KEY, otherwise an empty key. The wrapper exports the selected key only inside a subshell for the CLI call, never in argv. A non-empty RUNPOD_API_URL shell variable is also exported there, even if it was not exported by the caller.
RUNPODKIT_CLI selects an alternate executable path or shell function name; it is one quoted command name, not a command string with arguments. Empty or unset means runpodkit. A function named runpodkit, including the vendored-copy definition above, works directly. Subshell execution isolates exports and function side effects from the caller.
The library is safe to source under set -uo pipefail and preserves shell options, traps, and IFS. It uses no exit. Under set -e, handle expected nonzero function returns with if or another shell conditional.
CLI reference
Use either runpodkit or python3 -m runpodkit. Every subcommand supports --help.
| Subcommand and arguments | Standard output | Command-specific exit codes |
|---|---|---|
list [--all] [--with-env] |
JSON array; hides TERMINATED unless --all |
0 |
get ID [--with-env] |
Pod JSON; on 404, a JSON object whose detail is "pod not found" |
0 found; 3 missing |
state ID or state - |
State word; NOTFOUND for a missing pod or invalid/empty stdin JSON |
0, including NOTFOUND |
ssh ID or ssh - |
ip port and newline, or nothing when unavailable |
0 endpoint; 1 unavailable |
wait-ssh ID [--timeout N] |
Reachable ip port; default 320 seconds |
0 ready; 3 timeout |
wait-status ID STATUS [--timeout N] [--with-env] |
Pod JSON; case-insensitive target, default 240 seconds |
0 matched; 3 timeout |
start ID [--with-env] |
Pod JSON from action response | 0 |
stop ID [--with-env] |
Pod JSON from action response | 0 |
restart ID [--with-env] |
Pod JSON from action response | 0 |
delete ID |
HTTP status, including 404 when already missing; prints other HTTP error codes too; no stdout on transport failure |
0 deleted/missing; 1 other errors |
create --body FILE [--gpu ID ...] [--with-env] |
Created or recovered pod JSON; FILE may be - for stdin |
0 |
volumes |
Network-volume JSON array | 0 |
bash-lib |
Absolute path to the Bash library | 0 |
version |
runpodkit followed by its version |
0 |
All commands can also return 1 for operational errors, 2 for usage errors, or 130 on keyboard interrupt. Exit 3 is reserved for get not found and wait timeouts. Broken stdout pipes return 1 quietly. Operational errors normally write one line prefixed runpodkit: to stderr; an unavailable ssh endpoint returns 1 silently.
The CLI reads the API key only from RUNPOD_API_KEY, with no key flag. state -, ssh -, bash-lib, and version need no key and make no network requests. Other commands use RUNPOD_API_URL if supplied.
JSON output is indented by two spaces with a trailing newline. By default, commands printing pod JSON remove each pod's top-level env field. --with-env keeps it and is supported only by list, get, wait-status, start, stop, restart, and create. volumes prints its response without this pod-field filtering. Python API results retain env.
create reads a JSON object from a file or stdin. Repeat --gpu or supply several IDs after one flag; quote GPU IDs containing spaces:
runpodkit create --body pod.json --gpu "NVIDIA RTX A5000" "NVIDIA A40"
runpodkit create --body pod.json --gpu "NVIDIA RTX A5000" --gpu "NVIDIA A40"
RunPod v2 behavior notes
These are recorded API observations; startup timing is not a guarantee.
- V2
statusis the observed state. The v1-styledesiredStatusadded byto_v1is a compatibility field and maps booting states toRUNNING. runtimecan be null while booting.pod_statetreatsstatus: RUNNINGwith null or missing runtime asSTARTING.- SSH comes from a
runtime.portsentry with integerprivate: 22,type: "tcp", a non-empty IP, and a positive public port. A decimal-string public port is accepted and converted to an integer. The private-19123httpentry is ignored.ssh.directcan be stale and is never used. - Stale runtime after start: for about 25 seconds, the API has reported
RUNNINGwith the previous run's SSH port, which refuses connections. The port changes on every restart.wait_sshre-GETs the pod on every poll and TCP-probes that poll's endpoint; it does not cache the firstRUNNINGendpoint.wait_status(..., "RUNNING")alone does not establish SSH readiness. - Wrong-state actions can return HTTP
409; for example, stopping anEXITEDpod. The client propagates the error instead of treating the action as successful. - Create capacity refusals return HTTP
400. This is eligible for the guarded GPU fallback described above. - The minimum persistent volume is 10 GB.
- Cloudflare has rejected Python's default urllib User-Agent with HTTP
403anderror code: 1010. Every client request sends the browser-styleMozilla/5.0 (X11; Linux x86_64) runpodkit/User-Agent followed by the package version, along with Bearer authorization, JSON content type, and JSON accept headers.
Security
The CLI accepts the API key through the environment, and Bash passes it only through the child environment. The client sends it in the Authorization header. The key is never added to argv and is redacted from client-generated error messages, error bodies, and repr(rp); the CLI also redacts it from output and diagnostics. Supply credentials through the environment rather than command-line arguments.
Pod env fields are stripped from CLI JSON by default because they may contain secrets. --with-env exposes them. Python API results and to_v1 copies retain them; key redaction is not general redaction of every secret in a response.
Tests are offline: HTTP and TCP calls are mocked, with guards against unmocked client network access. Bash tests use local stubs or stdin parsing; installer tests use temporary directories and interpreters.
Running the tests
From the clone root:
python3 -m unittest discover -s tests -v
tests/test_bash.py and tests/test_install.py can run every shell scenario under several Bash executables. Supply colon-separated absolute paths:
RUNPODKIT_TEST_BASHES=/path/to/bash3.2:/bin/bash \
python3 -m unittest discover -s tests -v
Without this variable, the shell tests use bash from PATH and are skipped only if there is none. Configured paths must be absolute, existing executables; a wrong path is a test error, never a silent skip. The tests require no API key, pip, or network.
Contributing
Issues and pull requests are welcome. Keep the runtime standard-library only, keep Bash 3.2 compatibility, and add an offline test for any behavior change. CI runs the suite on Python 3.9 through 3.13, the shell tests under a source-built GNU Bash 3.2.57, and a separate real-macOS job.
License
MIT. See LICENSE. Not affiliated with or endorsed by RunPod.
Metadata
Release files for runpodkit 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| runpodkit-0.2.0.tar.gz | 50.8 kB | With provenance | Details for runpodkit-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| runpodkit-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for runpodkit-0.2.0-py3-none-any.whl |
Total release size: 71.4 kB
Release files / runpodkit-0.2.0.tar.gz
| Download URL | runpodkit-0.2.0.tar.gz |
|---|---|
| Size | 50.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f122dd517869867ea7d82f791bf9268930adb74d4b6e6d4e17b6d80718f78e8
|
|
BLAKE2b-256 checksum How to use checksums |
4f16f9ae4ab1db41772f6ca21c8ebd2e3799ab93791ecce91e4ce4c82deef70f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / runpodkit-0.2.0-py3-none-any.whl
| Download URL | runpodkit-0.2.0-py3-none-any.whl |
|---|---|
| Size | 20.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ffe30636cae3817c1aab1ed866f6497dc24596e095f0dcfd7d76cbf8a71832c7
|
|
BLAKE2b-256 checksum How to use checksums |
ff74de471cd3175e5491bb286a936b195451f00f0b6a09e536e5786f5d4eea91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logSecurity for runpodkit 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for runpodkit-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.