开发者参考
可编程的全球算力。
三大 API 接口族,通过 HTTPS 传输标准 JSON,覆盖物理基础设施、任务部署与算力交易。
身份验证与基础地址
在控制台创建 Bearer API 密钥:/dashboard/keys。请保留在服务端,并设置为 XCITY_API_KEY 环境变量。每个生产请求均需发送 Authorization: Bearer <key>。
https://api.xcity.net/v1下方接口路径已包含 /v1,只需拼接到 https://api.xcity.net。Python 示例使用 requests 包(pip install requests)。max_price 为每 GPU 小时价格上限;count 为 GPU 数量。
生产 API 在此作为集成契约说明。本仓库仅实现下方三个只读静态演示接口;示例中的任务提交、预留及市场写入操作并非此站点的已上线接口。
Management API · 管理
查看区域基础设施并管理设施与集群。Facility API 与 Cluster API 属于此接口族。
| 方法 | 接口 | 用途 / 请求 |
|---|---|---|
GET | /v1/regions | 列出区域、已投运 MW、GPU、PUE 与健康指标。 |
GET | /v1/facilities | 列出供电、冷却与设施容量。 |
GET | /v1/clusters | 查看集群资源与节点健康。 |
POST | /v1/clusters/{id}/actions | 提交 {action: "scale" | "drain" | "reboot"};扩缩容另需 count。 |
curl
curl https://api.xcity.net/v1/regions \
-H "Authorization: Bearer $XCITY_API_KEY"Python
import os
import requests
response = requests.get(
"https://api.xcity.net/v1/regions",
headers={"Authorization": f"Bearer {os.environ['XCITY_API_KEY']}"},
timeout=30,
)
response.raise_for_status()
for region in response.json()["data"]:
print(region["id"], region["gpu_count"])Scheduling API · 调度
提交容器任务、监控任务状态、取消运行并预留容量。
| 方法 | 接口 | 用途 / 请求 |
|---|---|---|
POST | /v1/jobs | 提交 image、gpu_type、count、region 提示与 max_price(美元/GPU 小时)。 |
GET | /v1/jobs/{id} | 读取状态:queued、running、completed、failed 或 cancelled。 |
DELETE | /v1/jobs/{id} | 取消排队或运行中的任务。 |
POST | /v1/reservations | 预留 region、gpu_type、count、start_at 与 duration_hours。 |
curl
curl -X POST https://api.xcity.net/v1/jobs \
-H "Authorization: Bearer $XCITY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"image":"ghcr.io/xcity/training:latest","gpu_type":"H200","count":8,"region":"latam-1","max_price":1.8}'Python
import os
import requests
response = requests.post(
"https://api.xcity.net/v1/jobs",
headers={"Authorization": f"Bearer {os.environ['XCITY_API_KEY']}"},
json={
"image": "ghcr.io/xcity/training:latest",
"gpu_type": "H200", "count": 8,
"region": "latam-1", "max_price": 1.80,
},
timeout=30,
)
response.raise_for_status()
print(response.json()["id"])Marketplace API · 售卖
发布可用容量、比较报价、下单并查看区域 GPU 小时价格。
| 方法 | 接口 | 用途 / 请求 |
|---|---|---|
GET | /v1/market/offers | 发现可用供应商容量与报价 ID。 |
POST | /v1/market/offers | 出售容量:region、gpu_type、count、price_per_gpu_hour、available_until。 |
POST | /v1/market/orders | 购买报价:offer_id、count、duration_hours。 |
GET | /v1/market/prices | 按区域与 GPU 类别读取当前按需、现货与预留价格。 |
curl
curl -X POST https://api.xcity.net/v1/market/offers \
-H "Authorization: Bearer $XCITY_API_KEY" \
-H "Content-Type: application/json" \
-d '{"region":"latam-1","gpu_type":"H200","count":8,"price_per_gpu_hour":1.65,"available_until":"2027-01-01T00:00:00Z"}'Python
import os
import requests
response = requests.post(
"https://api.xcity.net/v1/market/orders",
headers={"Authorization": f"Bearer {os.environ['XCITY_API_KEY']}"},
json={"offer_id": "offer_xct_01", "count": 8, "duration_hours": 24},
timeout=30,
)
response.raise_for_status()
print(response.json())试一试 · 静态 JSON 演示
以下同源公开示例无需 API 密钥。它们与页面使用相同区域与价格数据,均返回 {"object":"list","data":[...]},是静态快照,并非实时行情。