| name | vastai-sdk-patterns |
| description | Apply production-ready Vast.ai SDK patterns for Python and REST API.
Use when implementing Vast.ai integrations, refactoring SDK usage,
or establishing coding standards for GPU cloud operations.
Trigger with phrases like "vastai SDK patterns", "vastai best practices",
"vastai code patterns", "idiomatic vastai".
|
| allowed-tools | Read, Write, Edit, Grep |
| version | 1.11.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","vast-ai","python","patterns"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Vast.ai SDK Patterns
Overview
Production-ready patterns for the Vast.ai CLI, Python SDK, and REST API at cloud.vast.ai/api/v0. Covers typed search queries, instance lifecycle management, offer scoring, and error handling.
Prerequisites
- Completed
vastai-install-auth setup
- Python 3.8+ with
requests
- Familiarity with the Vast.ai marketplace model
Instructions
Pattern 1: Typed Search Query Builder
from dataclasses import dataclass
from typing import Optional
@dataclass
class GPUQuery:
num_gpus: int = 1
gpu_name: Optional[str] = None
gpu_ram_min: Optional[float] = None
reliability_min: float = 0.95
max_dph: Optional[float] = None
def to_filter(self) -> dict:
f = {"rentable": {"eq": True}, "num_gpus": {"eq": self.num_gpus},
"reliability2": {"gte": self.reliability_min}}
if self.gpu_name:
f["gpu_name"] = {"eq": self.gpu_name}
if .gpu_ram_min:
f[] = {: .gpu_ram_min}
.max_dph:
f[] = {: .max_dph}
f