Python SDK 快速入门
在 5 分钟内通过 Python 或终端找到一张 GPU、租用它并通过 SSH 登录——全部完成
最后更新于
这有帮助吗?
这有帮助吗?
clore config set api_key YOUR_API_KEYclore search --gpu "RTX 4090" --max-price 5.0 --sort price --limit 10from clore_ai import CloreAI
client = CloreAI()
servers = client.marketplace(gpu="RTX 4090", max_price_usd=5.0)
for s in servers[:5]:
print(f"Server {s.id}: {s.gpu_count}x {s.gpu_model} — ${s.price_usd:.4f}/h — {s.location}")Server 142: 1x NVIDIA GeForce RTX 4090 — $0.0800/h — EU
Server 305: 1x NVIDIA GeForce RTX 4090 — $0.0950/h — US
Server 891: 2x NVIDIA GeForce RTX 4090 — $0.1200/h — EUclore deploy 142 \
--image cloreai/ubuntu22.04-cuda12 \
--type on-demand \
--currency bitcoin \
--ssh-password MySecurePass123 \
--port 22:tcp \
--port 8888:httporder = client.create_order(
server_id=142,
image="cloreai/ubuntu22.04-cuda12",
type="on-demand",
currency="bitcoin",
ssh_password="MySecurePass123",
ports={"22": "tcp", "8888": "http"}
)
print(f"Order created! ID: {order.id}")
print(f"IP: {order.pub_cluster}")
print(f"Ports: {order.tcp_ports}")CLI(自动连接)手动 SSH
ssh root@<pub_cluster> -p <ssh_port>完成后取消订单以停止计费:clore cancel 38
client.cancel_order(order_id=38, issue="Done with my work")from clore_ai import CloreAI
完整脚本:搜索 → 部署 → 监控 → 取消
import time
client = CloreAI() # 使用 CLORE_API_KEY 环境变量
servers = client.marketplace(gpu="RTX 4090", max_price_usd=5.0)
# 1. 找到最便宜的 RTX 4090
servers.sort(key=lambda s: s.price_usd or float("inf"))
if not servers:
print("没有低于 $5/h 的 RTX 4090 可用")
exit(1)
best = servers[0]
print(f"最佳优惠:Server {best.id} — ${best.price_usd:.4f}/h — {best.location}")
order = client.create_order(
# 2. 部署
image="cloreai/ubuntu22.04-cuda12",
type="on-demand",
currency="bitcoin",
ssh_password="MySecurePass123",
server_id=best.id,
)
ports={"22": "tcp"}
print(f"Order {order.id} created!")
# 3. 等待分配 IP
for _ in range(12):
orders = client.my_orders()
current = next((o for o in orders if o.id == order.id), None)
if current and current.pub_cluster:
print(f"已就绪!SSH: ssh root@{current.pub_cluster} -p {current.tcp_ports.get('22', 22)}")
break
print("等待服务器启动...")
time.sleep(10)
# 4. ... 执行您的工作 ...
# 5. 完成后取消
client.cancel_order(order_id=order.id)