Установка
pip install lowcostgpu # Python ≥3.10, zero heavy deps
export LOWCOSTGPU_API_KEY=pg_live_…SDK за 60 секунд
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 secondОдноразовые GPU, гарантированно
Приём, который экономит реальные деньги: контекстный менеджер уничтожает инстанс при выходе, включая случаи, когда ваш код вызывает исключение.
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 instancesАсинхронность & парк
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)]))Ошибки & повторы
- повтор HTTP 429/5xx с экспоненциальной задержкой (настраивается, для POST по умолчанию выключен);
- ошибки API вызывают lowcostgpu.APIError с полями .code и .message прямо из таблицы ошибок;
- бизнес-правила (нехватка баланса, машина недоступна) вызывают DeployError — перехватите его, пополните баланс, повторите попытку.
Типизация
Полная типизация (маркер py.typed): редакторы автодополняют предложения, инстансы и цены; mypy проходит в строгом режиме. Датаклассы отражают JSON REST API поле за полем, поэтому справочник API одновременно служит справочником по SDK.