RunPower 开放API接口说明
RunPower API 提供GPU算力资源的查询、创建、管理等功能。基础URL: /api
登录后获取Token,在请求头中传:
Authorization: Bearer <your-token>
在控制台创建API Key后,在请求头中传:
X-API-Key: sk-lunxd-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
获取可用GPU列表及价格
curl -X GET https://your-host/api/gpu/list \
-H "X-API-Key: sk-lunxd-xxxxxxxx"
获取我的实例列表
curl -X GET https://your-host/api/instances \
-H "Authorization: Bearer <token>"
创建GPU实例
curl -X POST https://your-host/api/gpu/create \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"gpu_type": "RTX 4090", "hours": 10}'
停止GPU实例
curl -X POST https://your-host/api/gpu/stop \
-H "Authorization: Bearer <token>" \
-d '{"instance_id": 1}'
获取实例详情
获取账单列表
curl -X GET https://your-host/api/bills?page=1&page_size=20 \
-H "Authorization: Bearer <token>"
获取账单汇总
import requests
class RunPowerClient:
def __init__(self, api_key=None, token=None, base_url="https://your-host"):
self.base_url = base_url
self.session = requests.Session()
if api_key:
self.session.headers["X-API-Key"] = api_key
elif token:
self.session.headers["Authorization"] = f"Bearer {token}"
def list_gpus(self):
r = self.session.get(f"{self.base_url}/api/gpu/list")
return r.json()
def list_instances(self):
r = self.session.get(f"{self.base_url}/api/instances")
return r.json()
def create_instance(self, gpu_type, hours, image_id=None):
data = {"gpu_type": gpu_type, "hours": hours}
if image_id:
data["image_id"] = image_id
r = self.session.post(f"{self.base_url}/api/gpu/create", json=data)
return r.json()
def stop_instance(self, instance_id):
r = self.session.post(f"{self.base_url}/api/gpu/stop",
json={"instance_id": instance_id})
return r.json()
# 使用示例
client = RunPowerClient(api_key="sk-lunxd-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
gpus = client.list_gpus()
print(gpus)