For the complete documentation index, see llms.txt. This page is also available as Markdown.
CLI और SDK गाइड
अवलोकन
Clore.ai एक प्रदान करता है REST API जो GPU मार्केटप्लेस तक पूर्ण प्रोग्रामेटिक पहुँच सक्षम करता है — सर्वर सूचीबद्ध करना, ऑर्डर बनाना, डिप्लॉयमेंट्स की निगरानी करना, और किराये रद्द करना।
नोट: फिलहाल कोई आधिकारिक CLI बाइनरी नहीं है। सभी ऑटोमेशन सीधे REST API के माध्यम से, जैसे curl, Python, या Node.js के साथ।
आधार URL:https://api.clore.ai/v1
प्रतिक्रिया प्रारूप: JSON। प्रत्येक प्रतिक्रिया में एक code फ़ील्ड होता है जो स्थिति दर्शाता है।
स्पॉट ऑर्डर सस्ते होते हैं लेकिन उन पर अधिक बोली लगाई जा सकती है। आप प्रति दिन अपनी कीमत तय करते हैं:
ऑर्डर की स्थिति जांचें
सक्रिय ऑर्डर में शामिल हैं pub_cluster (होस्टनेम) और tcp_ports SSH पहुँच के लिए:
अपने किराये पर लिए गए सर्वर में SSH करें:
ऑर्डर रद्द करें
वैकल्पिक रूप से सर्वर से संबंधित कोई समस्या रिपोर्ट करें:
Python SDK
एक हल्का रैपर जो requests लाइब्रेरी। इसे इस तरह इंस्टॉल करें:
CloreClient क्लास
पूर्ण कार्यशील उदाहरण
Node.js उदाहरण
मूल fetch API (Node.js 18+):
सामान्य कार्यप्रवाह
सबसे सस्ता RTX 4090 खोजें और उसे किराए पर लें
मेरे ऑर्डर मॉनिटर करें
जब कीमत X से नीचे गिरे तो स्वतः किराए पर लें
वेबसॉकेट
Clore.ai REST API वर्तमान में WebSocket endpoint प्रदान नहीं करता है। रीयल-टाइम मॉनिटरिंग के लिए, उचित अंतराल पर polling का उपयोग करें (नीचे rate limits देखें)।
रेट सीमाएँ
एंडपॉइंट
सीमा
अधिकांश एंडपॉइंट
1 अनुरोध/सेकंड
create_order
1 अनुरोध/5 सेकंड
set_spot_price (मूल्य में कटौती)
प्रति 600 सेकंड
रेट-लिमिट प्रतिक्रिया (कोड 5):
सर्वोत्तम अभ्यास:
जोड़ें time.sleep(1) लगातार API कॉलों के बीच
के लिए create_order, अनुरोधों के बीच कम से कम 5 सेकंड प्रतीक्षा करें
मॉनिटरिंग लूप के लिए 60+ सेकंड के पोलिंग अंतराल का उपयोग करें
यदि आपको इसे बार-बार क्वेरी करना हो, तो मार्केटप्लेस डेटा को स्थानीय रूप से कैश करें
Python सहायक:
त्रुटि प्रबंधन
हर API प्रतिक्रिया में एक code फ़ील्ड शामिल होती है। इसका मान 0 सफलता का संकेत देता है।
त्रुटि कोड
कोड
अर्थ
कार्रवाई
0
सफलता
—
1
डेटाबेस त्रुटि
देरी के बाद पुनः प्रयास करें
2
अमान्य इनपुट डेटा
अपने अनुरोध बॉडी/पैरामीटर जाँचें
3
अमान्य API टोकन
डैशबोर्ड में अपनी API कुंजी सत्यापित करें
4
अमान्य एंडपॉइंट
एंडपॉइंट URL जाँचें
5
रेट सीमा पार हो गई (1 req/sec)
अनुरोधों के बीच देरी जोड़ें
6
एप्लिकेशन त्रुटि (देखें error फ़ील्ड)
विवरण के लिए error फ़ील्ड पढ़ें
कोड 6 उप-त्रुटियाँ
error मान
अर्थ
exceeded_max_step
स्पॉट मूल्य में कटौती बहुत बड़ी है; देखें max_step फ़ील्ड
can_lower_every_600_seconds
स्पॉट मूल्य को फिर से घटाने से पहले प्रतीक्षा करनी होगी; देखें time_to_lowering
Python त्रुटि प्रबंधन उदाहरण
JavaScript त्रुटि प्रबंधन उदाहरण
उपलब्ध Docker इमेजें
Clore.ai GPU वर्कलोड के लिए अनुकूलित पूर्व-निर्मित इमेजें प्रदान करता है:
इमेज
विवरण
cloreai/ubuntu20.04-jupyter
Ubuntu 20.04 + JupyterLab
cloreai/ubuntu22.04-jupyter
Ubuntu 22.04 + JupyterLab
आप कोई भी सार्वजनिक Docker Hub इमेज भी उपयोग कर सकते हैं। GPU एक्सेस के लिए, CUDA-सक्षम इमेजें उपयोग करें, जैसे:
पोर्ट फ़ॉरवर्डिंग
ऑर्डर बनाते समय, उजागर करने के लिए पोर्ट निर्दिष्ट करें:
curl -XPOST \\
-H 'auth: YOUR_API_KEY' \\
-H 'Content-type: application/json' \\
-d '{
"id": 38,
"issue": "GPU बहुत गर्म हो रहा था और प्रदर्शन थ्रॉटल कर रहा था"
}' \\
'https://api.clore.ai/v1/cancel_order'
pip install requests
import requests
import time
class CloreClient:
"""Clore.ai REST API के लिए सरल Python SDK."""
BASE_URL = "https://api.clore.ai/v1"
def __init__(self, api_key: str):
self.api_key = api_key
self.session = requests.Session()
self.session.headers.update({"auth": api_key})
def _get(self, endpoint: str, params: dict = None) -> dict:
url = f"{self.BASE_URL}/{endpoint}"
response = self.session.get(url, params=params)
response.raise_for_status()
data = response.json()
if data.get("code") != 0:
raise CloreAPIError(data)
return data
def _post(self, endpoint: str, body: dict) -> dict:
url = f"{self.BASE_URL}/{endpoint}"
self.session.headers.update({"Content-type": "application/json"})
response = self.session.post(url, json=body)
response.raise_for_status()
data = response.json()
if data.get("code") != 0:
raise CloreAPIError(data)
return data
def list_servers(self) -> list:
"""मार्केटप्लेस पर उपलब्ध सभी सर्वर प्राप्त करें."""
data = self._get("marketplace")
return data["servers"]
def get_server_details(self, server_id: int) -> dict:
"""किसी विशिष्ट सर्वर के लिए स्पॉट मार्केटप्लेस जानकारी प्राप्त करें."""
data = self._get("spot_marketplace", params={"market": server_id})
return data["market"]
def create_order(
self,
server_id: int,
image: str,
order_type: str = "on-demand",
currency: str = "bitcoin",
spotprice: float = None,
ports: dict = None,
ssh_password: str = None,
ssh_key: str = None,
jupyter_token: str = None,
env: dict = None,
command: str = None,
) -> dict:
"""
एक on-demand या spot ऑर्डर बनाएं।
आर्ग्स:
server_id: किराये पर लेने वाले सर्वर की ID
image: Docker image (उदा. 'cloreai/ubuntu20.04-jupyter')
order_type: 'on-demand' या 'spot'
currency: 'bitcoin' (डिफ़ॉल्ट)
spotprice: स्पॉट ऑर्डर के लिए आवश्यक — BTC में प्रति दिन कीमत
ports: पोर्ट फ़ॉरवर्डिंग, उदा. {"22": "tcp", "8888": "http"}
ssh_password: SSH पासवर्ड (केवल अल्फ़ान्यूमेरिक वर्ण)
ssh_key: SSH सार्वजनिक कुंजी
jupyter_token: Jupyter notebook टोकन
env: पर्यावरण चर का डिक्शनरी
command: कंटेनर शुरू होने के बाद चलाने के लिए शेल कमांड
"""
if order_type == "spot" and spotprice is None:
raise ValueError("spotprice is required for spot orders")
body = {
"currency": currency,
"image": image,
"renting_server": server_id,
"type": order_type,
}
if spotprice is not None:
body["spotprice"] = spotprice
if ports:
body["ports"] = ports
if ssh_password:
body["ssh_password"] = ssh_password
if ssh_key:
body["ssh_key"] = ssh_key
if jupyter_token:
body["jupyter_token"] = jupyter_token
if env:
body["env"] = env
if command:
body["command"] = command
return self._post("create_order", body)
def get_orders(self, include_completed: bool = False) -> list:
"""अपने सक्रिय (और वैकल्पिक रूप से पूर्ण) ऑर्डर प्राप्त करें."""
params = {"return_completed": "true"} if include_completed else {}
data = self._get("my_orders", params=params)
return data["orders"]
def cancel_order(self, order_id: int, issue: str = None) -> dict:
"""एक ऑर्डर रद्द करें। वैकल्पिक रूप से कोई समस्या रिपोर्ट करें."""
body = {"id": order_id}
if issue:
body["issue"] = issue
return self._post("cancel_order", body)
def get_wallets(self) -> list:
"""अपने वॉलेट और बैलेंस प्राप्त करें."""
data = self._get("wallets")
return data["wallets"]
def get_my_servers(self) -> list:
"""वे सर्वर प्राप्त करें जिन्हें आप मार्केटप्लेस को प्रदान कर रहे हैं."""
data = self._get("my_servers")
return data["servers"]
class CloreAPIError(Exception):
"""जब Clore API गैर-शून्य code लौटाती है, तब उठाया जाता है."""
ERROR_CODES = {
0: "सामान्य",
1: "डेटाबेस त्रुटि",
2: "अमान्य इनपुट डेटा",
3: "अमान्य API टोकन",
4: "अमान्य एंडपॉइंट",
5: "रेट सीमा पार हो गई (1 अनुरोध/सेकंड)",
6: "त्रुटि (त्रुटि फ़ील्ड देखें)",
}
def __init__(self, response: dict):
self.code = response.get("code")
self.error = response.get("error", "")
message = self.ERROR_CODES.get(self.code, f"अज्ञात code {self.code}")
if self.error:
message = f"{message}: {self.error}"
super().__init__(f"Clore API त्रुटि {self.code}: {message}")
import os
from clore_client import CloreClient, CloreAPIError
# क्लाइंट आरंभ करें
client = CloreClient(api_key=os.environ["CLORE_API_KEY"] )
# 1. मार्केटप्लेस ब्राउज़ करें
servers = client.list_servers()
print(f"मार्केटप्लेस पर {len(servers)} सर्वर मिले")
# 2. उपलब्ध RTX 4090 सर्वर फ़िल्टर करें
rtx4090_servers = [
s for s in servers
if "4090" in s["specs"].get("gpu", "") and not s["rented"]
]
if not rtx4090_servers:
print("कोई उपलब्ध RTX 4090 सर्वर नहीं मिला")
exit(1)
# 3. सबसे सस्ता चुनें
cheapest = min(rtx4090_servers, key=lambda s: s["price"]["on_demand"]["bitcoin"] )
print(f"सबसे सस्ता RTX 4090: सर्वर ID {cheapest['id']}, "
f"कीमत {cheapest['price']['on_demand']['bitcoin']:.8f} BTC/दिन")
# 4. ऑर्डर बनाएं
try:
client.create_order(
server_id=cheapest["id"],
image="cloreai/ubuntu20.04-jupyter",
order_type="on-demand",
currency="bitcoin",
ports={"22": "tcp", "8888": "http"},
ssh_password="SecurePass123",
jupyter_token="MyToken123",
)
print("ऑर्डर सफलतापूर्वक बनाया गया!")
except CloreAPIError as e:
print(f"ऑर्डर बनाने में विफल: {e}")
exit(1)
# 5. अपने ऑर्डर जांचें
orders = client.get_orders()
for order in orders:
if not order.get("expired"):
cluster = order.get("pub_cluster", [])
tcp = order.get("tcp_ports", [])
print(f"ऑर्डर {order['id']}: सर्वर {order['si']}")
if cluster and tcp:
ssh_port = tcp[0].split(":")[1]
print(f" SSH: ssh root@{cluster[0]} -p {ssh_port}")
from clore_client import CloreClient
client = CloreClient(api_key="YOUR_API_KEY")
def rent_cheapest_rtx4090(image="cloreai/ubuntu20.04-jupyter", ssh_password="SecurePass123"):
servers = client.list_servers()
# उपलब्ध RTX 4090 फ़िल्टर करें
candidates = [
s for s in servers
if "4090" in s["specs"].get("gpu", "")
and not s["rented"]
]
if not candidates:
raise RuntimeError("कोई उपलब्ध RTX 4090 सर्वर नहीं मिला")
# ऑन-डिमांड BTC कीमत के अनुसार क्रमबद्ध करें
candidates.sort(key=lambda s: s["price"]["on_demand"]["bitcoin"] )
best = candidates[0]
price_btc = best["price"]["on_demand"]["bitcoin"]
print(f"सर्वर {best['id']} किराए पर लिया जा रहा है: {best['specs']['gpu']} @ {price_btc:.8f} BTC/day")
client.create_order(
server_id=best["id"],
image=image,
order_type="on-demand",
currency="bitcoin",
ports={"22": "tcp"},
ssh_password=ssh_password,
)
print("हो गया! SSH कनेक्शन विवरण के लिए अपने ऑर्डर देखें।")
return best["id"]
rent_cheapest_rtx4090()
import time
from clore_client import CloreClient
client = CloreClient(api_key="YOUR_API_KEY")
def monitor_orders(poll_interval_seconds=60):
"""ऑर्डरों को पोल करें और स्थिति अपडेट प्रिंट करें।"""
print(f"ऑर्डरों की निगरानी की जा रही है (हर {poll_interval_seconds}s पर पोलिंग). रोकने के लिए Ctrl+C दबाएँ.\n")
while True:
orders = client.get_orders(include_completed=False)
active = [o for o in orders if not o.get("expired")]
print(f"--- {len(active)} सक्रिय ऑर्डर ---")
for order in active:
cluster = order.get("pub_cluster", [])
tcp = order.get("tcp_ports", [])
spend = order.get("spend", 0)
ssh_info = ""
if cluster and tcp:
port = tcp[0].split(":")[1]
ssh_info = f" | SSH: {cluster[0]}:{port}"
print(f" ऑर्डर {order['id']}: सर्वर {order['si']}"
f" | खर्च {spend:.8f} BTC{ssh_info}")
if not active:
print(" कोई सक्रिय ऑर्डर नहीं हैं.")
print()
time.sleep(poll_interval_seconds)
monitor_orders()
import time
from clore_client import CloreClient
client = CloreClient(api_key="YOUR_API_KEY")
def auto_rent_on_price_drop(
gpu_model: str = "RTX 4090",
max_price_btc: float = 0.00015,
image: str = "cloreai/ubuntu20.04-jupyter",
ssh_password: str = "SecurePass123",
check_interval_seconds: int = 120,
):
"""
मार्केटप्लेस पर नज़र रखें और कीमत सीमा से नीचे आने पर स्वतः GPU किराए पर लें।
आर्ग्स:
खोजने के लिए GPU मॉडल का नाम (केस-इन्सेंसिटिव)
BTC में प्रति दिन अधिकतम स्वीकार्य कीमत
तैनात करने के लिए Docker इमेज
कंटेनर के लिए SSH पासवर्ड
कितनी बार जाँच करनी है (rate limits का सम्मान करें!)
"""
print(f"{gpu_model} को ≤ {max_price_btc:.8f} BTC/day पर देख रहे हैं...")
while True:
servers = client.list_servers()
for server in servers:
gpu = server["specs"].get("gpu", "")
if gpu_model.lower() not in gpu.lower():
continue
if server["rented"]:
continue
price = server["price"]["on_demand"]["bitcoin"]
if price <= max_price_btc:
print(f"🎯 मैच मिल गया! सर्वर {server['id']}: {gpu} @ {price:.8f} BTC/day")
try:
client.create_order(
server_id=server["id"],
image=image,
order_type="on-demand",
currency="bitcoin",
ports={"22": "tcp"},
ssh_password=ssh_password,
required_price=price, # इस कीमत को लॉक करें
)
print(f"✅ सर्वर {server['id']} के लिए ऑर्डर बना दिया गया!")
return server["id"]
except Exception as e:
print(f"ऑर्डर बनाने में विफल: {e}. पुनः प्रयास किया जाएगा...")
print(f"अभी तक कोई मेल नहीं मिला. {check_interval_seconds}s में फिर जाँच करेंगे...")
time.sleep(check_interval_seconds)
auto_rent_on_price_drop(gpu_model="4090", max_price_btc=0.00012)
{ "code": 5 }
import time
def safe_api_call(fn, *args, delay=1.1, **kwargs):
"""रेट-लिमिट सुरक्षा के साथ API कॉल को रैप करें।"""
result = fn(*args, **kwargs)
time.sleep(delay)
return result
from clore_client import CloreClient, CloreAPIError
import time
client = CloreClient(api_key="YOUR_API_KEY")
def create_order_with_retry(server_id, image, max_retries=3):
for attempt in range(max_retries):
try:
return client.create_order(
server_id=server_id,
image=image,
order_type="on-demand",
currency="bitcoin",
ports={"22": "tcp"},
ssh_password="SecurePass123",
)
except CloreAPIError as e:
if e.code == 5: # रेट सीमा
print(f"रेट सीमा लगी। 5s प्रतीक्षा कर रहे हैं... (प्रयास {attempt+1}/{max_retries})")
time.sleep(5)
elif e.code == 3: # खराब API कुंजी
print("अमान्य API कुंजी! अपनी CLORE_API_KEY जाँचें.")
raise
elif e.code == 2: # खराब इनपुट
print(f"अमान्य अनुरोध: {e}")
raise
else:
print(f"API त्रुटि: {e}. 3s में पुनः प्रयास किया जाएगा...")
time.sleep(3)
raise RuntimeError(f"{max_retries} प्रयासों के बाद विफल")
async function createOrderWithRetry(client, serverConfig, maxRetries = 3) {
for (let attempt = 0; attempt < maxRetries; attempt++) {
try {
return await client.createOrder(serverConfig);
} catch (err) {
const code = parseInt(err.message.match(/error (\d+)/)?.[1]);
if (code === 5) {
console.log(`रेट सीमा लगी। 5s प्रतीक्षा कर रहे हैं... (प्रयास ${attempt + 1}/${maxRetries})`);
await new Promise(r => setTimeout(r, 5000));
} else if (code === 3) {
throw new Error('अमान्य API कुंजी');
} else {
console.log(`API त्रुटि: ${err.message}. 3s में पुनः प्रयास किया जाएगा...`);
await new Promise(r => setTimeout(r, 3000));
}
}
}
throw new Error(`${maxRetries} प्रयासों के बाद विफल`);
}