Automating GPU Rental with Python

Automating GPU Rental with Python Scripts

πŸ’‘ New: Official Python SDK

This guide uses raw requests for learning purposes. For production, use the official SDK: pip install clore-ai β€” built-in rate limiter, async support, type hints.

β†’ SDK Quick Start

What We're Building

A robust Python automation framework for Clore.ai that handles server discovery, order management, automatic retries, and cost tracking β€” the foundation for all your GPU automation needs.

Prerequisites

  • Clore.ai API key

  • Python 3.10+

  • requests, tenacity libraries

pip install requests tenacity

Step 1: Set Up the Clore Client

πŸ“¦ Using the standard Clore API client. See Clore API Client Reference for the full implementation and setup instructions. Save it as clore_client.py in your project.

from clore_client import CloreClient

client = CloreClient(api_key="your-api-key")

clore_automation/client.py

"""Production-ready Clore.ai API client with retry logic."""

import requests import time import logging from typing import Dict, List, Optional, Any from dataclasses import dataclass from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type

logging.basicConfig(level=logging.INFO) logger = logging.getLogger(name)

class CloreAPIError(Exception): """Clore API error with code.""" def init(self, message: str, code: int = -1, response: dict = None): self.code = code self.response = response or {} super().init(f"[Code {code}] {message}")

class RateLimitError(CloreAPIError): """Rate limit exceeded.""" pass

class InsufficientBalanceError(CloreAPIError): """Not enough balance.""" pass

@dataclass class ServerFilter: """Filter criteria for server search.""" gpu_types: List[str] = None # ["RTX 4090", "A100"] min_gpu_count: int = 1 max_price_usd: float = 10.0 min_reliability: float = 0.0 min_vram_gb: int = 0 currencies: List[str] = None # ["CLORE-Blockchain", "bitcoin"]

=== Usage Example ===

if name == "main": client = CloreClient("YOUR_API_KEY")

Step 3: Cost Tracker

Full Example: Automated Training Job

Best Practices

1. Always Use Retry Logic

2. Implement Proper Cleanup

3. Track All Costs

Next Steps

Last updated

Was this helpful?