vastai-sdk-patterns

Featured

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".

AI & Automation 2,944 stars 440 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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 ```python 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 self.gpu_ram_min: f["gpu_ram"] = {"gte": self.gpu_ram_min} if self.max_dph: f["dph_total"] = {"lte": self.max_dph} return f ``` ### Pattern 2: Context-Managed Instance Lifecycle ```python from contextlib import contextmanager @contextmanager def managed_instance(client, offer_id, image, disk_gb=20, timeout=300): """Auto-destroy instance on exit or exception.""" inst = client.create_instance(offer_id, image, disk_gb) instance_id = inst["new_contract"] try: info = client.poll_unti...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
1 years ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category