Installation
pip install lowcostgpu # Python ≥3.10, zero heavy deps
export LOWCOSTGPU_API_KEY=pg_live_…Le SDK en soixante secondes
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 secondGPU jetables, garantis
Le motif qui vous fait vraiment économiser : le gestionnaire de contexte détruit l’instance à la sortie, y compris quand votre code lève une exception.
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 & flottes
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)]))Erreurs & réessais
- réessai sur HTTP 429/5xx avec backoff exponentiel (configurable, désactivé par défaut pour POST) ;
- Les erreurs de l’API lèvent lowcostgpu.APIError, avec .code et .message directement issus de la table des erreurs ;
- les règles métier (solde faible, machine disparue) lèvent DeployError — l’intercepter, recharger, réessayer.
Typage
Entièrement typé (marqueur py.typed) : les éditeurs complètent automatiquement les offres, les instances et les prix ; mypy passe en mode strict. Les dataclasses reflètent le JSON de l’API REST champ par champ, si bien que la référence API fait aussi office de référence du SDK.