列出 GPU 目錄
curl https://gputw.ai/api/gpus/active列出可用機器
curl -H "Authorization: Bearer $GPUTW_API_KEY" "https://gputw.ai/api/nodes/available?catalogId=<catalog-id>"每台機器都帶有 fastVault:true 表示機器就在儲存庫旁的機櫃裡,讀寫 /vault 快好幾倍;false 是遠端機器;null 表示不確定。每次啟動都要從 /vault 載入大型模型或資料集的工作,請優先選 true。見 GPU 目錄。
建立執行個體
curl -X POST https://gputw.ai/api/instances/create \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"nodeId":"<node-id>","bandwidthMbps":100,"templateId":"<template-id>","ports":[8080]}'部署公開自訂映像
以 customImage 取代 templateId,即可部署 Docker Hub、GHCR 等公開 registry 的任意映像。映像參考必須帶明確的非 latest tag 或 sha256 digest。啟用 sshEnabled 時以 root 搭配帳戶的 SSH 金鑰登入——金鑰會自動注入;若映像沒有 SSH 伺服器,系統會在啟動時自動安裝(映像需以 root 執行並內含 apk/apt/dnf 等套件管理器)。也可改為宣告 Web UI。選填 env 可注入環境變數;選填 args 會取代映像的 CMD(ENTRYPOINT 保留不變)。
curl -X POST https://gputw.ai/api/instances/create \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"nodeId":"<node-id>","bandwidthMbps":100,"customImage":{"dockerImage":"ghcr.io/acme/trainer:1.4.2","sshEnabled":true,"env":[{"name":"HF_TOKEN","value":"hf_xxx"}],"args":["--port","8080"]},"ports":[8080]}'部署私有自訂映像
私有 registry 請加上 registryAuth。GPUtw 會轉成短效的 image pull secret,並在執行個體停止、失敗或終止時刪除已儲存的憑證。設定 webUiEnabled 並搭配 webUiLabel 與 webUiPort 即可開放瀏覽器介面。
curl -X POST https://gputw.ai/api/instances/create \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"nodeId":"<node-id>","bandwidthMbps":100,"customImage":{"dockerImage":"registry.example.com/team/app:2025-06-30","registryAuth":{"registry":"registry.example.com","username":"<user>","password":"<token>"},"webUiEnabled":true,"webUiLabel":"My App","webUiPort":8080}}'自訂映像部署需要 instances:create 權限。拉取映像時間會計入帳務,且 customImage 不可與 templateId/template 併用。公開映像請省略 registryAuth。env 最多 32 筆(名稱格式 [A-Za-z_][A-Za-z0-9_]*;平台保留的 PUBLIC_KEY、GATEWAY_KEY、NVIDIA_VISIBLE_DEVICES、NVIDIA_DRIVER_CAPABILITIES 會被拒絕);args 最多 64 個。
將執行中的執行個體切換為自訂映像
以 PUT /instances/<id> 帶入 customImage 物件(欄位與建立時相同),會在同一台機器上就地重新部署。執行個體不會被停止,拉取新映像期間 GPU 仍保留給你(狀態先顯示 DEPLOYING,再變成 RUNNING)。容器會重建,因此執行個體內 /vault 以外的所有資料都會清除(/workspace、/home、/root、已安裝的套件),與停止相同。
curl -X PUT https://gputw.ai/api/instances/<instance-id> \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"customImage":{"dockerImage":"docker.io/acme/trainer:v3","sshEnabled":true}}'需要 instances:manage 與 instances:create 權限(自訂映像需要與建立時相同的權限)。拉取映像的計費與自訂映像部署相同:拉取成功不另外計費;映像若在 45 分鐘內未能啟動,部署期間會計費。若映像無法啟動,執行個體會變成 FAILED 並釋出 GPU,建議先用 POST /instances/validate-image 驗證映像。customImage 不可與 templateId/template 併用;改傳 templateId 則會切回目錄映像,並刪除已儲存的 registry 憑證。
停止執行個體
curl -X POST https://gputw.ai/api/instances/stop \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"instanceId":"<instance-id>"}'為執行個體命名
每台執行個體都有名稱(最多 40 個字),方便分辨多台相似的機器。建立時若沒有帶 name,會自動取下一個可用的 GPU 1、GPU 2…;之後也可以隨時改名,傳空字串則重設為下一個預設名稱。需要 instances:manage 範圍。每個執行個體物件都會帶回 name 欄位。
# 建立時命名
curl -X POST https://gputw.ai/api/instances/create \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"nodeId":"<node-id>","bandwidthMbps":100,"templateId":"<template-id>","name":"training-1"}'
# 之後改名
curl -X PATCH https://gputw.ai/api/instances/<instance-id>/name \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name":"llama-finetune"}' # 或 {"name":""} 重設為下一個 GPU N設定自動停止
讓執行個體在幾小時後或指定時間自動停止。建立時帶入 autoStopHours(或 ISO 格式的 autoStopAt),或之後再設定、延長、取消;時間需在 10 分鐘後到 30 天內。需要 instances:manage 範圍,與停止相同。停止前 30 分鐘與 5 分鐘會通知你。
# 建立時設定
curl -X POST https://gputw.ai/api/instances/create \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"nodeId":"<node-id>","bandwidthMbps":100,"templateId":"<template-id>","autoStopHours":4}'
# 之後:設定時間、延長或取消
curl -X PATCH https://gputw.ai/api/instances/<instance-id>/auto-stop \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"autoStopAt":"2026-11-01T18:00:00+08:00"}' # 或 {"extendHours":1} / {"autoStopAt":null}時間到時執行個體會被停止,效果與上面的停止 API 相同:/workspace 會被清空,只有 /vault 會保留。若想在工作跑完就立刻停止,請在腳本最後執行 gputw-shutdown(見「從執行個體內部關機」)。
重新啟動已停止的執行個體
已停止(或失敗)的執行個體可以在同一台機器上重新啟動;若那台機器正在使用中,也可以改到另一台同型號的空閒機器。restart-options 會告訴你哪種可行。需要 instances:manage 範圍。
# 可以在哪裡啟動?
curl https://gputw.ai/api/instances/<instance-id>/restart-options \
-H "Authorization: Bearer $GPUTW_API_KEY"
# 同一台機器(或:{"mode":"alternative","nodeId":"<node-id>"})
curl -X POST https://gputw.ai/api/instances/<instance-id>/restart \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"mode":"same"}'刪除執行個體
刪除會停止計費,並永久移除執行個體與其中所有資料;只有 /vault 會保留。delete-stopped 一次移除所有已停止或失敗的執行個體(也可只傳指定的 id),回應會列出 deleted 與 skipped;維護中的執行個體會被略過。需要 instances:manage 範圍。
curl -X POST https://gputw.ai/api/instances/delete \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"instanceId":"<instance-id>"}'
# 所有已停止/失敗的(可選:{"instanceIds":[...]})
curl -X POST https://gputw.ai/api/instances/delete-stopped \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'監控指標、啟動紀錄與歷史
即時的 GPU/VRAM/CPU/RAM/網路取樣(range:1h、6h 或 24h)、啟動中或失敗部署的啟動紀錄、生命週期事件,以及計費的執行紀錄。皆需要 instances:read 範圍。
curl https://gputw.ai/api/instances/<instance-id>/metrics?range=6h \
-H "Authorization: Bearer $GPUTW_API_KEY"
curl https://gputw.ai/api/instances/<instance-id>/startup-log \
-H "Authorization: Bearer $GPUTW_API_KEY"
curl https://gputw.ai/api/instances/<instance-id>/events \
-H "Authorization: Bearer $GPUTW_API_KEY"
curl https://gputw.ai/api/instances/<instance-id>/runs \
-H "Authorization: Bearer $GPUTW_API_KEY"值得知道的執行個體欄位
每個執行個體物件(GET /instances、GET /instances/<id>)除了狀態之外還帶有:
- name: 執行個體名稱(見上方)。
- diskUsedGb / diskLimitGb: 已使用的磁碟,以及寫入開始失敗的上限(租用磁碟加上容器本身檔案的額度),單位 GB。執行中約每 10 分鐘量測一次;第一次量測前為 null。
- diskUsageAt: 這次讀數的時間。時間太舊就視為過時。
- maintenanceSince: 執行個體底下的機器維修期間有值,其餘時候為 null。維護期間不計費。
maintenanceSince 有值時,停止、刪除、重新啟動、重新設定與重啟容器都會被拒絕:
HTTP/1.1 409 Conflict
{"success":false,"data":null,"error":"This instance is under maintenance: its machine is being repaired. It is not billed meanwhile and your data is kept. It will come back automatically.","code":"INSTANCE_IN_MAINTENANCE"}請依 code 判斷,不要比對訊息文字。稍後再試即可,執行個體會自己回來。見 狀態與OOM。
管理 HTTP 連接埠
curl -X PATCH https://gputw.ai/api/instances/<instance-id>/ports \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"ports":[8080,18080],"portAccess":{"8080":{"mode":"unlisted","password":"strong-password"},"18080":{"mode":"public"}}}'建立 raw TCP exposure
將容器連接埠對應到 tcp.gputw.ai 上由平台指派的公開連接埠,回應會回傳指派的 endpoint。
curl -X POST https://gputw.ai/api/instances/<instance-id>/exposures \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"protocol":"tcp","containerPort":25565}'建立 raw UDP exposure
將 protocol 設為 udp,適用於 datagram 服務(遊戲伺服器、WireGuard、QUIC 等)。系統會在 udp.gputw.ai 指派獨立的公開連接埠——TCP 與 UDP 的連接埠是分開配置的,因此相同號碼可能同時出現在兩者上。
curl -X POST https://gputw.ai/api/instances/<instance-id>/exposures \
-H "Authorization: Bearer $GPUTW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"protocol":"udp","containerPort":51820}'Raw TCP/UDP 端點是未驗證的 L4 直通連線。請使用本身具備驗證的服務,且切勿 raw 暴露未驗證的 web UI。以 DELETE /api/instances/{id}/exposures/{exposureId} 移除曝露,移除後該公開連接埠會釋出供重用。