目录

简介 认证方式 GPU查询 实例管理 账单 Python SDK

API 文档

RunPower 开放API接口说明

简介

RunPower API 提供GPU算力资源的查询、创建、管理等功能。基础URL: /api

认证方式

方式一:JWT Token(推荐)

登录后获取Token,在请求头中传:

Authorization: Bearer <your-token>

方式二:API Key

在控制台创建API Key后,在请求头中传:

X-API-Key: sk-lunxd-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

GPU查询

GET /api/gpu/list

获取可用GPU列表及价格

curl -X GET https://your-host/api/gpu/list \
  -H "X-API-Key: sk-lunxd-xxxxxxxx"

实例管理

GET /api/instances

获取我的实例列表

curl -X GET https://your-host/api/instances \
  -H "Authorization: Bearer <token>"

POST /api/gpu/create

创建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}'

POST /api/gpu/stop

停止GPU实例

curl -X POST https://your-host/api/gpu/stop \
  -H "Authorization: Bearer <token>" \
  -d '{"instance_id": 1}'

GET /api/instance/{id}

获取实例详情

账单

GET /api/bills

获取账单列表

curl -X GET https://your-host/api/bills?page=1&page_size=20 \
  -H "Authorization: Bearer <token>"

GET /api/bills/summary

获取账单汇总

Python SDK 示例

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)