Installation
pip install lowcostgpu # Python ≥3.10, zero heavy deps
export LOWCOSTGPU_API_KEY=pg_live_…Sechzig Sekunden SDK
import lowcostgpu
client = lowcostgpu.Client() # reads LOWCOSTGPU_API_KEY
# the public price sheet — no key needed for this call
for g in client.gpus():
print(g.slug, g.price.on_demand)
# find capacity and deploy
offer = client.offers(gpu="rtx-4090", num_min=1)[0]
inst = client.instances.create(
machine_id=offer.machine_id,
template="pytorch",
disk_gb=60,
type="interruptible",
)
inst.wait("running")
print(inst.hostname, inst.price_hr)
inst.stop() # billing ends this secondWegwerf-GPUs, garantiert
Das Muster, das wirklich Geld spart: Der Kontextmanager löscht die Instanz beim Verlassen des Kontexts, auch wenn Ihr Code eine Exception auslöst.
with client.ephemeral(gpu="a100-sxm4", template="axolotl",
volume="ckpts:/ckpts") as gpu:
gpu.exec("axolotl train qlora.yml") # streams output
gpu.download("/ckpts/adapter", "./out") # billed at $0.01/GB
# ← destroyed here, success or crash — no forgotten $2/hr instancesAsync & Flotten
import asyncio, lowcostgpu
async def frame(n: int):
async with lowcostgpu.AsyncClient().ephemeral(
gpu="rtx-4090", template="blender",
volume="scene:/scene:ro") as gpu:
await gpu.exec(f"blender -b /scene/shot.blend -f {n}")
# 8 frames in parallel — per-second billing makes this cost the same
asyncio.run(asyncio.gather(*[frame(n) for n in range(1, 9)]))Fehler & Wiederholungen
- Wiederholung bei HTTP 429/5xx mit exponentiellem Backoff (konfigurierbar, für POST standardmäßig deaktiviert);
- API-Fehler lösen lowcostgpu.APIError aus – mit .code und .message direkt aus der Fehlertabelle;
- Geschäftsregeln (niedriges Guthaben, Maschine nicht mehr verfügbar) lösen DeployError aus – abfangen, aufladen, erneut versuchen.
Typisierung
Vollständig typisiert (py.typed-Marker): Editoren vervollständigen Angebote, Instanzen und Preise automatisch; mypy läuft im Strict-Modus fehlerfrei durch. Die Dataclasses spiegeln Feld für Feld das JSON der REST-API, sodass die API-Referenz zugleich als SDK-Referenz dient.