{
  "openapi": "3.1.0",
  "info": {
    "title": "Ocent云计算 开放 API",
    "version": "1.0.0",
    "description": "用一把长期有效的 **API 密钥**，在脚本、机器人、CI 或 AI 代理中管理自己账户下的资源：查询账户、钱包与商店；管理游戏服务器（开关机、控制台、配置、端口、SFTP、文件、Steam 创意工坊、续费与套餐）；管理云服务器（开关机、重装、密码、购买、续费、释放）。\n\n开放 API 与网页面板使用**同一套接口**（同一 URL、请求与响应格式），区别只在认证方式。API 密钥只能调用本文列出的接口，只能操作密钥所属账户自己的资源；他人的实例或云服务器一律返回 `404 not_found`。\n\n## 认证\n\n在「账户 → API 密钥」创建密钥。完整密钥（`ock_` 加 48 位小写十六进制）**只在创建时显示一次**，之后列表只显示前 12 位前缀。每个请求带请求头：\n\n```\nAuthorization: Bearer ock_xxxxxxxx\n```\n\n```sh\nexport OCENT_API_KEY='ock_xxxxxxxx'   # 不要写进代码仓库\ncurl -s https://ocent.net/api/v1/auth/me -H \"Authorization: Bearer $OCENT_API_KEY\"\n```\n\n- 平台只保存密钥的 SHA-256 摘要，丢失后只能删除并重新创建。\n- 密钥以所属用户身份行事，权限不会超过该用户；管理员的密钥也不能访问管理端接口。\n- 修改登录密码、通过邮件重置密码、被管理员重置密码或强制下线、删除账号时，该账户的**全部密钥会被删除**。账号被禁用时密钥立即不可用（`403 account_disabled`），解除禁用后恢复。\n- 密钥的创建与删除只能在网页面板完成（需再次输入登录密码），密钥本身不能管理密钥。\n- 网页控制台、星露谷远程桌面与云服务器网页 VNC 的 WebSocket 只接受网页登录，**不接受 API 密钥**；脚本请改用控制台 REST 接口（读日志、发命令）。\n\n| HTTP | code | 说明 |\n| --- | --- | --- |\n| 401 | `unauthorized` | 缺少 `Authorization: Bearer ...` 头 |\n| 401 | `invalid_api_key` | 格式不对、已删除或所属用户不存在，停止重试 |\n| 401 | `api_key_expired` | 到达创建时选择的有效期，换新密钥 |\n| 403 | `account_disabled` | 账户被禁用 |\n\n## 权限范围（scope）\n\n| scope | 含义 |\n| --- | --- |\n| `read` | 只读查询；总是包含，无法去掉 |\n| `write` | 不直接产生资金变动的变更（开关机、发命令、改配置、写文件、重装等），以及读取凭据（SFTP 密码、云服务器登录密码、密码类变量的值） |\n| `billing` | 涉及资金或资源生命周期：开服、续费、改套餐、切换游戏、删除实例、购买/续费/释放云服务器、优惠码试算 |\n\n- `write` 与 `billing` 互不包含，两者都需要时都要勾选。缺少权限返回 `403 insufficient_scope`，响应体带 `required_scope`。\n- 两类 `write` 请求会导致后续扣费，**额外要求 `billing`**：把实例或云服务器的 `auto_renew` 从关闭改为开启；让**按小时计费**的实例从非运行状态 `start` / `restart`。\n- 按小时实例在 `write` 下重装时，安装期间仍按运行价计费。\n- `read` 不等于“无敏感信息”：它能读取实例的全部文件，游戏配置里可能有 RCON 或服务器密码。没有 `write` 时，`input_type=password` 的变量值会被清空并标记 `value_redacted: true`，但这挡不住从配置文件读取。\n\n每个接口的所需权限标注在接口标题旁。\n\n## 默认拒绝\n\n只有本文列出的「方法 + 路径」可以用 API 密钥调用，其余已登录接口一律返回 `403 api_key_forbidden`。不开放的能力包括：管理端接口、修改密码 / 实名认证 / QQ 绑定、充值与扫码直付、邀请返利与提现、工单、AI 报错分析、星露谷管理面板、API 密钥管理本身，以及网页控制台与 VNC 的 WebSocket。\n\n## 限流\n\n1. 每个客户端 IP **1200 次/分钟**（所有带 `Bearer ock_...` 的请求，含无效密钥）。\n2. 每个密钥 **300 次/分钟**（所有接口合计；被白名单或权限拒绝的请求不计入）。\n3. 部分接口另有自身限额，与网页面板共享，见各接口说明。\n\n超限返回 `429 rate_limited`，**不带** `Retry-After` 头，请指数退避（1 秒、2 秒、4 秒……加随机抖动）。被限流的请求没有进入业务处理，可安全重试。限流存储暂不可用时返回 `503 rate_limit_unavailable`。\n\n## 错误格式\n\n```json\n{\"error\": \"中文可读消息\", \"code\": \"snake_case_机器码\"}\n```\n\n- 请按 `code` 判断，`error` 仅用于展示，文案可能调整。对未知 `code` 按 HTTP 状态码兜底。\n- 少数错误带额外字段：`insufficient_scope` 带 `required_scope`；`price_changed` 带 `diff_cents` / `hourly_price_cents` / `price_cents`；`invalid_variable` 带 `field`；`provision_failed` 带 `instance_id`。\n- `504 agent_timeout` / `timeout` 表示节点响应超时，操作可能已部分完成，先查询状态再决定是否重试。\n\n## 通用约定\n\n- **金额是整数「分」**（人民币）：`balance_cents: 12345` 即 ¥123.45，不要用浮点数计算。`oc_coins`（OC币积分）是整数个数，不是金额。\n- **时间**：RFC 3339 字符串（UTC，如 `2026-12-01T08:00:00Z`），可能为 `null`。**ID**：正整数（64 位）。\n- **分页**：钱包流水用 `limit`（1–100，默认 20）与 `offset`，返回 `{items,total,limit,offset}`，按 `id` 倒序；实例与云服务器列表不分页。\n- **请求体**：一般 JSON 请求体上限 2 MiB（`413 body_too_large`）；文本文件写入上限 4 MiB；上传单文件上限由节点决定（目录列表的 `max_upload_bytes`）。\n- **没有幂等键**：开服、续费、购买等扣费请求网络超时或中断后**不要直接重试**，先用实例列表、钱包流水或云服务器列表确认是否已成功。\n- **长请求**：开服、重装、改套餐、修改设置等在服务端同步等待节点，可能需要数分钟（上限约 20 分钟）；开关机最长约 5 分钟；压缩/解压最长 30 分钟。客户端超时建议至少 25 分钟。客户端断开后服务端**仍会继续执行**，可能出现“客户端已超时，但服务端已完成并扣费”。\n- **价格确认**：改套餐必须带 `expected_diff_cents`，云服务器购买/续费可带 `expected_price_cents`；价格不一致时返回 `409 price_changed` 且不扣费。\n- v1 内只做向后兼容的变更（新增接口、字段、错误码、枚举值），客户端应忽略未知字段。\n\n## 状态值\n\n**游戏服务器 `status`**：`provisioning`（已扣费，正在创建）、`installing`（正在安装）、`install_failed`（安装失败，需重新安装）、`starting`、`running`、`stopped`（新建或安装完成后默认停止，需手动开机）、`error`（详见 `status_detail` / `last_error`）、`expired`（已到期停机，续费后恢复；到期若干天后会被自动删除，见 `delete_at`）。\n\n**`install_status`**：`\"\"`、`installing`、`installed`、`failed`。**`billing_mode`**：`monthly`、`hourly`。**节点 `status`**：`pending`、`online`、`offline`、`error`。\n\n**云服务器 `status`**：`provisioning`、`running`、`stopped`、`starting`、`stopping`、`rebooting`、`reinstalling`、`expired`（到期已关机，宽限期内续费可恢复）、`terminated`（已释放）、`error`（创建失败已退款、重装失败或上游资源不存在）。\n\n## 安全建议\n\n- **最小权限**：监控只给 `read`；运维脚本给 `read` + `write`；只有确实需要开服、续费、删除时才给 `billing`，并设置短有效期、用完即删。\n- **一用途一密钥**：不同脚本、不同机器用不同密钥，便于单独吊销，也能从「最近使用时间 / IP」发现异常。\n- **不要泄露**：不要把密钥写进代码仓库、前端页面、截图、日志或工单；只通过 HTTPS 调用。\n- **AI 代理**：扣费或删除数据（删除实例、切换游戏、重装、释放云服务器、强制停止）前应征得你的确认；`ocent` 命令行工具对这类操作要求显式 `--yes`。\n- **审计**：通过密钥发起的非 GET 请求会记录在平台审计日志（密钥前缀、方法、路由与响应状态，不含请求体）；查询请求不记录。\n- **泄露处理**：立即在「API 密钥」页面删除该密钥（即时生效），检查钱包流水与资源列表；怀疑账号被盗时修改登录密码，会同时删除全部密钥。\n- **玩家输入**：把玩家消息转发到控制台命令时要自行过滤，命令以服务器控制台身份执行。"
  },
  "servers": [
    {
      "url": "https://ocent.net/api/v1",
      "description": "生产环境"
    }
  ],
  "security": [
    {
      "ApiKey": []
    }
  ],
  "tags": [
    {
      "name": "account",
      "x-displayName": "账户",
      "description": "当前用户信息。"
    },
    {
      "name": "store",
      "x-displayName": "商店",
      "description": "游戏服务器与云服务器的在售商品、套餐与优惠码试算。"
    },
    {
      "name": "wallet",
      "x-displayName": "钱包",
      "description": "余额、钱包流水与 OC币流水。充值只能在网页面板完成。"
    },
    {
      "name": "instances",
      "x-displayName": "游戏服务器",
      "description": "游戏服务器实例的查询、开服与删除。"
    },
    {
      "name": "power",
      "x-displayName": "电源与控制台",
      "description": "开机、停止、重启、强制停止，读取控制台输出与发送控制台命令。"
    },
    {
      "name": "config",
      "x-displayName": "配置与变量",
      "description": "启动参数、运行镜像、自动续费、变量、重新安装与切换游戏。"
    },
    {
      "name": "network",
      "x-displayName": "端口与 SFTP",
      "description": "端口映射、SFTP 凭据与 Steam 在线人数查询。"
    },
    {
      "name": "files",
      "x-displayName": "文件",
      "description": "实例数据目录内的文件管理：列目录、读写文本、上传下载、压缩解压、移动、删除、改权限。"
    },
    {
      "name": "workshop",
      "x-displayName": "Steam",
      "description": "Steam 创意工坊物品的查询、订阅与移除。"
    },
    {
      "name": "billing-ops",
      "x-displayName": "续费与套餐",
      "description": "游戏服务器的续费、改套餐、删除退款试算。"
    },
    {
      "name": "vps",
      "x-displayName": "云服务器",
      "description": "云服务器的查询、电源、重装系统、密码、购买、续费与释放。"
    }
  ],
  "paths": {
    "/auth/me": {
      "get": {
        "operationId": "getCurrentUser",
        "summary": "当前用户信息",
        "description": "返回 API 密钥所属用户的基本信息、余额与 OC币积分。\n\n- 只读，无副作用；适合用来验证密钥是否可用（`ocent auth login` 保存密钥前就会调用它）。\n- 响应**不包含**当前密钥的任何信息（名称、权限范围、到期时间），密钥管理只能在网页面板完成。\n- `realname_verified` 只表示是否已通过实名认证，不返回姓名或证件号。\n- 使用 API 密钥时永远不会出现网页端代登录才有的 `impersonator` 字段。",
        "tags": [
          "account"
        ],
        "x-scope": "read",
        "x-cli": "ocent whoami",
        "responses": {
          "200": {
            "description": "当前用户。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountMeResponse"
                },
                "example": {
                  "user": {
                    "id": 1001,
                    "email": "you@example.com",
                    "display_name": "示例用户",
                    "role": "user",
                    "balance_cents": 12345,
                    "oc_coins": 120,
                    "email_verified": true,
                    "invite_code": "K7MQ2XPA",
                    "created_at": "2026-11-01T08:00:00Z",
                    "realname_verified": false
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/store": {
      "get": {
        "operationId": "getGameStore",
        "summary": "游戏服务器商店",
        "description": "列出在售的节点（含各节点在售套餐）与在售游戏（含版本与整合包），用于开服前选择商品。\n\n- `nodes` 按名称升序；每个节点的 `plans` 按 `sort_order`、月价、ID 升序，节点没有在售套餐时为空数组。\n- `groups` 按 `sort_order`、ID 升序，**只列出至少有一个在售版本的游戏**；`versions` 按 ID 倒序。\n- 开服（`POST /instances`）需要：版本 ID（`versions[].id`，即 `image_id`）、节点 ID，以及该节点下的套餐 ID（`plans[].id`）。套餐必须满足游戏的 `min_cpu_cores` / `min_memory_mb` / `min_disk_mb`。\n- `hourly_price_cents` 为 0 表示该套餐不支持按小时计费。\n- `versions[].variables` 只含面板可见的变量；`password` 类型变量的 `default_value` 在商店中被清空。\n- 节点 `status` 为实时状态，`offline` 的节点可能无法开服。\n- 商品配置随时可能调整，已购实例保存的是购买时的价格与资源快照，不受影响。",
        "tags": [
          "store"
        ],
        "x-scope": "read",
        "x-cli": "ocent store list --game Minecraft",
        "responses": {
          "200": {
            "description": "商店目录。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StoreCatalog"
                },
                "example": {
                  "nodes": [
                    {
                      "id": 1,
                      "name": "华东一区",
                      "status": "online",
                      "public_host": "node1.example.com",
                      "plans": [
                        {
                          "id": 3,
                          "node_id": 1,
                          "name": "标准 4G",
                          "cpu_cores": 2,
                          "memory_mb": 4096,
                          "disk_mb": 20480,
                          "monthly_price_cents": 3000,
                          "hourly_price_cents": 6,
                          "sort_order": 0,
                          "enabled": true
                        }
                      ]
                    }
                  ],
                  "groups": [
                    {
                      "id": 2,
                      "name": "Minecraft",
                      "description": "Java 版服务端",
                      "min_cpu_cores": 1,
                      "min_memory_mb": 2048,
                      "min_disk_mb": 5120,
                      "sort_order": 0,
                      "enabled": true,
                      "cover_url": "/api/v1/media/cover-2-0123456789abcdef.webp",
                      "banner_url": "",
                      "versions": [
                        {
                          "id": 10,
                          "group_id": 2,
                          "name": "Paper",
                          "version": "1.21",
                          "description": "高性能插件服务端",
                          "docker_image": "ghcr.io/example/java:21",
                          "docker_images": [
                            {
                              "name": "Java 21",
                              "image": "ghcr.io/example/java:21"
                            }
                          ],
                          "ports": [
                            {
                              "container_port": 25565,
                              "protocol": "tcp",
                              "primary": true,
                              "mirror": false
                            }
                          ],
                          "mount_path": "/home/container",
                          "enabled": true,
                          "startup_command_locked": false,
                          "variables": [
                            {
                              "key": "SERVER_JARFILE",
                              "name": "服务端文件",
                              "description": "启动的 jar 文件名",
                              "default_value": "server.jar",
                              "input_type": "text",
                              "options": [],
                              "rule": "[A-Za-z0-9._-]+\\.jar",
                              "user_editable": true,
                              "required_on_create": false
                            }
                          ],
                          "has_install": true,
                          "curseforge_modpacks": false,
                          "workshop_app_id": 0,
                          "workshop_dir": ""
                        }
                      ],
                      "modpacks": [
                        {
                          "id": 5,
                          "group_id": 2,
                          "game_image_id": 10,
                          "name": "示例整合包",
                          "version": "1.0.0",
                          "description": "预装常用插件",
                          "docker_image": "ghcr.io/example/java:21",
                          "startup_command": "java -Xms128M -jar {{SERVER_JARFILE}}",
                          "run_install_script": false,
                          "file_size": 52428800,
                          "sort_order": 0,
                          "icon_url": ""
                        }
                      ]
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/vps/store": {
      "get": {
        "operationId": "getVpsStore",
        "summary": "云服务器商店",
        "description": "列出可购买云服务器的地域、套餐、系统镜像、付费周期与直接支付渠道。\n\n- 平台未开放云服务器时仍返回 200：`enabled` 为 `false`，`regions` 与 `payment_channels` 为空数组，`periods` 照常返回。\n- `regions` 只列出同时有在售套餐与在售镜像的（站点, 地域）组合，按该组合第一个套餐的排序值排列；不同站点的地域 ID 可能重复，请用 `provider` + `region` 联合识别。\n- `regions[].realname_required` 针对**当前用户**：该站点要求实名且你尚未通过实名认证时为 `true`，此时购买会被拒绝（403）。顶层 `realname_required` 为任一已配置站点满足该条件时为 `true`（兼容旧客户端）。`realname_enabled` 表示平台当前是否提供实名认证。\n- `periods` 为 1 / 3 / 12 个月的付费周期与折扣百分比；`grace_days` 为到期后停机保留的天数，过后释放。\n- `payment_channels` 是除余额外可直接支付的渠道。开放 API 不支持直接支付，购买与续费只能从余额扣费。\n- 实际价格以购买接口计算为准，建议购买时带 `expected_price_cents` 做价格确认。",
        "tags": [
          "store"
        ],
        "x-scope": "read",
        "x-cli": "ocent vps store",
        "responses": {
          "200": {
            "description": "云服务器商店目录。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/StoreVPSCatalog"
                },
                "example": {
                  "enabled": true,
                  "grace_days": 7,
                  "regions": [
                    {
                      "provider": "ucloud",
                      "region": "cn-sh2",
                      "region_name": "上海二",
                      "realname_required": false,
                      "plans": [
                        {
                          "id": 4,
                          "provider": "ucloud",
                          "region": "cn-sh2",
                          "region_name": "上海二",
                          "name": "2 核 4G",
                          "description": "通用型",
                          "cpu_cores": 2,
                          "memory_mb": 4096,
                          "disk_gb": 40,
                          "bandwidth_mbps": 5,
                          "traffic_gb": 0,
                          "monthly_price_cents": 6900
                        }
                      ],
                      "images": [
                        {
                          "id": 9,
                          "provider": "ucloud",
                          "region": "cn-sh2",
                          "name": "Ubuntu 22.04",
                          "os_type": "Linux",
                          "os_name": "Ubuntu 22.04 64位"
                        }
                      ]
                    }
                  ],
                  "realname_required": false,
                  "realname_enabled": true,
                  "payment_channels": [
                    {
                      "channel": "alipay",
                      "name": "支付宝"
                    },
                    {
                      "channel": "wechat",
                      "name": "微信支付"
                    }
                  ],
                  "periods": [
                    {
                      "months": 1,
                      "label": "按月",
                      "discount_percent": 100
                    },
                    {
                      "months": 3,
                      "label": "按季度",
                      "discount_percent": 95
                    },
                    {
                      "months": 12,
                      "label": "按年",
                      "discount_percent": 85
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/coupons/preview": {
      "post": {
        "operationId": "previewCoupon",
        "summary": "试算优惠码",
        "description": "按指定的版本、节点与套餐试算新开游戏服务器时优惠码的折扣，**不占用名额、不扣费**。\n\n- 只用于预估：真正开服（`POST /instances` 带 `coupon_code`）时会在事务内重新校验全部条件，试算通过不保证开服时仍可用。\n- 折扣按套餐**月价**计算：百分比折扣向下取整到分，固定金额折扣不超过原价。\n- `renewal_price_cents` 是之后每次续费的价格：循环券（`recurring: true`）为折后价，新购券为原价。\n- `billing_mode` 为 `hourly` 时直接返回 `400 coupon_not_supported`（按小时计费不支持优惠券）；省略或其他值都按月付试算。\n- 校验顺序固定：优惠码存在 → 启用 → 已生效 → 未过期 → 总名额 → 个人使用次数 → 适用游戏与套餐 → 原价大于 0 → 最低消费。\n- 本接口不检查节点是否在线、套餐是否满足游戏最低配置，这些在开服时检查。\n- 需要 `billing` 权限。",
        "tags": [
          "store"
        ],
        "x-scope": "billing",
        "x-rate-limit": "30 次/分钟/IP（与带 coupon_code 的开服请求共用额度）",
        "x-cli": "ocent api POST /coupons/preview --data '{\"code\":\"SAVE5\",\"node_id\":1,\"image_id\":10,\"plan_id\":3}' --yes",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CouponPreviewRequest"
              },
              "example": {
                "code": "SAVE5",
                "node_id": 1,
                "image_id": 10,
                "plan_id": 3,
                "billing_mode": "monthly"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "试算结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CouponPreviewResponse"
                },
                "example": {
                  "code": "SAVE5",
                  "name": "新用户立减 5 元",
                  "discount_type": "fixed",
                  "percent_off": 0,
                  "amount_off_cents": 500,
                  "recurring": false,
                  "original_cents": 3000,
                  "discount_cents": 500,
                  "paid_cents": 2500,
                  "renewal_price_cents": 3000
                }
              }
            }
          },
          "400": {
            "description": "请求无效或按小时计费。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "按小时计费不支持优惠券",
                  "code": "coupon_not_supported"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "优惠码不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "优惠码不存在",
                  "code": "coupon_not_found"
                }
              }
            }
          },
          "409": {
            "description": "商品不可用或优惠码当前不可用于该订单。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "未达到优惠码最低消费 ¥50.00",
                  "code": "coupon_min_amount"
                }
              }
            }
          },
          "413": {
            "$ref": "#/components/responses/PayloadTooLarge"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_input",
            "description": "请求体无法解析，或缺少 code / node_id / image_id / plan_id（ID 须为正整数），或优惠码去掉空白后为空"
          },
          {
            "status": 400,
            "code": "coupon_not_supported",
            "description": "billing_mode 为 hourly，按小时计费不支持优惠券"
          },
          {
            "status": 404,
            "code": "coupon_not_found",
            "description": "优惠码不存在（含超过 32 个字符的优惠码）"
          },
          {
            "status": 409,
            "code": "game_unavailable",
            "description": "游戏版本不存在、未上架，或所属游戏未上架"
          },
          {
            "status": 409,
            "code": "plan_unavailable",
            "description": "套餐不存在、未上架或不属于所选节点"
          },
          {
            "status": 409,
            "code": "coupon_disabled",
            "description": "优惠码已停用"
          },
          {
            "status": 409,
            "code": "coupon_not_started",
            "description": "优惠码尚未生效"
          },
          {
            "status": 409,
            "code": "coupon_expired",
            "description": "优惠码已过期"
          },
          {
            "status": 409,
            "code": "coupon_exhausted",
            "description": "优惠码总名额已用完"
          },
          {
            "status": 409,
            "code": "coupon_user_limit",
            "description": "已达到该优惠码的个人使用次数上限"
          },
          {
            "status": 409,
            "code": "coupon_not_applicable",
            "description": "优惠码不适用于所选游戏或套餐，或套餐原价为 0"
          },
          {
            "status": 409,
            "code": "coupon_min_amount",
            "description": "套餐月价未达到优惠码最低消费，消息中带门槛金额"
          }
        ]
      }
    },
    "/wallet": {
      "get": {
        "operationId": "getWallet",
        "summary": "钱包概况",
        "description": "返回当前余额、累计入账、累计支出与 OC币积分。\n\n- 金额均为整数分；`income_cents` 为全部正数流水之和，`spent_cents` 为全部负数流水绝对值之和（包含退款等入账，不等于净充值）。\n- `oc_coins` 是整数积分，不是金额。\n- 充值只能在网页面板完成，开放 API 不提供充值接口。",
        "tags": [
          "wallet"
        ],
        "x-scope": "read",
        "x-cli": "ocent wallet show",
        "responses": {
          "200": {
            "description": "钱包概况。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WalletSummary"
                },
                "example": {
                  "balance_cents": 12345,
                  "income_cents": 50000,
                  "spent_cents": 37655,
                  "oc_coins": 120
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/wallet/transactions": {
      "get": {
        "operationId": "listWalletTransactions",
        "summary": "钱包流水",
        "description": "分页列出当前用户的钱包流水，按 ID 倒序（最新在前）。\n\n- `amount_cents` 有符号：正数为入账，负数为扣款；`balance_after_cents` 为该笔变动后的余额。\n- `type` 会随功能增加，不要假设是固定集合。\n- `limit` 取 1–100，默认 20；`offset` 取 0–1000000，默认 0。参数不是整数或小于下限时按默认值处理，超过上限时按上限处理，不会返回 400；以响应中的 `limit` / `offset` 为准。\n- 扣费请求超时或断线后，可先查询本接口确认是否已扣费，再决定是否重试。",
        "tags": [
          "wallet"
        ],
        "x-scope": "read",
        "x-cli": "ocent wallet transactions --limit 20 --page 1",
        "parameters": [
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Offset"
          }
        ],
        "responses": {
          "200": {
            "description": "钱包流水分页。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WalletTransactionPage"
                },
                "example": {
                  "items": [
                    {
                      "id": 88,
                      "user_id": 1001,
                      "type": "instance_renewal",
                      "amount_cents": -3000,
                      "balance_after_cents": 12345,
                      "description": "实例 my-server 续费 1 个月",
                      "reference_type": "order",
                      "reference_id": 341,
                      "created_at": "2026-11-20T08:00:00Z"
                    }
                  ],
                  "total": 42,
                  "limit": 20,
                  "offset": 0
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/wallet/oc-coins/transactions": {
      "get": {
        "operationId": "listOcCoinTransactions",
        "summary": "OC币流水",
        "description": "分页列出当前用户的 OC币积分流水，按 ID 倒序（最新在前）。\n\n- 结构与钱包流水相同，但字段名为 `amount` 与 `balance_after`，单位是整数积分而不是金额。\n- `type` 会随功能增加，不要假设是固定集合。\n- `limit` 取 1–100，默认 20；`offset` 取 0–1000000，默认 0。非法值按默认值、超过上限按上限处理，不会返回 400。",
        "tags": [
          "wallet"
        ],
        "x-scope": "read",
        "x-cli": "ocent wallet transactions --oc-coins --limit 20",
        "parameters": [
          {
            "$ref": "#/components/parameters/Limit"
          },
          {
            "$ref": "#/components/parameters/Offset"
          }
        ],
        "responses": {
          "200": {
            "description": "OC币流水分页。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OCCoinTransactionPage"
                },
                "example": {
                  "items": [
                    {
                      "id": 15,
                      "user_id": 1001,
                      "type": "recharge_bonus",
                      "amount": 50,
                      "balance_after": 120,
                      "description": "充值 ¥50.00 赠送 OC币",
                      "reference_type": "order",
                      "reference_id": 330,
                      "created_at": "2026-11-18T03:20:00Z"
                    }
                  ],
                  "total": 3,
                  "limit": 20,
                  "offset": 0
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/instances": {
      "get": {
        "operationId": "listInstances",
        "summary": "列出游戏服务器实例",
        "description": "返回当前账户的全部游戏服务器实例，按 ID 倒序，不分页。\n\n- 只有 `starting` 与 `installing` 状态的实例会顺便向节点刷新状态；其他实例返回数据库中的最近状态，需要最新状态时用 `GET /instances/{id}`。\n- 没有 `write` 权限的密钥看到的密码类变量（`input_type=password`）`value` 为空串，并带 `value_redacted: true`。",
        "tags": [
          "instances"
        ],
        "x-scope": "read",
        "x-cli": "ocent instance list",
        "responses": {
          "200": {
            "description": "实例列表。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceList"
                },
                "example": {
                  "items": [
                    {
                      "id": 42,
                      "name": "my-server",
                      "status": "running",
                      "status_detail": "",
                      "last_error": "",
                      "node": {
                        "id": 1,
                        "name": "华东一区",
                        "status": "online",
                        "public_host": "node1.example.com"
                      },
                      "connect_host": "node1.example.com",
                      "image": {
                        "id": 10,
                        "group_id": 2,
                        "name": "Paper",
                        "version": "1.21",
                        "description": "",
                        "docker_image": "example/minecraft:java21",
                        "docker_images": [
                          {
                            "name": "Java 21",
                            "image": "example/minecraft:java21"
                          }
                        ],
                        "ports": [
                          {
                            "container_port": 25565,
                            "protocol": "tcp",
                            "primary": true,
                            "mirror": false
                          }
                        ],
                        "mount_path": "/data",
                        "enabled": true,
                        "startup_command_locked": false,
                        "variables": [],
                        "has_install": true,
                        "curseforge_modpacks": false,
                        "workshop_app_id": 0,
                        "workshop_dir": ""
                      },
                      "game": {
                        "id": 2,
                        "name": "Minecraft",
                        "cover_url": "",
                        "banner_url": ""
                      },
                      "plan_id": 3,
                      "plan_name": "标准 4G",
                      "cpu_cores": 2,
                      "memory_mb": 4096,
                      "disk_mb": 20480,
                      "monthly_price_cents": 3000,
                      "renewal_price_cents": 3000,
                      "recurring_coupon_code": "",
                      "billing_mode": "monthly",
                      "hourly_price_cents": 0,
                      "hourly_storage_price_cents": 0,
                      "hourly_storage_percent": 10,
                      "hourly_storage_paid": false,
                      "expires_at": "2026-12-24T08:00:00Z",
                      "auto_renew": true,
                      "delete_at": null,
                      "startup_command": "java -Xmx{{SERVER_MEMORY}}M -jar server.jar nogui",
                      "docker_image": "example/minecraft:java21",
                      "mount_path": "/data",
                      "ports": [
                        {
                          "container_port": 25565,
                          "host_port": 30001,
                          "protocol": "tcp"
                        }
                      ],
                      "primary_port": {
                        "container_port": 25565,
                        "host_port": 30001,
                        "protocol": "tcp"
                      },
                      "variables": [
                        {
                          "key": "MAX_PLAYERS",
                          "name": "最大人数",
                          "description": "",
                          "default_value": "20",
                          "input_type": "text",
                          "options": [],
                          "rule": "^[0-9]{1,3}$",
                          "user_editable": true,
                          "required_on_create": false,
                          "value": "20"
                        }
                      ],
                      "install_status": "installed",
                      "install_error": "",
                      "installed_at": "2026-11-24T08:05:00Z",
                      "has_install": true,
                      "modpack_id": null,
                      "modpack_name": "",
                      "modpack_version": "",
                      "modpack_icon_url": "",
                      "curseforge_project_id": 0,
                      "curseforge_file_id": 0,
                      "curseforge_slug": "",
                      "created_at": "2026-11-24T08:00:00Z",
                      "updated_at": "2026-11-24T08:06:00Z"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createInstance",
        "summary": "开通游戏服务器",
        "description": "从余额扣第一期费用并在节点上创建实例：按月开通 1 个月（扣套餐月价，可用优惠码），按小时预付第 1 小时（扣套餐小时价）。\n\n- 成功返回 `201`。有安装步骤时 `status` 为 `installing`，用 `GET /instances/{id}` 轮询直到 `stopped`（成功）或 `install_failed`；没有安装步骤时为节点报告的状态。**创建后不会自动开机。**\n- 这是同步请求，节点拉取镜像等可能需要数十秒到数分钟，客户端超时请设长一些（建议 ≥ 25 分钟）。客户端断开后服务端仍会继续执行。\n- **没有幂等键**：超时或断线后不要直接重试，先用 `GET /instances` 和钱包流水确认是否已开通。\n- 节点创建失败时自动退款并删除实例：`502 provision_failed`，响应带 `instance_id`。\n- 每次开通都会生成 SFTP 账号 `dc-<实例ID>` 与随机密码，用 `GET /instances/{id}/sftp` 读取。\n- 请求体带非空 `coupon_code` 时，与 `POST /coupons/preview` 共用 30 次/分钟/IP 的限额。",
        "tags": [
          "instances"
        ],
        "x-scope": "billing",
        "x-danger": "billing",
        "x-long-running": true,
        "x-rate-limit": "带非空 coupon_code 时与优惠码试算共用 30 次/分钟/IP",
        "x-cli": "ocent instance create --name my-server --image 10 --plan 3 --var MAX_PLAYERS=20 --yes",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InstanceCreateRequest"
              },
              "example": {
                "name": "my-server",
                "image_id": 10,
                "node_id": 1,
                "plan_id": 3,
                "billing_mode": "monthly",
                "auto_renew": true,
                "docker_image": "",
                "startup_command": "",
                "variables": {
                  "MAX_PLAYERS": "20"
                },
                "modpack_id": null,
                "coupon_code": ""
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "已开通。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceResponse"
                },
                "example": {
                  "instance": {
                    "id": 42,
                    "name": "my-server",
                    "status": "installing",
                    "status_detail": "正在执行安装脚本",
                    "last_error": "",
                    "node": {
                      "id": 1,
                      "name": "华东一区",
                      "status": "online",
                      "public_host": "node1.example.com"
                    },
                    "connect_host": "node1.example.com",
                    "image": {
                      "id": 10,
                      "group_id": 2,
                      "name": "Paper",
                      "version": "1.21",
                      "description": "",
                      "docker_image": "example/minecraft:java21",
                      "docker_images": [
                        {
                          "name": "Java 21",
                          "image": "example/minecraft:java21"
                        }
                      ],
                      "ports": [
                        {
                          "container_port": 25565,
                          "protocol": "tcp",
                          "primary": true,
                          "mirror": false
                        }
                      ],
                      "mount_path": "/data",
                      "enabled": true,
                      "startup_command_locked": false,
                      "variables": [],
                      "has_install": true,
                      "curseforge_modpacks": false,
                      "workshop_app_id": 0,
                      "workshop_dir": ""
                    },
                    "game": {
                      "id": 2,
                      "name": "Minecraft",
                      "cover_url": "",
                      "banner_url": ""
                    },
                    "plan_id": 3,
                    "plan_name": "标准 4G",
                    "cpu_cores": 2,
                    "memory_mb": 4096,
                    "disk_mb": 20480,
                    "monthly_price_cents": 3000,
                    "renewal_price_cents": 3000,
                    "recurring_coupon_code": "",
                    "billing_mode": "monthly",
                    "hourly_price_cents": 0,
                    "hourly_storage_price_cents": 0,
                    "hourly_storage_percent": 10,
                    "hourly_storage_paid": false,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": true,
                    "delete_at": null,
                    "startup_command": "java -Xmx{{SERVER_MEMORY}}M -jar server.jar nogui",
                    "docker_image": "example/minecraft:java21",
                    "mount_path": "/data",
                    "ports": [
                      {
                        "container_port": 25565,
                        "host_port": 30001,
                        "protocol": "tcp"
                      }
                    ],
                    "primary_port": {
                      "container_port": 25565,
                      "host_port": 30001,
                      "protocol": "tcp"
                    },
                    "variables": [
                      {
                        "key": "MAX_PLAYERS",
                        "name": "最大人数",
                        "description": "",
                        "default_value": "20",
                        "input_type": "text",
                        "options": [],
                        "rule": "^[0-9]{1,3}$",
                        "user_editable": true,
                        "required_on_create": false,
                        "value": "20"
                      }
                    ],
                    "install_status": "installing",
                    "install_error": "",
                    "installed_at": null,
                    "has_install": true,
                    "modpack_id": null,
                    "modpack_name": "",
                    "modpack_version": "",
                    "modpack_icon_url": "",
                    "curseforge_project_id": 0,
                    "curseforge_file_id": 0,
                    "curseforge_slug": "",
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:06:00Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientBalance"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点创建失败，已自动退款（`provision_failed`，带 `instance_id`），或 CurseForge 服务不可用。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例创建失败，已退回余额；请检查节点状态后重试",
                  "code": "provision_failed",
                  "instance_id": 42
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_input",
            "description": "请求体无法解析，或缺少 name/image_id/node_id/plan_id，或 curseforge 与 modpack_id 同时出现、ID 为 0"
          },
          {
            "status": 400,
            "code": "invalid_name",
            "description": "名称去空白后不是 2–60 个字符"
          },
          {
            "status": 400,
            "code": "invalid_command",
            "description": "启动参数超过 4096 字节、含 NUL 或引用了未定义的变量"
          },
          {
            "status": 400,
            "code": "invalid_billing_mode",
            "description": "billing_mode 不是 monthly 或 hourly"
          },
          {
            "status": 400,
            "code": "coupon_not_supported",
            "description": "按小时计费不支持优惠码"
          },
          {
            "status": 400,
            "code": "plan_too_small",
            "description": "套餐低于游戏最低配置"
          },
          {
            "status": 400,
            "code": "invalid_variable",
            "description": "变量不存在、不可修改、必填为空或格式不符（带 field）"
          },
          {
            "status": 400,
            "code": "invalid_docker_image",
            "description": "运行镜像不属于该版本"
          },
          {
            "status": 400,
            "code": "invalid_modpack",
            "description": "整合包与版本不匹配，或该版本只能通过 CurseForge 整合包开服"
          },
          {
            "status": 402,
            "code": "insufficient_balance",
            "description": "余额不足以支付首期费用"
          },
          {
            "status": 403,
            "code": "startup_command_locked",
            "description": "该版本不允许修改启动参数"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "节点或游戏版本不存在"
          },
          {
            "status": 409,
            "code": "node_unavailable",
            "description": "节点未启用或不在线"
          },
          {
            "status": 409,
            "code": "game_unavailable",
            "description": "游戏或版本未上架"
          },
          {
            "status": 409,
            "code": "plan_unavailable",
            "description": "套餐不属于该节点或未在售"
          },
          {
            "status": 409,
            "code": "hourly_unavailable",
            "description": "套餐不支持按小时计费"
          },
          {
            "status": 409,
            "code": "no_capacity",
            "description": "节点可用端口不足或版本端口数超限"
          },
          {
            "status": 409,
            "code": "modpack_unavailable",
            "description": "整合包不存在、已停用或未上传"
          },
          {
            "status": 409,
            "code": "modpack_syncing",
            "description": "整合包仍在同步到存储机"
          },
          {
            "status": 409,
            "code": "image_not_internal",
            "description": "运行镜像或安装镜像不来自平台镜像仓库"
          },
          {
            "status": 404,
            "code": "coupon_not_found",
            "description": "优惠码不存在"
          },
          {
            "status": 409,
            "code": "coupon_disabled",
            "description": "优惠码已停用"
          },
          {
            "status": 409,
            "code": "coupon_not_started",
            "description": "优惠码尚未生效"
          },
          {
            "status": 409,
            "code": "coupon_expired",
            "description": "优惠码已过期"
          },
          {
            "status": 409,
            "code": "coupon_exhausted",
            "description": "优惠码已被领完"
          },
          {
            "status": 409,
            "code": "coupon_user_limit",
            "description": "已达到该优惠码的使用次数上限"
          },
          {
            "status": 409,
            "code": "coupon_not_applicable",
            "description": "优惠码不适用于所选游戏或套餐"
          },
          {
            "status": 409,
            "code": "coupon_min_amount",
            "description": "未达到优惠码最低消费"
          },
          {
            "status": 400,
            "code": "curseforge_unsupported_loader",
            "description": "整合包加载器不受支持（只支持 Forge、NeoForge、Fabric）"
          },
          {
            "status": 400,
            "code": "curseforge_game_mismatch",
            "description": "整合包不属于该游戏"
          },
          {
            "status": 404,
            "code": "curseforge_not_found",
            "description": "未找到该 CurseForge 整合包或文件"
          },
          {
            "status": 409,
            "code": "curseforge_blocked",
            "description": "整合包已被管理员屏蔽"
          },
          {
            "status": 409,
            "code": "curseforge_not_distributable",
            "description": "作者未开放该文件的第三方下载"
          },
          {
            "status": 409,
            "code": "curseforge_no_java",
            "description": "暂不支持该整合包的我的世界版本"
          },
          {
            "status": 409,
            "code": "curseforge_no_install_image",
            "description": "该版本未配置安装镜像"
          },
          {
            "status": 502,
            "code": "curseforge_unavailable",
            "description": "CurseForge 服务暂时不可用"
          },
          {
            "status": 503,
            "code": "curseforge_disabled",
            "description": "CurseForge 整合包开服未开放"
          },
          {
            "status": 502,
            "code": "provision_failed",
            "description": "节点创建失败，已退回余额（带 instance_id）"
          }
        ]
      }
    },
    "/instances/{id}": {
      "get": {
        "operationId": "getInstance",
        "summary": "查询实例详情",
        "description": "返回单个实例，并按节流间隔向节点刷新状态：`starting` 每 3 秒、`installing` 每 5 秒、其他每 15 秒最多刷新一次；`provisioning`、`expired` 或节点不在线时不刷新。适合轮询等待开机或安装完成（建议 2–5 秒一次）。\n\n- 套餐、价格与资源是购买或改套餐时的快照，之后商品调整不影响已有实例。\n- `disk_mb` 不是文件系统硬配额，游戏写盘、SFTP 上传仍可能写满节点磁盘。\n- 没有 `write` 权限的密钥看到的密码类变量 `value` 为空串，并带 `value_redacted: true`。\n- 实例不存在或不属于当前账户时返回 `404 not_found`。",
        "tags": [
          "instances"
        ],
        "x-scope": "read",
        "x-cli": "ocent instance get 42",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "responses": {
          "200": {
            "description": "实例详情。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceResponse"
                },
                "example": {
                  "instance": {
                    "id": 42,
                    "name": "my-server",
                    "status": "running",
                    "status_detail": "",
                    "last_error": "",
                    "node": {
                      "id": 1,
                      "name": "华东一区",
                      "status": "online",
                      "public_host": "node1.example.com"
                    },
                    "connect_host": "node1.example.com",
                    "image": {
                      "id": 10,
                      "group_id": 2,
                      "name": "Paper",
                      "version": "1.21",
                      "description": "",
                      "docker_image": "example/minecraft:java21",
                      "docker_images": [
                        {
                          "name": "Java 21",
                          "image": "example/minecraft:java21"
                        }
                      ],
                      "ports": [
                        {
                          "container_port": 25565,
                          "protocol": "tcp",
                          "primary": true,
                          "mirror": false
                        }
                      ],
                      "mount_path": "/data",
                      "enabled": true,
                      "startup_command_locked": false,
                      "variables": [],
                      "has_install": true,
                      "curseforge_modpacks": false,
                      "workshop_app_id": 0,
                      "workshop_dir": ""
                    },
                    "game": {
                      "id": 2,
                      "name": "Minecraft",
                      "cover_url": "",
                      "banner_url": ""
                    },
                    "plan_id": 3,
                    "plan_name": "标准 4G",
                    "cpu_cores": 2,
                    "memory_mb": 4096,
                    "disk_mb": 20480,
                    "monthly_price_cents": 3000,
                    "renewal_price_cents": 3000,
                    "recurring_coupon_code": "",
                    "billing_mode": "monthly",
                    "hourly_price_cents": 0,
                    "hourly_storage_price_cents": 0,
                    "hourly_storage_percent": 10,
                    "hourly_storage_paid": false,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": true,
                    "delete_at": null,
                    "startup_command": "java -Xmx{{SERVER_MEMORY}}M -jar server.jar nogui",
                    "docker_image": "example/minecraft:java21",
                    "mount_path": "/data",
                    "ports": [
                      {
                        "container_port": 25565,
                        "host_port": 30001,
                        "protocol": "tcp"
                      }
                    ],
                    "primary_port": {
                      "container_port": 25565,
                      "host_port": 30001,
                      "protocol": "tcp"
                    },
                    "variables": [
                      {
                        "key": "MAX_PLAYERS",
                        "name": "最大人数",
                        "description": "",
                        "default_value": "20",
                        "input_type": "text",
                        "options": [],
                        "rule": "^[0-9]{1,3}$",
                        "user_editable": true,
                        "required_on_create": false,
                        "value": "20"
                      }
                    ],
                    "install_status": "installed",
                    "install_error": "",
                    "installed_at": "2026-11-24T08:05:00Z",
                    "has_install": true,
                    "modpack_id": null,
                    "modpack_name": "",
                    "modpack_version": "",
                    "modpack_icon_url": "",
                    "curseforge_project_id": 0,
                    "curseforge_file_id": 0,
                    "curseforge_slug": "",
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:06:00Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "delete": {
        "operationId": "deleteInstance",
        "summary": "删除实例",
        "description": "**永久删除实例及节点上的全部数据，不可恢复。** 先在节点上删除容器与数据（节点上已不存在视为成功），再释放端口、删除记录并在同一事务内退款。\n\n- 按月实例退回剩余整天数价值（当天不退）与已付净额中的较小者的 80%；按小时实例不退款。删除前可用 `GET /instances/{id}/delete-refund` 试算。\n- 节点暂时无法删除时返回 `502 agent_unavailable`，此时未删除、未退款，可稍后重试。\n- 最长约 2 分钟。",
        "tags": [
          "instances"
        ],
        "x-scope": "billing",
        "x-danger": "destructive",
        "x-long-running": true,
        "x-cli": "ocent instance delete 42 --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "responses": {
          "200": {
            "description": "已删除。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceDeleteResult"
                },
                "example": {
                  "message": "实例及数据已删除，已退回剩余天数费用 ¥23.20",
                  "refund_cents": 2320
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点暂时无法完成删除，实例未删除、未退款。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "节点暂时无法完成删除，请稍后重试",
                  "code": "agent_unavailable"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 502,
            "code": "agent_unavailable",
            "description": "节点暂时无法完成删除，未删除、未退款"
          }
        ]
      }
    },
    "/instances/{id}/install": {
      "get": {
        "operationId": "getInstanceInstall",
        "summary": "查询安装状态与日志",
        "description": "从节点读取最近一次安装（开服、重新安装、切换游戏）的状态、退出码与日志末尾（约 64 KiB）。\n\n- 实例没有安装步骤且从未安装过时直接返回空结果（`status` 与 `log` 为空串），不访问节点。\n- 节点离线或读取失败时返回 `503 node_unavailable`；节点上没有该实例的安装记录时返回 `404 not_found`。",
        "tags": [
          "instances"
        ],
        "x-scope": "read",
        "x-cli": "ocent instance install 42",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "responses": {
          "200": {
            "description": "安装信息。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceInstallInfo"
                },
                "example": {
                  "status": "installed",
                  "error": "",
                  "exit_code": 0,
                  "started_at": "2026-11-24T08:00:10Z",
                  "finished_at": "2026-11-24T08:04:55Z",
                  "log": "[install] Downloading server.jar...\n[install] Done.\n"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "description": "节点离线或暂时无法读取安装日志。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "节点离线，暂时无法读取安装日志",
                  "code": "node_unavailable"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或节点上没有该实例的安装记录"
          },
          {
            "status": 503,
            "code": "node_unavailable",
            "description": "节点离线或读取安装日志失败"
          }
        ]
      }
    },
    "/instances/{id}/actions": {
      "post": {
        "operationId": "instancePowerAction",
        "summary": "开机、停止、重启或强制停止",
        "description": "同步等待节点完成电源操作，最长约 5 分钟（`stop` 会等待游戏正常存档退出）。\n\n- `start` / `restart` 会按当前变量重新渲染启动命令与配置文件；设置有变化时节点会先重建容器（数据保留）。\n- `kill` 相当于 SIGKILL，未保存的数据可能丢失；旧版节点不支持时返回 `502 agent_unsupported`。\n- 安装失败（`install_failed`）的实例不能 `start` / `restart`，需先重新安装；`stop` / `kill` 仍可执行。\n- **按小时实例**：在已按存储价支付的小时内开机，会补扣「运行价 − 存储价」差额；余额不足返回 `402 insufficient_balance` 且不开机。\n- **API 密钥额外要求**：让按小时实例从非运行状态（不是 `starting`/`running`/`installing`/`provisioning`）`start` 或 `restart` 会按运行价持续扣费，密钥除 `write` 外还需要 `billing`，否则 `403 insufficient_scope`（`required_scope: \"billing\"`）。",
        "tags": [
          "power"
        ],
        "x-scope": "write",
        "x-scope-note": "按小时计费实例从非运行状态 start/restart 另需 billing",
        "x-long-running": true,
        "x-cli": "ocent instance restart 42",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InstanceActionRequest"
              },
              "example": {
                "action": "restart"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "操作完成。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceActionResult"
                },
                "example": {
                  "status": "running",
                  "message": "操作成功",
                  "warnings": []
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientBalance"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_action",
            "description": "缺少 action 或不是 start/stop/restart/kill"
          },
          {
            "status": 402,
            "code": "insufficient_balance",
            "description": "按小时实例余额不足以支付开机后的运行费用"
          },
          {
            "status": 403,
            "code": "insufficient_scope",
            "description": "按小时实例开机，密钥缺少 billing"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期（或已过到期时间），请先续费"
          },
          {
            "status": 409,
            "code": "instance_provisioning",
            "description": "实例正在创建中"
          },
          {
            "status": 409,
            "code": "instance_installing",
            "description": "实例正在安装"
          },
          {
            "status": 409,
            "code": "install_failed",
            "description": "安装失败，请先重新安装（只拦 start/restart）"
          },
          {
            "status": 502,
            "code": "agent_unsupported",
            "description": "节点 Agent 版本过低，不支持 kill"
          },
          {
            "status": 502,
            "code": "agent_action_failed",
            "description": "节点操作失败"
          },
          {
            "status": 503,
            "code": "node_offline",
            "description": "节点离线"
          }
        ]
      }
    },
    "/instances/{id}/console/logs": {
      "get": {
        "operationId": "getInstanceConsoleLogs",
        "summary": "读取控制台输出",
        "description": "读取最近的控制台输出（网页控制台的 WebSocket 不接受 API 密钥，脚本请用本接口）。\n\n- 主控连接节点的控制台流：先收到状态，再收到历史回放；收到第一个事件后若 800 ms 内没有新输出即认为回放结束，整个请求最长约 5 秒。游戏输出频繁时会读满 5 秒，返回内容可能多于 `tail` 行。\n- `output` 是原文，**包含 ANSI 颜色控制码**，需要纯文本时请自行去除（`ocent instance logs` 默认已去除）。\n- `output` 最多 256 KiB，超出时只保留末尾并设置 `truncated: true`。\n- 已到期的实例也可以读取。\n- 同时进行的请求每实例最多 2 个、每用户最多 4 个，超出返回 `429 console_logs_busy`；请不要并发调用。",
        "tags": [
          "power"
        ],
        "x-scope": "read",
        "x-rate-limit": "60 次/分钟/用户；并发每实例 2 个、每用户 4 个",
        "x-cli": "ocent instance logs 42 --tail 200",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          },
          {
            "name": "tail",
            "in": "query",
            "required": false,
            "description": "节点回放的历史行数，1–1000，默认 200",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000,
              "default": 200
            },
            "example": 200
          }
        ],
        "responses": {
          "200": {
            "description": "控制台输出。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceConsoleLogs"
                },
                "example": {
                  "output": "[12:00:01 INFO]: Done (3.2s)! For help, type \"help\"\r\n",
                  "status": "running",
                  "truncated": false
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "节点离线。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "节点离线，暂时无法读取控制台",
                  "code": "node_offline"
                }
              }
            }
          },
          "429": {
            "description": "超过限流（`rate_limited`），或同时读取的请求过多（`console_logs_busy`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "同时读取控制台输出的请求过多，请等上一个请求完成后再试",
                  "code": "console_logs_busy"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_tail",
            "description": "tail 不是 1–1000 的整数"
          },
          {
            "status": 409,
            "code": "node_offline",
            "description": "节点离线"
          },
          {
            "status": 429,
            "code": "console_logs_busy",
            "description": "同时进行的读取请求过多，等上一个完成后再试"
          },
          {
            "status": 502,
            "code": "agent_unsupported",
            "description": "节点 Agent 版本过低"
          },
          {
            "status": 502,
            "code": "agent_error",
            "description": "节点上找不到该实例或读取失败"
          },
          {
            "status": 504,
            "code": "agent_timeout",
            "description": "5 秒内未收到任何事件"
          }
        ]
      }
    },
    "/instances/{id}/console/command": {
      "post": {
        "operationId": "sendInstanceConsoleCommand",
        "summary": "发送控制台命令",
        "description": "向游戏进程的标准输入写入一条命令。\n\n- 成功只表示已写入标准输入，**不返回命令输出**；需要结果时稍等片刻再调用 `GET /instances/{id}/console/logs`。\n- 实例处于 `installing`、`install_failed` 或 `starting` 时会先向节点刷新状态再判断。\n- 节点 10 秒内未响应返回 `504 agent_timeout`，命令可能未送达。\n- 游戏命令以服务器管理员身份执行（例如 Minecraft 的 `op`、`stop`），请只给可信的脚本 `write` 权限。",
        "tags": [
          "power"
        ],
        "x-scope": "write",
        "x-rate-limit": "60 次/分钟/用户",
        "x-cli": "ocent instance cmd 42 say 服务器将在 5 分钟后重启",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InstanceConsoleCommandRequest"
              },
              "example": {
                "command": "say 服务器将在 5 分钟后重启"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "命令已写入。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessageResponse"
                },
                "example": {
                  "message": "命令已发送"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_command",
            "description": "缺少 command、为空、超过 1024 字节、含控制字符（制表符除外）或非法 UTF-8"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期"
          },
          {
            "status": 409,
            "code": "instance_busy",
            "description": "实例正在创建、正在安装或安装失败"
          },
          {
            "status": 409,
            "code": "instance_installing",
            "description": "节点报告正在安装"
          },
          {
            "status": 409,
            "code": "node_offline",
            "description": "节点离线"
          },
          {
            "status": 409,
            "code": "not_running",
            "description": "服务器未运行"
          },
          {
            "status": 409,
            "code": "stdin_unavailable",
            "description": "容器创建时未开启控制台输入；保存一次启动参数重建容器后即可使用"
          },
          {
            "status": 502,
            "code": "agent_unsupported",
            "description": "节点 Agent 版本过低"
          },
          {
            "status": 502,
            "code": "agent_error",
            "description": "节点上找不到该实例或发送失败"
          },
          {
            "status": 504,
            "code": "agent_timeout",
            "description": "节点 10 秒内未响应，命令可能未送达"
          }
        ]
      }
    },
    "/instances/{id}/settings": {
      "patch": {
        "operationId": "updateInstanceSettings",
        "summary": "修改启动参数、运行镜像或自动续费",
        "description": "字段均可选，但至少提供一项（否则 `400 no_changes`）。\n\n- 修改 `startup_command` 或 `docker_image` 会让节点重建容器（数据保留，运行中的实例会重启），可能需要数分钟（切换镜像要拉取镜像）。安装失败的实例只保存，下次重新安装时生效。\n- 只改 `auto_renew` 不访问节点，已到期的实例也可以修改。\n- 按小时实例忽略 `auto_renew`（总是自动扣费）。\n- **API 密钥额外要求**：按月实例把 `auto_renew` 从关闭改为开启时，到期会自动从余额扣费，密钥除 `write` 外还需要 `billing`，否则 `403 insufficient_scope`（`required_scope: \"billing\"`）。关闭不需要。",
        "tags": [
          "config"
        ],
        "x-scope": "write",
        "x-scope-note": "把 auto_renew 从关闭改为开启（按月实例）另需 billing",
        "x-long-running": true,
        "x-cli": "ocent instance settings 42 --startup-command 'java -Xmx3G -jar server.jar nogui'",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InstanceSettingsRequest"
              },
              "example": {
                "startup_command": "java -Xmx3G -jar server.jar nogui"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "已更新。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceUpdateResult"
                },
                "example": {
                  "instance": {
                    "id": 42,
                    "name": "my-server",
                    "status": "running",
                    "status_detail": "运行设置已更新，容器已重建",
                    "last_error": "",
                    "node": {
                      "id": 1,
                      "name": "华东一区",
                      "status": "online",
                      "public_host": "node1.example.com"
                    },
                    "connect_host": "node1.example.com",
                    "image": {
                      "id": 10,
                      "group_id": 2,
                      "name": "Paper",
                      "version": "1.21",
                      "description": "",
                      "docker_image": "example/minecraft:java21",
                      "docker_images": [
                        {
                          "name": "Java 21",
                          "image": "example/minecraft:java21"
                        }
                      ],
                      "ports": [
                        {
                          "container_port": 25565,
                          "protocol": "tcp",
                          "primary": true,
                          "mirror": false
                        }
                      ],
                      "mount_path": "/data",
                      "enabled": true,
                      "startup_command_locked": false,
                      "variables": [],
                      "has_install": true,
                      "curseforge_modpacks": false,
                      "workshop_app_id": 0,
                      "workshop_dir": ""
                    },
                    "game": {
                      "id": 2,
                      "name": "Minecraft",
                      "cover_url": "",
                      "banner_url": ""
                    },
                    "plan_id": 3,
                    "plan_name": "标准 4G",
                    "cpu_cores": 2,
                    "memory_mb": 4096,
                    "disk_mb": 20480,
                    "monthly_price_cents": 3000,
                    "renewal_price_cents": 3000,
                    "recurring_coupon_code": "",
                    "billing_mode": "monthly",
                    "hourly_price_cents": 0,
                    "hourly_storage_price_cents": 0,
                    "hourly_storage_percent": 10,
                    "hourly_storage_paid": false,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": true,
                    "delete_at": null,
                    "startup_command": "java -Xmx3G -jar server.jar nogui",
                    "docker_image": "example/minecraft:java21",
                    "mount_path": "/data",
                    "ports": [
                      {
                        "container_port": 25565,
                        "host_port": 30001,
                        "protocol": "tcp"
                      }
                    ],
                    "primary_port": {
                      "container_port": 25565,
                      "host_port": 30001,
                      "protocol": "tcp"
                    },
                    "variables": [
                      {
                        "key": "MAX_PLAYERS",
                        "name": "最大人数",
                        "description": "",
                        "default_value": "20",
                        "input_type": "text",
                        "options": [],
                        "rule": "^[0-9]{1,3}$",
                        "user_editable": true,
                        "required_on_create": false,
                        "value": "20"
                      }
                    ],
                    "install_status": "installed",
                    "install_error": "",
                    "installed_at": "2026-11-24T08:05:00Z",
                    "has_install": true,
                    "modpack_id": null,
                    "modpack_name": "",
                    "modpack_version": "",
                    "modpack_icon_url": "",
                    "curseforge_project_id": 0,
                    "curseforge_file_id": 0,
                    "curseforge_slug": "",
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:06:00Z"
                  },
                  "message": "设置已更新",
                  "warnings": []
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_input",
            "description": "请求体无法解析"
          },
          {
            "status": 400,
            "code": "no_changes",
            "description": "没有提供任何字段"
          },
          {
            "status": 400,
            "code": "invalid_command",
            "description": "启动参数超过 4096 字节、含 NUL 或引用了未定义的变量"
          },
          {
            "status": 400,
            "code": "invalid_docker_image",
            "description": "运行镜像不属于该游戏"
          },
          {
            "status": 403,
            "code": "startup_command_locked",
            "description": "该版本不允许修改启动参数"
          },
          {
            "status": 403,
            "code": "insufficient_scope",
            "description": "开启自动续费，密钥缺少 billing"
          },
          {
            "status": 409,
            "code": "instance_busy",
            "description": "该实例正在调整端口或切换游戏，稍后再试"
          },
          {
            "status": 409,
            "code": "game_switched",
            "description": "实例已在此期间切换游戏，请重新读取后重试"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期（或已过到期时间），请先续费"
          },
          {
            "status": 409,
            "code": "instance_provisioning",
            "description": "实例正在创建中"
          },
          {
            "status": 409,
            "code": "instance_installing",
            "description": "实例正在安装"
          },
          {
            "status": 409,
            "code": "install_failed",
            "description": "节点报告安装失败"
          },
          {
            "status": 409,
            "code": "image_not_internal",
            "description": "运行镜像不来自平台镜像仓库"
          },
          {
            "status": 502,
            "code": "agent_settings_failed",
            "description": "节点重建容器失败"
          },
          {
            "status": 503,
            "code": "node_offline",
            "description": "节点离线，无法重建容器"
          }
        ]
      }
    },
    "/instances/{id}/variables": {
      "patch": {
        "operationId": "updateInstanceVariables",
        "summary": "修改实例变量",
        "description": "合并保存变量值，只能修改 `user_editable` 的变量；未提交的变量保持不变。\n\n- 只保存，不调用节点、不重建当前容器；新值在下次开机或重启（`start`/`restart` 会重新渲染）、重建容器或重新安装时生效。\n- 只校验提交的变量：值最多 1024 字节、不能含换行或 NUL；`select` 须是选项之一；有 `rule` 时须整体匹配；`required_on_create` 的变量不能改为空。\n- 隐藏/密码类变量只是面板不显示，游戏进程仍能读取；模板替换不做 shell 转义。",
        "tags": [
          "config"
        ],
        "x-scope": "write",
        "x-cli": "ocent instance variables 42 --var MAX_PLAYERS=30",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InstanceVariablesRequest"
              },
              "example": {
                "variables": {
                  "MAX_PLAYERS": "30"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "已保存。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceUpdateResult"
                },
                "example": {
                  "instance": {
                    "id": 42,
                    "name": "my-server",
                    "status": "running",
                    "status_detail": "",
                    "last_error": "",
                    "node": {
                      "id": 1,
                      "name": "华东一区",
                      "status": "online",
                      "public_host": "node1.example.com"
                    },
                    "connect_host": "node1.example.com",
                    "image": {
                      "id": 10,
                      "group_id": 2,
                      "name": "Paper",
                      "version": "1.21",
                      "description": "",
                      "docker_image": "example/minecraft:java21",
                      "docker_images": [
                        {
                          "name": "Java 21",
                          "image": "example/minecraft:java21"
                        }
                      ],
                      "ports": [
                        {
                          "container_port": 25565,
                          "protocol": "tcp",
                          "primary": true,
                          "mirror": false
                        }
                      ],
                      "mount_path": "/data",
                      "enabled": true,
                      "startup_command_locked": false,
                      "variables": [],
                      "has_install": true,
                      "curseforge_modpacks": false,
                      "workshop_app_id": 0,
                      "workshop_dir": ""
                    },
                    "game": {
                      "id": 2,
                      "name": "Minecraft",
                      "cover_url": "",
                      "banner_url": ""
                    },
                    "plan_id": 3,
                    "plan_name": "标准 4G",
                    "cpu_cores": 2,
                    "memory_mb": 4096,
                    "disk_mb": 20480,
                    "monthly_price_cents": 3000,
                    "renewal_price_cents": 3000,
                    "recurring_coupon_code": "",
                    "billing_mode": "monthly",
                    "hourly_price_cents": 0,
                    "hourly_storage_price_cents": 0,
                    "hourly_storage_percent": 10,
                    "hourly_storage_paid": false,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": true,
                    "delete_at": null,
                    "startup_command": "java -Xmx{{SERVER_MEMORY}}M -jar server.jar nogui",
                    "docker_image": "example/minecraft:java21",
                    "mount_path": "/data",
                    "ports": [
                      {
                        "container_port": 25565,
                        "host_port": 30001,
                        "protocol": "tcp"
                      }
                    ],
                    "primary_port": {
                      "container_port": 25565,
                      "host_port": 30001,
                      "protocol": "tcp"
                    },
                    "variables": [
                      {
                        "key": "MAX_PLAYERS",
                        "name": "最大人数",
                        "description": "",
                        "default_value": "20",
                        "input_type": "text",
                        "options": [],
                        "rule": "^[0-9]{1,3}$",
                        "user_editable": true,
                        "required_on_create": false,
                        "value": "30"
                      }
                    ],
                    "install_status": "installed",
                    "install_error": "",
                    "installed_at": "2026-11-24T08:05:00Z",
                    "has_install": true,
                    "modpack_id": null,
                    "modpack_name": "",
                    "modpack_version": "",
                    "modpack_icon_url": "",
                    "curseforge_project_id": 0,
                    "curseforge_file_id": 0,
                    "curseforge_slug": "",
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:06:00Z"
                  },
                  "message": "环境变量已保存，将在下次开机或重启时生效",
                  "warnings": []
                }
              }
            }
          },
          "400": {
            "description": "请求无效或变量校验失败（`invalid_variable` 带 `field`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "最大人数 的格式不符合要求",
                  "code": "invalid_variable",
                  "field": "MAX_PLAYERS"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_input",
            "description": "请求体无法解析或缺少 variables"
          },
          {
            "status": 400,
            "code": "no_changes",
            "description": "variables 为空对象"
          },
          {
            "status": 400,
            "code": "invalid_variable",
            "description": "变量不存在、不可修改、必填为空或格式不符（带 field）"
          },
          {
            "status": 409,
            "code": "instance_busy",
            "description": "该实例正在调整端口或切换游戏，稍后再试"
          },
          {
            "status": 409,
            "code": "game_switched",
            "description": "实例已在此期间切换游戏，请重新读取后重试"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期（或已过到期时间），请先续费"
          },
          {
            "status": 409,
            "code": "instance_provisioning",
            "description": "实例正在创建中"
          },
          {
            "status": 409,
            "code": "instance_installing",
            "description": "实例正在安装"
          }
        ]
      }
    },
    "/instances/{id}/reinstall": {
      "post": {
        "operationId": "reinstallInstance",
        "summary": "重新安装",
        "description": "停止实例，**保留数据目录**，重新运行版本的安装脚本（平台整合包实例会重新下载并解压覆盖同名文件；CurseForge 整合包会重新向 CurseForge 校验）。完成后保持停止，需手动开机。\n\n- 无请求体。`202` 只表示节点已接受，不代表安装完成：用 `GET /instances/{id}` 轮询直到 `status` 变为 `stopped`（成功）或 `install_failed`，日志见 `GET /instances/{id}/install`。\n- 等待游戏正常停止可能需要一段时间，客户端超时请设长一些。",
        "tags": [
          "config"
        ],
        "x-scope": "write",
        "x-danger": "destructive",
        "x-long-running": true,
        "x-cli": "ocent instance reinstall 42 --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "responses": {
          "202": {
            "description": "已开始重新安装。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceAcceptedResult"
                },
                "example": {
                  "instance": {
                    "id": 42,
                    "name": "my-server",
                    "status": "installing",
                    "status_detail": "正在执行安装脚本",
                    "last_error": "",
                    "node": {
                      "id": 1,
                      "name": "华东一区",
                      "status": "online",
                      "public_host": "node1.example.com"
                    },
                    "connect_host": "node1.example.com",
                    "image": {
                      "id": 10,
                      "group_id": 2,
                      "name": "Paper",
                      "version": "1.21",
                      "description": "",
                      "docker_image": "example/minecraft:java21",
                      "docker_images": [
                        {
                          "name": "Java 21",
                          "image": "example/minecraft:java21"
                        }
                      ],
                      "ports": [
                        {
                          "container_port": 25565,
                          "protocol": "tcp",
                          "primary": true,
                          "mirror": false
                        }
                      ],
                      "mount_path": "/data",
                      "enabled": true,
                      "startup_command_locked": false,
                      "variables": [],
                      "has_install": true,
                      "curseforge_modpacks": false,
                      "workshop_app_id": 0,
                      "workshop_dir": ""
                    },
                    "game": {
                      "id": 2,
                      "name": "Minecraft",
                      "cover_url": "",
                      "banner_url": ""
                    },
                    "plan_id": 3,
                    "plan_name": "标准 4G",
                    "cpu_cores": 2,
                    "memory_mb": 4096,
                    "disk_mb": 20480,
                    "monthly_price_cents": 3000,
                    "renewal_price_cents": 3000,
                    "recurring_coupon_code": "",
                    "billing_mode": "monthly",
                    "hourly_price_cents": 0,
                    "hourly_storage_price_cents": 0,
                    "hourly_storage_percent": 10,
                    "hourly_storage_paid": false,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": true,
                    "delete_at": null,
                    "startup_command": "java -Xmx{{SERVER_MEMORY}}M -jar server.jar nogui",
                    "docker_image": "example/minecraft:java21",
                    "mount_path": "/data",
                    "ports": [
                      {
                        "container_port": 25565,
                        "host_port": 30001,
                        "protocol": "tcp"
                      }
                    ],
                    "primary_port": {
                      "container_port": 25565,
                      "host_port": 30001,
                      "protocol": "tcp"
                    },
                    "variables": [
                      {
                        "key": "MAX_PLAYERS",
                        "name": "最大人数",
                        "description": "",
                        "default_value": "20",
                        "input_type": "text",
                        "options": [],
                        "rule": "^[0-9]{1,3}$",
                        "user_editable": true,
                        "required_on_create": false,
                        "value": "20"
                      }
                    ],
                    "install_status": "installing",
                    "install_error": "",
                    "installed_at": "2026-11-24T08:05:00Z",
                    "has_install": true,
                    "modpack_id": null,
                    "modpack_name": "",
                    "modpack_version": "",
                    "modpack_icon_url": "",
                    "curseforge_project_id": 0,
                    "curseforge_file_id": 0,
                    "curseforge_slug": "",
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:06:00Z"
                  },
                  "message": "已开始重新安装，完成后请手动开机"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "no_install",
            "description": "该游戏版本没有配置安装脚本"
          },
          {
            "status": 409,
            "code": "instance_busy",
            "description": "该实例正在调整端口或切换游戏，稍后再试"
          },
          {
            "status": 409,
            "code": "game_switched",
            "description": "实例已在此期间切换游戏，请重新读取后重试"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期（或已过到期时间），请先续费"
          },
          {
            "status": 409,
            "code": "instance_provisioning",
            "description": "实例正在创建中"
          },
          {
            "status": 409,
            "code": "instance_installing",
            "description": "实例正在安装"
          },
          {
            "status": 409,
            "code": "install_failed",
            "description": "节点报告安装失败"
          },
          {
            "status": 409,
            "code": "modpack_unavailable",
            "description": "实例使用的整合包已不存在"
          },
          {
            "status": 409,
            "code": "modpack_syncing",
            "description": "整合包仍在同步到存储机"
          },
          {
            "status": 409,
            "code": "image_not_internal",
            "description": "安装镜像或运行镜像不来自平台镜像仓库"
          },
          {
            "status": 400,
            "code": "curseforge_unsupported_loader",
            "description": "整合包加载器不受支持（只支持 Forge、NeoForge、Fabric）"
          },
          {
            "status": 404,
            "code": "curseforge_not_found",
            "description": "未找到该 CurseForge 整合包或文件"
          },
          {
            "status": 409,
            "code": "curseforge_blocked",
            "description": "整合包已被管理员屏蔽"
          },
          {
            "status": 409,
            "code": "curseforge_not_distributable",
            "description": "作者未开放该文件的第三方下载"
          },
          {
            "status": 409,
            "code": "curseforge_no_java",
            "description": "暂不支持该整合包的我的世界版本"
          },
          {
            "status": 409,
            "code": "curseforge_no_install_image",
            "description": "该版本未配置安装镜像"
          },
          {
            "status": 502,
            "code": "curseforge_unavailable",
            "description": "CurseForge 服务暂时不可用"
          },
          {
            "status": 503,
            "code": "curseforge_disabled",
            "description": "CurseForge 整合包开服未开放"
          },
          {
            "status": 502,
            "code": "agent_reinstall_failed",
            "description": "节点重新安装失败"
          },
          {
            "status": 503,
            "code": "node_offline",
            "description": "节点离线"
          }
        ]
      }
    },
    "/instances/{id}/switch-game": {
      "post": {
        "operationId": "switchInstanceGame",
        "summary": "切换游戏",
        "description": "**清空整个数据目录**，按新版本（可以是其他游戏，可选整合包）重新安装。保留套餐、价格、到期时间、节点与 SFTP 账号。\n\n- 本身不扣费，但若实例使用循环优惠码且新游戏不在其适用范围内，优惠会结束、之后续费按原价（`message` 中会说明），因此归为 `billing`。\n- `confirm_name` 必须与实例名完全一致。套餐须满足新游戏的最低配置（`plan_too_small` 时先升级套餐）。\n- 端口按新版本重新分配，自定义端口全部清除，外网端口通常会变化。\n- 成功返回 `202`：有安装步骤时 `status` 为 `installing`，否则为 `stopped`；完成后需手动开机。\n- 同步等待节点停止游戏并清空数据，客户端超时请设长一些。",
        "tags": [
          "config"
        ],
        "x-scope": "billing",
        "x-danger": "destructive",
        "x-long-running": true,
        "x-cli": "ocent instance switch-game 42 --image 11 --confirm-name my-server --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InstanceSwitchGameRequest"
              },
              "example": {
                "image_id": 11,
                "confirm_name": "my-server",
                "docker_image": "",
                "modpack_id": null,
                "variables": {},
                "startup_command": ""
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "已开始切换。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceAcceptedResult"
                },
                "example": {
                  "instance": {
                    "id": 42,
                    "name": "my-server",
                    "status": "installing",
                    "status_detail": "正在执行安装脚本",
                    "last_error": "",
                    "node": {
                      "id": 1,
                      "name": "华东一区",
                      "status": "online",
                      "public_host": "node1.example.com"
                    },
                    "connect_host": "node1.example.com",
                    "image": {
                      "id": 10,
                      "group_id": 2,
                      "name": "Paper",
                      "version": "1.21",
                      "description": "",
                      "docker_image": "example/minecraft:java21",
                      "docker_images": [
                        {
                          "name": "Java 21",
                          "image": "example/minecraft:java21"
                        }
                      ],
                      "ports": [
                        {
                          "container_port": 25565,
                          "protocol": "tcp",
                          "primary": true,
                          "mirror": false
                        }
                      ],
                      "mount_path": "/data",
                      "enabled": true,
                      "startup_command_locked": false,
                      "variables": [],
                      "has_install": true,
                      "curseforge_modpacks": false,
                      "workshop_app_id": 0,
                      "workshop_dir": ""
                    },
                    "game": {
                      "id": 2,
                      "name": "Minecraft",
                      "cover_url": "",
                      "banner_url": ""
                    },
                    "plan_id": 3,
                    "plan_name": "标准 4G",
                    "cpu_cores": 2,
                    "memory_mb": 4096,
                    "disk_mb": 20480,
                    "monthly_price_cents": 3000,
                    "renewal_price_cents": 3000,
                    "recurring_coupon_code": "",
                    "billing_mode": "monthly",
                    "hourly_price_cents": 0,
                    "hourly_storage_price_cents": 0,
                    "hourly_storage_percent": 10,
                    "hourly_storage_paid": false,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": true,
                    "delete_at": null,
                    "startup_command": "java -Xmx{{SERVER_MEMORY}}M -jar server.jar nogui",
                    "docker_image": "example/minecraft:java21",
                    "mount_path": "/data",
                    "ports": [
                      {
                        "container_port": 25565,
                        "host_port": 30001,
                        "protocol": "tcp"
                      }
                    ],
                    "primary_port": {
                      "container_port": 25565,
                      "host_port": 30001,
                      "protocol": "tcp"
                    },
                    "variables": [
                      {
                        "key": "MAX_PLAYERS",
                        "name": "最大人数",
                        "description": "",
                        "default_value": "20",
                        "input_type": "text",
                        "options": [],
                        "rule": "^[0-9]{1,3}$",
                        "user_editable": true,
                        "required_on_create": false,
                        "value": "20"
                      }
                    ],
                    "install_status": "installing",
                    "install_error": "",
                    "installed_at": null,
                    "has_install": true,
                    "modpack_id": null,
                    "modpack_name": "",
                    "modpack_version": "",
                    "modpack_icon_url": "",
                    "curseforge_project_id": 0,
                    "curseforge_file_id": 0,
                    "curseforge_slug": "",
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:06:00Z"
                  },
                  "message": "已开始切换游戏，安装完成后请手动开机"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_input",
            "description": "请求体无法解析、缺少 image_id/confirm_name，或 curseforge 与 modpack_id 同时出现"
          },
          {
            "status": 400,
            "code": "invalid_command",
            "description": "启动参数超过 4096 字节、含 NUL 或引用了未定义的变量"
          },
          {
            "status": 400,
            "code": "confirm_mismatch",
            "description": "confirm_name 与实例名称不一致"
          },
          {
            "status": 400,
            "code": "plan_too_small",
            "description": "当前套餐低于新游戏的最低配置"
          },
          {
            "status": 400,
            "code": "invalid_docker_image",
            "description": "运行镜像不属于目标版本"
          },
          {
            "status": 400,
            "code": "invalid_variable",
            "description": "变量不存在、不可修改、必填为空或格式不符（带 field）"
          },
          {
            "status": 400,
            "code": "invalid_modpack",
            "description": "整合包与版本不匹配，或该版本只能通过 CurseForge 整合包安装"
          },
          {
            "status": 403,
            "code": "startup_command_locked",
            "description": "目标版本不允许修改启动参数"
          },
          {
            "status": 409,
            "code": "switch_in_progress",
            "description": "该实例正在调整端口或切换游戏"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期（或已过到期时间），请先续费"
          },
          {
            "status": 409,
            "code": "instance_provisioning",
            "description": "实例正在创建中"
          },
          {
            "status": 409,
            "code": "instance_installing",
            "description": "实例正在安装"
          },
          {
            "status": 409,
            "code": "install_failed",
            "description": "节点报告安装失败"
          },
          {
            "status": 409,
            "code": "game_unavailable",
            "description": "目标版本不存在或未上架"
          },
          {
            "status": 409,
            "code": "no_capacity",
            "description": "节点可用端口不足或版本端口数超限"
          },
          {
            "status": 409,
            "code": "modpack_unavailable",
            "description": "整合包不存在、已停用或未上传"
          },
          {
            "status": 409,
            "code": "modpack_syncing",
            "description": "整合包仍在同步到存储机"
          },
          {
            "status": 409,
            "code": "image_not_internal",
            "description": "运行镜像或安装镜像不来自平台镜像仓库"
          },
          {
            "status": 400,
            "code": "curseforge_unsupported_loader",
            "description": "整合包加载器不受支持（只支持 Forge、NeoForge、Fabric）"
          },
          {
            "status": 400,
            "code": "curseforge_game_mismatch",
            "description": "整合包不属于该游戏"
          },
          {
            "status": 404,
            "code": "curseforge_not_found",
            "description": "未找到该 CurseForge 整合包或文件"
          },
          {
            "status": 409,
            "code": "curseforge_blocked",
            "description": "整合包已被管理员屏蔽"
          },
          {
            "status": 409,
            "code": "curseforge_not_distributable",
            "description": "作者未开放该文件的第三方下载"
          },
          {
            "status": 409,
            "code": "curseforge_no_java",
            "description": "暂不支持该整合包的我的世界版本"
          },
          {
            "status": 409,
            "code": "curseforge_no_install_image",
            "description": "该版本未配置安装镜像"
          },
          {
            "status": 502,
            "code": "curseforge_unavailable",
            "description": "CurseForge 服务暂时不可用"
          },
          {
            "status": 503,
            "code": "curseforge_disabled",
            "description": "CurseForge 整合包开服未开放"
          },
          {
            "status": 502,
            "code": "agent_unsupported",
            "description": "节点暂不支持切换游戏"
          },
          {
            "status": 502,
            "code": "agent_switch_failed",
            "description": "切换失败；若提示清空数据目录失败，部分文件可能已被删除"
          },
          {
            "status": 503,
            "code": "node_offline",
            "description": "节点离线"
          }
        ]
      }
    },
    "/instances/{id}/renew": {
      "post": {
        "operationId": "renewInstance",
        "summary": "续费实例",
        "description": "无请求体。按月实例续费 1 个月，按 `renewal_price_cents`（循环优惠后的价格）从余额扣费；新到期时间从原到期时间（已过期则从现在）顺延一个月。\n\n- 已到期（`expired`）的实例续费后恢复为 `stopped`（或到期前的安装状态），需手动开机。\n- 按小时实例：未到期时返回 `409 hourly_auto_billed`（系统每小时自动扣费）；已到期时调用本接口恢复计费，扣 1 小时存储价，`message` 为「已恢复按小时计费」，`order.kind` 为 `instance_hourly`。\n- **没有幂等键**：超时或断线后先查询实例 `expires_at` 与钱包流水，不要直接重试。",
        "tags": [
          "billing-ops"
        ],
        "x-scope": "billing",
        "x-danger": "billing",
        "x-cli": "ocent instance renew 42 --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "responses": {
          "200": {
            "description": "续费成功。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceRenewResult"
                },
                "example": {
                  "message": "续费成功",
                  "expires_at": "2027-01-24T08:00:00Z",
                  "order": {
                    "id": 342,
                    "user_id": 1001,
                    "kind": "instance_renewal",
                    "amount_cents": 3000,
                    "status": "paid",
                    "provider": "balance",
                    "provider_ref": "",
                    "instance_id": 42,
                    "discount_cents": 0,
                    "coupon_code": "",
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:00:00Z"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientBalance"
          },
          "403": {
            "description": "账号已被禁用，或密钥缺少 billing 权限。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "账号已被禁用，请联系管理员",
                  "code": "account_disabled"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "按小时实例未到期，无需手动续费。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "按小时计费实例会自动扣费，无需手动续费",
                  "code": "hourly_auto_billed"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-error-codes": [
          {
            "status": 402,
            "code": "insufficient_balance",
            "description": "余额不足"
          },
          {
            "status": 403,
            "code": "account_disabled",
            "description": "账号已被禁用"
          },
          {
            "status": 409,
            "code": "hourly_auto_billed",
            "description": "按小时实例未到期，由系统自动扣费"
          }
        ]
      }
    },
    "/instances/{id}/plans": {
      "get": {
        "operationId": "listInstancePlanOptions",
        "summary": "查询可更换的套餐与差价",
        "description": "列出实例所在节点在售的套餐及此刻更换的报价，用于 `POST /instances/{id}/plan`。\n\n- 按月实例的 `diff_cents` 按剩余天数（不足一天按一天）在 30 天月内折算新旧实际月价之差，向上取整；降级（`downgrade: true`）不能选择，报价为 0。\n- 按小时实例只列出支持小时价的套餐，`diff_cents` 恒为 0，`renewal_price_cents` 为新的小时价，另带 `hourly_storage_price_cents`；新价格从下一小时起生效。\n- `fits: false` 表示低于游戏最低配置（见 `min_resources`）。",
        "tags": [
          "billing-ops"
        ],
        "x-scope": "read",
        "x-cli": "ocent instance plans 42",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "responses": {
          "200": {
            "description": "套餐与报价。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstancePlanOptions"
                },
                "example": {
                  "billing_mode": "monthly",
                  "remaining_days": 17,
                  "min_resources": {
                    "cpu_cores": 1,
                    "memory_mb": 2048,
                    "disk_mb": 5120
                  },
                  "items": [
                    {
                      "id": 3,
                      "node_id": 1,
                      "name": "标准 4G",
                      "cpu_cores": 2,
                      "memory_mb": 4096,
                      "disk_mb": 20480,
                      "monthly_price_cents": 3000,
                      "hourly_price_cents": 6,
                      "sort_order": 0,
                      "enabled": true,
                      "current": true,
                      "fits": true,
                      "downgrade": false,
                      "diff_cents": 0,
                      "renewal_price_cents": 3000,
                      "recurring_discount_kept": false
                    },
                    {
                      "id": 4,
                      "node_id": 1,
                      "name": "高配 8G",
                      "cpu_cores": 4,
                      "memory_mb": 8192,
                      "disk_mb": 40960,
                      "monthly_price_cents": 6000,
                      "hourly_price_cents": 12,
                      "sort_order": 1,
                      "enabled": true,
                      "current": false,
                      "fits": true,
                      "downgrade": false,
                      "diff_cents": 1700,
                      "renewal_price_cents": 6000,
                      "recurring_discount_kept": false
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/instances/{id}/plan": {
      "post": {
        "operationId": "changeInstancePlan",
        "summary": "更换套餐",
        "description": "立即把实例换到同一节点的另一个套餐，节点按新配置重建容器（数据保留，运行中会重启）。不支持降级。\n\n- 必须带 `expected_diff_cents`（取自 `GET /instances/{id}/plans`）；服务端计算的差价不一致时返回 `409 price_changed`（带当前 `diff_cents`），不扣费，确认后用新金额重新提交。\n- 按月实例升级：先扣差价再重建容器，重建失败时自动退回差价（`502 agent_settings_failed`）。差价为 0 时先重建再记录。\n- 按小时实例：不折算、不扣费，传 `expected_diff_cents: 0`，可选 `expected_hourly_price_cents` 确认新小时价；新价格从下一小时起生效。\n- 新套餐不在循环优惠码适用范围内时优惠结束（`message` 中会说明）。\n- 同步等待节点重建容器，可能需要数分钟。",
        "tags": [
          "billing-ops"
        ],
        "x-scope": "billing",
        "x-danger": "billing",
        "x-long-running": true,
        "x-cli": "ocent instance plan-change 42 --plan 4 --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InstancePlanChangeRequest"
              },
              "example": {
                "plan_id": 4,
                "expected_diff_cents": 1700
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "已更换。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstancePlanChangeResult"
                },
                "example": {
                  "instance": {
                    "id": 42,
                    "name": "my-server",
                    "status": "running",
                    "status_detail": "套餐已更换，容器已重建",
                    "last_error": "",
                    "node": {
                      "id": 1,
                      "name": "华东一区",
                      "status": "online",
                      "public_host": "node1.example.com"
                    },
                    "connect_host": "node1.example.com",
                    "image": {
                      "id": 10,
                      "group_id": 2,
                      "name": "Paper",
                      "version": "1.21",
                      "description": "",
                      "docker_image": "example/minecraft:java21",
                      "docker_images": [
                        {
                          "name": "Java 21",
                          "image": "example/minecraft:java21"
                        }
                      ],
                      "ports": [
                        {
                          "container_port": 25565,
                          "protocol": "tcp",
                          "primary": true,
                          "mirror": false
                        }
                      ],
                      "mount_path": "/data",
                      "enabled": true,
                      "startup_command_locked": false,
                      "variables": [],
                      "has_install": true,
                      "curseforge_modpacks": false,
                      "workshop_app_id": 0,
                      "workshop_dir": ""
                    },
                    "game": {
                      "id": 2,
                      "name": "Minecraft",
                      "cover_url": "",
                      "banner_url": ""
                    },
                    "plan_id": 4,
                    "plan_name": "高配 8G",
                    "cpu_cores": 4,
                    "memory_mb": 8192,
                    "disk_mb": 40960,
                    "monthly_price_cents": 6000,
                    "renewal_price_cents": 6000,
                    "recurring_coupon_code": "",
                    "billing_mode": "monthly",
                    "hourly_price_cents": 0,
                    "hourly_storage_price_cents": 0,
                    "hourly_storage_percent": 10,
                    "hourly_storage_paid": false,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": true,
                    "delete_at": null,
                    "startup_command": "java -Xmx{{SERVER_MEMORY}}M -jar server.jar nogui",
                    "docker_image": "example/minecraft:java21",
                    "mount_path": "/data",
                    "ports": [
                      {
                        "container_port": 25565,
                        "host_port": 30001,
                        "protocol": "tcp"
                      }
                    ],
                    "primary_port": {
                      "container_port": 25565,
                      "host_port": 30001,
                      "protocol": "tcp"
                    },
                    "variables": [
                      {
                        "key": "MAX_PLAYERS",
                        "name": "最大人数",
                        "description": "",
                        "default_value": "20",
                        "input_type": "text",
                        "options": [],
                        "rule": "^[0-9]{1,3}$",
                        "user_editable": true,
                        "required_on_create": false,
                        "value": "20"
                      }
                    ],
                    "install_status": "installed",
                    "install_error": "",
                    "installed_at": "2026-11-24T08:05:00Z",
                    "has_install": true,
                    "modpack_id": null,
                    "modpack_name": "",
                    "modpack_version": "",
                    "modpack_icon_url": "",
                    "curseforge_project_id": 0,
                    "curseforge_file_id": 0,
                    "curseforge_slug": "",
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:06:00Z"
                  },
                  "diff_cents": 1700,
                  "message": "套餐已更换，已扣除差价 ¥17.00",
                  "warnings": []
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientBalance"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "状态冲突；`price_changed` 带当前 `diff_cents`（按小时实例另带 `hourly_price_cents`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "差价已变化，请确认新的金额后重试",
                  "code": "price_changed",
                  "diff_cents": 1800
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点调整配置失败，差价已退回。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "节点调整配置失败，差价已退回，请稍后重试",
                  "code": "agent_settings_failed"
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_input",
            "description": "请求体无法解析，或缺少 plan_id / expected_diff_cents"
          },
          {
            "status": 400,
            "code": "same_plan",
            "description": "实例已在使用该套餐"
          },
          {
            "status": 400,
            "code": "plan_too_small",
            "description": "套餐低于游戏最低配置"
          },
          {
            "status": 402,
            "code": "insufficient_balance",
            "description": "余额不足以支付差价"
          },
          {
            "status": 409,
            "code": "plan_change_in_progress",
            "description": "该实例正在更换套餐"
          },
          {
            "status": 409,
            "code": "instance_busy",
            "description": "该实例正在调整端口或切换游戏，稍后再试"
          },
          {
            "status": 409,
            "code": "game_switched",
            "description": "实例已在此期间切换游戏，请重新读取后重试"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期"
          },
          {
            "status": 409,
            "code": "instance_provisioning",
            "description": "实例正在创建中"
          },
          {
            "status": 409,
            "code": "instance_installing",
            "description": "实例正在安装"
          },
          {
            "status": 409,
            "code": "install_failed",
            "description": "安装失败，请先重新安装"
          },
          {
            "status": 409,
            "code": "plan_unavailable",
            "description": "套餐不属于该节点或未在售"
          },
          {
            "status": 409,
            "code": "hourly_unavailable",
            "description": "按小时实例的目标套餐不支持小时价"
          },
          {
            "status": 409,
            "code": "plan_downgrade_disabled",
            "description": "不支持降级"
          },
          {
            "status": 409,
            "code": "price_changed",
            "description": "差价或小时价已变化，带当前 diff_cents（按小时另带 hourly_price_cents）"
          },
          {
            "status": 409,
            "code": "plan_changed",
            "description": "套餐已被并发修改，请刷新后重试"
          },
          {
            "status": 502,
            "code": "agent_settings_failed",
            "description": "节点调整配置失败（升级的差价已退回）"
          },
          {
            "status": 503,
            "code": "node_offline",
            "description": "节点离线"
          }
        ]
      }
    },
    "/instances/{id}/delete-refund": {
      "get": {
        "operationId": "getInstanceDeleteRefund",
        "summary": "试算删除退款",
        "description": "试算此刻删除实例（`DELETE /instances/{id}`）会退回多少余额，不做任何修改。\n\n规则：剩余价值 = 实际月价 × 剩余整天数 ÷ 30（当天不退）；可退价值 = min(剩余价值, 该实例已付净额)；退款 = 可退价值 × 80%，每步向下取整到分。按小时实例全部为 0。",
        "tags": [
          "billing-ops"
        ],
        "x-scope": "read",
        "x-cli": "ocent api GET /instances/42/delete-refund",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "responses": {
          "200": {
            "description": "退款试算。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceDeleteRefundQuote"
                },
                "example": {
                  "monthly_price_cents": 3000,
                  "remaining_days": 29,
                  "remaining_value_cents": 2900,
                  "refundable_value_cents": 2900,
                  "refund_percent": 80,
                  "refund_cents": 2320
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/instances/{id}/ports": {
      "get": {
        "operationId": "getInstancePorts",
        "summary": "查询端口映射",
        "description": "返回连接地址与端口列表：先列游戏版本自带端口（`source: \"image\"`，不可删除），再列自行添加的端口（`source: \"custom\"`）。同一外网端口的 TCP 与 UDP 合并为一条 `tcp_udp`。\n\n游戏连接与 SFTP 都直接连接节点，不经过主控。",
        "tags": [
          "network"
        ],
        "x-scope": "read",
        "x-cli": "ocent instance ports 42",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "responses": {
          "200": {
            "description": "端口列表。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceNetwork"
                },
                "example": {
                  "connect_host": "node1.example.com",
                  "items": [
                    {
                      "container_port": 25565,
                      "host_port": 30001,
                      "protocol": "tcp",
                      "source": "image",
                      "primary": true,
                      "remark": "",
                      "mirror": false
                    },
                    {
                      "container_port": 8123,
                      "host_port": 30002,
                      "protocol": "tcp",
                      "source": "custom",
                      "primary": false,
                      "remark": "地图",
                      "mirror": false
                    }
                  ],
                  "extra_count": 1,
                  "extra_limit": 10
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "addInstancePort",
        "summary": "添加端口",
        "description": "开放一个容器端口，外网端口从节点端口范围自动分配；`mirror: true` 时申请对等端口（容器端口与外网端口相同，供必须监听玩家连接端口的游戏或插件使用）。\n\n- 每个实例最多 10 条自定义端口（`tcp_udp` 计 1 条）。同一容器端口与协议已开放时返回 `409 port_exists`。\n- **会重建容器，运行中的实例会被重启**；节点失败时自动撤销本次分配。\n- 响应为变更后的端口列表加 `message` 与 `warnings`。",
        "tags": [
          "network"
        ],
        "x-scope": "write",
        "x-long-running": true,
        "x-cli": "ocent api POST /instances/42/ports --data '{\"container_port\":8123,\"protocol\":\"tcp\",\"remark\":\"地图\"}' --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InstancePortAddRequest"
              },
              "example": {
                "container_port": 8123,
                "protocol": "tcp",
                "remark": "地图"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "已添加。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceNetworkChange"
                },
                "example": {
                  "connect_host": "node1.example.com",
                  "items": [
                    {
                      "container_port": 25565,
                      "host_port": 30001,
                      "protocol": "tcp",
                      "source": "image",
                      "primary": true,
                      "remark": "",
                      "mirror": false
                    },
                    {
                      "container_port": 8123,
                      "host_port": 30002,
                      "protocol": "tcp",
                      "source": "custom",
                      "primary": false,
                      "remark": "地图",
                      "mirror": false
                    }
                  ],
                  "extra_count": 1,
                  "extra_limit": 10,
                  "message": "已开放容器端口 8123，外网端口 30002",
                  "warnings": []
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_input",
            "description": "请求体无法解析"
          },
          {
            "status": 400,
            "code": "invalid_port",
            "description": "非对等端口时 container_port 不在 1–65535"
          },
          {
            "status": 400,
            "code": "invalid_protocol",
            "description": "协议不是 tcp、udp 或 tcp_udp"
          },
          {
            "status": 400,
            "code": "invalid_remark",
            "description": "备注超过 40 个字"
          },
          {
            "status": 409,
            "code": "extra_port_limit",
            "description": "自定义端口已达 10 条"
          },
          {
            "status": 409,
            "code": "port_exists",
            "description": "该容器端口与协议已开放"
          },
          {
            "status": 409,
            "code": "port_change_in_progress",
            "description": "该实例正在调整端口"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期（或已过到期时间），请先续费"
          },
          {
            "status": 409,
            "code": "instance_provisioning",
            "description": "实例正在创建中"
          },
          {
            "status": 409,
            "code": "instance_installing",
            "description": "实例正在安装"
          },
          {
            "status": 409,
            "code": "install_failed",
            "description": "节点报告安装失败"
          },
          {
            "status": 409,
            "code": "instance_not_ready",
            "description": "实例尚未分配端口"
          },
          {
            "status": 409,
            "code": "no_free_port",
            "description": "节点可用端口不足"
          },
          {
            "status": 409,
            "code": "ports_changed",
            "description": "端口分配冲突，请重试"
          },
          {
            "status": 502,
            "code": "agent_unsupported",
            "description": "节点暂不支持调整端口"
          },
          {
            "status": 502,
            "code": "agent_settings_failed",
            "description": "节点调整端口失败"
          },
          {
            "status": 503,
            "code": "node_offline",
            "description": "节点离线"
          }
        ]
      }
    },
    "/instances/{id}/ports/{protocol}/{port}": {
      "delete": {
        "operationId": "deleteInstancePort",
        "summary": "删除端口",
        "description": "关闭一个自行添加的端口并释放其外网端口。`port` 是**容器端口**，`protocol` 须与添加时一致；版本自带端口不能删除（`404 port_not_found`）。\n\n**会重建容器，运行中的实例会被重启。** 响应为变更后的端口列表加 `message` 与 `warnings`。",
        "tags": [
          "network"
        ],
        "x-scope": "write",
        "x-long-running": true,
        "x-cli": "ocent api DELETE /instances/42/ports/tcp/8123 --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          },
          {
            "name": "protocol",
            "in": "path",
            "required": true,
            "description": "端口协议，与添加时一致",
            "schema": {
              "type": "string",
              "enum": [
                "tcp",
                "udp",
                "tcp_udp"
              ]
            },
            "example": "tcp"
          },
          {
            "name": "port",
            "in": "path",
            "required": true,
            "description": "容器端口",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 65535
            },
            "example": 8123
          }
        ],
        "responses": {
          "200": {
            "description": "已删除。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceNetworkChange"
                },
                "example": {
                  "connect_host": "node1.example.com",
                  "items": [
                    {
                      "container_port": 25565,
                      "host_port": 30001,
                      "protocol": "tcp",
                      "source": "image",
                      "primary": true,
                      "remark": "",
                      "mirror": false
                    }
                  ],
                  "extra_count": 0,
                  "extra_limit": 10,
                  "message": "已关闭容器端口 8123",
                  "warnings": []
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "实例不存在，或该端口不是自行添加的端口。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "只能删除自行添加的端口",
                  "code": "port_not_found"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_port",
            "description": "端口不在 1–65535 或协议无效"
          },
          {
            "status": 404,
            "code": "port_not_found",
            "description": "只能删除自行添加的端口"
          },
          {
            "status": 409,
            "code": "port_change_in_progress",
            "description": "该实例正在调整端口"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期（或已过到期时间），请先续费"
          },
          {
            "status": 409,
            "code": "instance_provisioning",
            "description": "实例正在创建中"
          },
          {
            "status": 409,
            "code": "instance_installing",
            "description": "实例正在安装"
          },
          {
            "status": 409,
            "code": "install_failed",
            "description": "节点报告安装失败"
          },
          {
            "status": 409,
            "code": "instance_not_ready",
            "description": "实例尚未分配端口"
          },
          {
            "status": 502,
            "code": "agent_unsupported",
            "description": "节点暂不支持调整端口"
          },
          {
            "status": 502,
            "code": "agent_settings_failed",
            "description": "节点调整端口失败"
          },
          {
            "status": 503,
            "code": "node_offline",
            "description": "节点离线"
          }
        ]
      }
    },
    "/instances/{id}/sftp": {
      "get": {
        "operationId": "getInstanceSFTP",
        "summary": "读取 SFTP 凭据",
        "description": "返回 SFTP 主机、端口、用户名与**明文密码**。读取凭据属于 `write` 权限。\n\nSFTP 直接连接节点，不经过主控。需要更换密码时用 `POST /instances/{id}/sftp/reset`。",
        "tags": [
          "network"
        ],
        "x-scope": "write",
        "x-cli": "ocent instance sftp 42",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "responses": {
          "200": {
            "description": "SFTP 凭据。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceSFTPResponse"
                },
                "example": {
                  "sftp": {
                    "host": "node1.example.com",
                    "port": 2022,
                    "username": "dc-42",
                    "password": "xxxxxxxxxxxxxxxxxxxxxxxx"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/instances/{id}/sftp/reset": {
      "post": {
        "operationId": "resetInstanceSFTP",
        "summary": "重置 SFTP 密码",
        "description": "生成新的随机 SFTP 密码并同步到节点，返回新的凭据；旧密码立即失效。无请求体。",
        "tags": [
          "network"
        ],
        "x-scope": "write",
        "x-cli": "ocent instance sftp-reset 42",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "responses": {
          "200": {
            "description": "新的 SFTP 凭据。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceSFTPResponse"
                },
                "example": {
                  "sftp": {
                    "host": "node1.example.com",
                    "port": 2022,
                    "username": "dc-42",
                    "password": "xxxxxxxxxxxxxxxxxxxxxxxx"
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点重置失败。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "SFTP 密码重置失败，请稍后重试",
                  "code": "agent_sftp_failed"
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          }
        },
        "x-error-codes": [
          {
            "status": 502,
            "code": "agent_sftp_failed",
            "description": "节点重置 SFTP 密码失败"
          },
          {
            "status": 503,
            "code": "node_offline",
            "description": "节点离线"
          }
        ]
      }
    },
    "/instances/{id}/steam-query": {
      "get": {
        "operationId": "querySteamServer",
        "summary": "查询 Steam 在线人数",
        "description": "由节点通过 Steam A2S 协议查询游戏服务器的名称、地图与在线人数，只适用于支持 A2S 的游戏。\n\n- `container_port` 必须是实例已映射 UDP 的**容器端口**，且不能带其他查询参数（不支持指定目标主机）。\n- 实例须在 `starting` 或 `running` 且不在安装中。\n- `503 query_unavailable` 表示未收到有效响应，**不代表 0 人**。\n- 响应带 `Cache-Control: no-store`。",
        "tags": [
          "network"
        ],
        "x-scope": "read",
        "x-rate-limit": "30 次/分钟/IP",
        "x-cli": "ocent api GET /instances/42/steam-query --query container_port=27015",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          },
          {
            "name": "container_port",
            "in": "query",
            "required": true,
            "description": "已映射 UDP 的容器端口（不是外网端口）",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 65535
            },
            "example": 27015
          }
        ],
        "responses": {
          "200": {
            "description": "查询结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceSteamQueryResult"
                },
                "example": {
                  "protocol": "a2s",
                  "sampled_at": "2026-11-24T08:00:00Z",
                  "name": "My Server",
                  "map": "world",
                  "players": 3,
                  "max_players": 20,
                  "bots": 0,
                  "app_id": 0,
                  "version": "1.0",
                  "latency_ms": 12.5
                }
              }
            }
          },
          "400": {
            "description": "查询端口无效。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "该容器端口没有分配 UDP 映射",
                  "code": "query_port_invalid"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "实例已到期，或密钥无权访问。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例已到期，无法查询",
                  "code": "instance_expired"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "description": "实例未运行。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例尚未运行，无法查询在线人数",
                  "code": "query_not_running"
                }
              }
            }
          },
          "429": {
            "description": "超过限流（`rate_limited`），或节点查询过于频繁（`query_busy`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "查询过于频繁，请稍后重试",
                  "code": "query_busy"
                }
              }
            }
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "description": "节点不可用（`node_offline`），或未收到有效 A2S 响应（`query_unavailable`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "未收到有效 Steam A2S 响应：请核对查询端口、游戏启动状态及协议支持；这不代表在线人数为 0",
                  "code": "query_unavailable"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "query_port_invalid",
            "description": "缺少或多出查询参数、端口无效，或该容器端口没有 UDP 映射"
          },
          {
            "status": 403,
            "code": "instance_expired",
            "description": "实例已到期"
          },
          {
            "status": 409,
            "code": "query_not_running",
            "description": "实例或游戏容器未运行"
          },
          {
            "status": 429,
            "code": "query_busy",
            "description": "节点查询过于频繁"
          },
          {
            "status": 502,
            "code": "query_unsupported",
            "description": "节点 Agent 缺少查询接口或实例不存在"
          },
          {
            "status": 502,
            "code": "agent_unavailable",
            "description": "无法获取节点查询结果"
          },
          {
            "status": 503,
            "code": "node_offline",
            "description": "节点未启用或不在线"
          },
          {
            "status": 503,
            "code": "query_unavailable",
            "description": "未收到有效 A2S 响应，不代表 0 人"
          }
        ]
      }
    },
    "/instances/{id}/workshop": {
      "get": {
        "operationId": "getInstanceWorkshop",
        "summary": "查询创意工坊物品与任务",
        "description": "返回已安装的创意工坊物品与正在运行（或最近一次）的安装任务。仅当版本 `image.workshop_app_id > 0` 时可用。\n\n安装任务运行中（`task.status: \"running\"`）建议每 3 秒左右轮询一次。",
        "tags": [
          "workshop"
        ],
        "x-scope": "read",
        "x-rate-limit": "240 次/分钟/用户",
        "x-cli": "ocent api GET /instances/42/workshop",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "responses": {
          "200": {
            "description": "创意工坊状态。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceWorkshopState"
                },
                "example": {
                  "app_id": 322330,
                  "items": [
                    {
                      "item_id": "2824688072",
                      "title": "Example Mod",
                      "dir": "mods/workshop-2824688072",
                      "bytes": 1048576,
                      "files": 12,
                      "time_updated": 1732435200,
                      "installed_at": "2026-11-24T08:00:00Z"
                    }
                  ],
                  "task": {
                    "status": "idle",
                    "started_at": "",
                    "finished_at": "",
                    "items": []
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "实例不存在，或该版本不支持创意工坊（`workshop_unsupported`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "该版本不支持创意工坊",
                  "code": "workshop_unsupported"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "description": "平台未开启创意工坊。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "创意工坊功能未开启",
                  "code": "workshop_disabled"
                }
              }
            }
          },
          "504": {
            "description": "节点响应超时。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "节点响应超时，请稍后刷新查看",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 404,
            "code": "workshop_unsupported",
            "description": "该版本不支持创意工坊（workshop_app_id 为 0）"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或节点上未找到该实例"
          },
          {
            "status": 503,
            "code": "workshop_disabled",
            "description": "平台未开启创意工坊"
          },
          {
            "status": 502,
            "code": "agent_unsupported",
            "description": "节点暂不支持创意工坊"
          },
          {
            "status": 502,
            "code": "workshop_agent_error",
            "description": "节点处理失败"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "节点响应超时，稍后刷新查看"
          }
        ]
      },
      "post": {
        "operationId": "installInstanceWorkshopItems",
        "summary": "安装创意工坊物品",
        "description": "在节点后台下载并安装创意工坊物品，立即返回 `202` 与任务状态；用 `GET /instances/{id}/workshop` 轮询进度。\n\n- 已有任务运行时返回 `409 workshop_busy`；已安装与新装合计不能超过 200 个。\n- 下载内容计入实例数据目录，节点按套餐 `disk_mb` 限制本次下载总量。",
        "tags": [
          "workshop"
        ],
        "x-scope": "write",
        "x-rate-limit": "30 次/分钟/用户（与删除合计）",
        "x-cli": "ocent api POST /instances/42/workshop --data '{\"item_ids\":[\"2824688072\"]}' --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InstanceWorkshopInstallRequest"
              },
              "example": {
                "item_ids": [
                  "2824688072"
                ]
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "已开始安装。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceWorkshopState"
                },
                "example": {
                  "app_id": 322330,
                  "items": [
                    {
                      "item_id": "2824688072",
                      "title": "Example Mod",
                      "dir": "mods/workshop-2824688072",
                      "bytes": 1048576,
                      "files": 12,
                      "time_updated": 1732435200,
                      "installed_at": "2026-11-24T08:00:00Z"
                    }
                  ],
                  "task": {
                    "status": "running",
                    "started_at": "2026-11-24T08:10:00Z",
                    "finished_at": "",
                    "items": [
                      {
                        "item_id": "2824688072",
                        "status": "queued",
                        "error": "",
                        "bytes_done": 0,
                        "bytes_total": 0
                      }
                    ]
                  }
                }
              }
            }
          },
          "400": {
            "description": "物品 ID 无效或数量超限。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "请填写 1-50 个创意工坊物品 ID，每个为 1-20 位数字",
                  "code": "invalid_item_ids"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "实例已到期，或密钥无权访问。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例已到期，请先续费",
                  "code": "instance_expired"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在，或该版本不支持创意工坊（`workshop_unsupported`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "该版本不支持创意工坊",
                  "code": "workshop_unsupported"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "description": "平台未开启创意工坊。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "创意工坊功能未开启",
                  "code": "workshop_disabled"
                }
              }
            }
          },
          "504": {
            "description": "节点响应超时。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "节点响应超时，请稍后刷新查看",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_item_ids",
            "description": "物品 ID 不是 1–20 位无前导零的数字，或去重后不在 1–50 个"
          },
          {
            "status": 400,
            "code": "too_many_items",
            "description": "安装后物品总数超过 200"
          },
          {
            "status": 403,
            "code": "instance_expired",
            "description": "实例已到期"
          },
          {
            "status": 409,
            "code": "instance_installing",
            "description": "实例正在安装"
          },
          {
            "status": 409,
            "code": "workshop_busy",
            "description": "已有创意工坊任务在运行"
          },
          {
            "status": 404,
            "code": "workshop_unsupported",
            "description": "该版本不支持创意工坊（workshop_app_id 为 0）"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或节点上未找到该实例"
          },
          {
            "status": 503,
            "code": "workshop_disabled",
            "description": "平台未开启创意工坊"
          },
          {
            "status": 502,
            "code": "agent_unsupported",
            "description": "节点暂不支持创意工坊"
          },
          {
            "status": 502,
            "code": "workshop_agent_error",
            "description": "节点处理失败"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "节点响应超时，稍后刷新查看"
          }
        ]
      }
    },
    "/instances/{id}/workshop/{item_id}": {
      "delete": {
        "operationId": "removeInstanceWorkshopItem",
        "summary": "删除创意工坊物品",
        "description": "删除一个已安装的物品（目录与记录）。物品不存在视为成功。返回删除后的状态。\n\n数据目录中的记录文件 `.ocent-workshop.json` 无效时返回 `409 workshop_record_invalid`，可通过文件管理修复或删除该文件后重试。",
        "tags": [
          "workshop"
        ],
        "x-scope": "write",
        "x-rate-limit": "30 次/分钟/用户（与安装合计）",
        "x-cli": "ocent api DELETE /instances/42/workshop/2824688072 --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          },
          {
            "name": "item_id",
            "in": "path",
            "required": true,
            "description": "物品 ID（1–20 位数字，无前导零）",
            "schema": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,19}$"
            },
            "example": "2824688072"
          }
        ],
        "responses": {
          "200": {
            "description": "已删除。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InstanceWorkshopState"
                },
                "example": {
                  "app_id": 322330,
                  "items": [],
                  "task": {
                    "status": "idle",
                    "started_at": "",
                    "finished_at": "",
                    "items": []
                  }
                }
              }
            }
          },
          "400": {
            "description": "物品 ID 无效。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "创意工坊物品 ID 应为 1-20 位数字",
                  "code": "invalid_item_ids"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "实例已到期，或密钥无权访问。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例已到期，请先续费",
                  "code": "instance_expired"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在，或该版本不支持创意工坊（`workshop_unsupported`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "该版本不支持创意工坊",
                  "code": "workshop_unsupported"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "description": "平台未开启创意工坊。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "创意工坊功能未开启",
                  "code": "workshop_disabled"
                }
              }
            }
          },
          "504": {
            "description": "节点响应超时。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "节点响应超时，请稍后刷新查看",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_item_ids",
            "description": "物品 ID 不是 1–20 位无前导零的数字"
          },
          {
            "status": 403,
            "code": "instance_expired",
            "description": "实例已到期"
          },
          {
            "status": 409,
            "code": "instance_installing",
            "description": "实例正在安装"
          },
          {
            "status": 409,
            "code": "workshop_busy",
            "description": "已有创意工坊任务在运行"
          },
          {
            "status": 409,
            "code": "workshop_record_invalid",
            "description": "记录文件 .ocent-workshop.json 无效"
          },
          {
            "status": 404,
            "code": "workshop_unsupported",
            "description": "该版本不支持创意工坊（workshop_app_id 为 0）"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或节点上未找到该实例"
          },
          {
            "status": 503,
            "code": "workshop_disabled",
            "description": "平台未开启创意工坊"
          },
          {
            "status": 502,
            "code": "agent_unsupported",
            "description": "节点暂不支持创意工坊"
          },
          {
            "status": 502,
            "code": "workshop_agent_error",
            "description": "节点处理失败"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "节点响应超时，稍后刷新查看"
          }
        ]
      }
    },
    "/instances/{id}/files": {
      "get": {
        "operationId": "listFiles",
        "summary": "列出目录",
        "description": "列出实例数据目录内某个目录的直接子项，并返回该节点允许上传的单个文件上限 `max_upload_bytes`。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- `path` 省略或为空时列出根目录 `/`。\n- `path` 必须是已存在的目录。\n- 不会递归列出子目录。",
        "tags": [
          "files"
        ],
        "x-scope": "read",
        "x-cli": "ocent file ls 42 /plugins",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          },
          {
            "name": "path",
            "in": "query",
            "required": false,
            "description": "要列出的目录，默认 `/`",
            "schema": {
              "type": "string"
            },
            "example": "/plugins"
          }
        ],
        "responses": {
          "200": {
            "description": "目录列表",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileList"
                },
                "example": {
                  "path": "/plugins",
                  "entries": [
                    {
                      "name": "EssentialsX",
                      "path": "/plugins/EssentialsX",
                      "is_dir": true,
                      "size": 4096,
                      "modified_at": "2026-11-20T03:12:00Z",
                      "mode": "drwxr-x---"
                    },
                    {
                      "name": "EssentialsX.jar",
                      "path": "/plugins/EssentialsX.jar",
                      "is_dir": false,
                      "size": 1048576,
                      "modified_at": "2026-11-20T03:10:00Z",
                      "mode": "-rw-r-----"
                    }
                  ],
                  "max_upload_bytes": 5368709120
                }
              }
            }
          },
          "400": {
            "description": "路径无效。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "路径不能包含 ..",
                  "code": "invalid_path"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "实例不存在（或不属于当前用户），或目标文件/目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件或目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_path",
            "description": "路径含 `..` 或 NUL"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或文件/目录不存在"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "操作超时，可能已部分完成"
          }
        ]
      },
      "delete": {
        "operationId": "deleteFile",
        "summary": "删除单个文件或目录",
        "description": "删除一个文件或目录；目录连同其全部内容一起删除，**不可恢复**。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- 不能删除根目录 `/`（`400 invalid_path`）。\n- 批量删除请用 `POST /instances/{id}/files/delete`。\n- 实例已到期（`expired` 或已过到期时间）时返回 `409 instance_expired`。",
        "tags": [
          "files"
        ],
        "x-scope": "write",
        "x-danger": "destructive",
        "x-cli": "ocent api DELETE /instances/42/files --query path=/logs/old.log --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          },
          {
            "name": "path",
            "in": "query",
            "required": true,
            "description": "要删除的文件或目录，不能是 `/`",
            "schema": {
              "type": "string"
            },
            "example": "/logs/old.log"
          }
        ],
        "responses": {
          "200": {
            "description": "已删除",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessageResponse"
                },
                "example": {
                  "message": "已删除"
                }
              }
            }
          },
          "400": {
            "description": "路径无效或为根目录。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "不能删除实例根目录",
                  "code": "invalid_path"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限（`insufficient_scope`），或节点上的文件没有访问权限（`permission_denied`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "API 密钥缺少 write 权限",
                  "code": "insufficient_scope",
                  "required_scope": "write"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在（或不属于当前用户），或目标文件/目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件或目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "实例已到期，文件写操作被拒绝（读取与下载仍可用）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例已到期，请先续费",
                  "code": "instance_expired"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_path",
            "description": "路径为空、为 `/` 或含 `..`"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或文件/目录不存在"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "操作超时，可能已部分完成"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期，写操作被拒绝"
          }
        ]
      }
    },
    "/instances/{id}/files/download": {
      "get": {
        "operationId": "downloadFile",
        "summary": "下载文件",
        "description": "以原始字节流返回一个文件，响应带 `Content-Disposition: attachment; filename=...`，节点提供时带 `Content-Length`。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- 只能下载文件；`path` 为目录时返回 `400 is_directory`，为空或 `/` 时返回 `400 invalid_path`。\n- 服务端单次下载最长 1 小时，大文件请设置足够长的客户端超时。\n- 不支持 `Range` 断点续传。\n- 错误响应仍为 JSON。",
        "tags": [
          "files"
        ],
        "x-scope": "read",
        "x-long-running": true,
        "x-cli": "ocent file download 42 /world.zip ./world.zip",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          },
          {
            "name": "path",
            "in": "query",
            "required": true,
            "description": "要下载的文件",
            "schema": {
              "type": "string"
            },
            "example": "/world.zip"
          }
        ],
        "responses": {
          "200": {
            "description": "文件原始内容",
            "headers": {
              "Content-Disposition": {
                "description": "`attachment; filename=<文件名>`",
                "schema": {
                  "type": "string"
                },
                "example": "attachment; filename=world.zip"
              },
              "Content-Length": {
                "description": "文件大小（字节），节点提供时返回",
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "路径无效或是目录。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "请选择有效文件",
                  "code": "invalid_path"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "实例不存在（或不属于当前用户），或目标文件/目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件或目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_path",
            "description": "路径为空、为 `/` 或含 `..`"
          },
          {
            "status": 400,
            "code": "is_directory",
            "description": "目标是目录"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或文件/目录不存在"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "操作超时，可能已部分完成"
          }
        ]
      }
    },
    "/instances/{id}/files/content": {
      "get": {
        "operationId": "readFileContent",
        "summary": "读取文本文件",
        "description": "读取一个 UTF-8 文本文件的完整内容，供在线编辑使用。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- 文件必须是文本且不超过 4 MiB：二进制文件返回 `415 not_text`，超过大小返回 `413 too_large`（请改用下载接口）。\n- `path` 为空或 `/` 时返回 `400 invalid_path`。",
        "tags": [
          "files"
        ],
        "x-scope": "read",
        "x-cli": "ocent file cat 42 /server.properties --text",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          },
          {
            "name": "path",
            "in": "query",
            "required": true,
            "description": "要读取的文本文件",
            "schema": {
              "type": "string"
            },
            "example": "/server.properties"
          }
        ],
        "responses": {
          "200": {
            "description": "文件内容",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileContent"
                },
                "example": {
                  "path": "/server.properties",
                  "content": "motd=A Minecraft Server\nmax-players=20\n",
                  "size": 1386,
                  "modified_at": "2026-11-24T08:30:00Z"
                }
              }
            }
          },
          "400": {
            "description": "路径无效或是目录。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "请选择有效文件",
                  "code": "invalid_path"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "实例不存在（或不属于当前用户），或目标文件/目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件或目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "413": {
            "description": "文件超过 4 MiB。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件超过 4 MiB，无法在线编辑，请下载后修改",
                  "code": "too_large"
                }
              }
            }
          },
          "415": {
            "description": "不是文本文件。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "该文件不是文本文件，无法在线编辑",
                  "code": "not_text"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_path",
            "description": "路径为空、为 `/` 或含 `..`"
          },
          {
            "status": 400,
            "code": "is_directory",
            "description": "目标是目录"
          },
          {
            "status": 413,
            "code": "too_large",
            "description": "文件超过 4 MiB"
          },
          {
            "status": 415,
            "code": "not_text",
            "description": "不是 UTF-8 文本文件"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或文件/目录不存在"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "操作超时，可能已部分完成"
          }
        ]
      },
      "put": {
        "operationId": "writeFileContent",
        "summary": "写入文本文件",
        "description": "用请求中的文本**整体覆盖**一个文件；文件不存在时新建（面板的「新建文件」即用此接口）。写入通过临时文件加原子替换完成。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- `content` 最大 4 MiB（UTF-8 字节数），超过返回 `413 too_large`。\n- 上级目录必须已存在，否则返回 `404 not_found`（提示「上级目录不存在」）。\n- 目标是目录时返回 `400 is_directory`。\n- 实例已到期（`expired` 或已过到期时间）时返回 `409 instance_expired`。",
        "tags": [
          "files"
        ],
        "x-scope": "write",
        "x-cli": "ocent file write 42 /server.properties --from-file ./server.properties",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FileWriteRequest"
              },
              "example": {
                "path": "/server.properties",
                "content": "motd=Ocent Server\nmax-players=20\n"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "写入后的文件条目",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileEntry"
                },
                "example": {
                  "name": "server.properties",
                  "path": "/server.properties",
                  "is_dir": false,
                  "size": 34,
                  "modified_at": "2026-11-24T09:00:00Z",
                  "mode": "-rw-r--r--"
                }
              }
            }
          },
          "400": {
            "description": "缺少 `path`、路径无效或目标是目录。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "请输入文件路径",
                  "code": "invalid_path"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限（`insufficient_scope`），或节点上的文件没有访问权限（`permission_denied`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "API 密钥缺少 write 权限",
                  "code": "insufficient_scope",
                  "required_scope": "write"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在，或上级目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "上级目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "实例已到期，文件写操作被拒绝（读取与下载仍可用）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例已到期，请先续费",
                  "code": "instance_expired"
                }
              }
            }
          },
          "413": {
            "description": "内容超过 4 MiB。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件内容超过 4 MiB，无法保存",
                  "code": "too_large"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_path",
            "description": "缺少 `path`、请求体无法解析、路径为 `/` 或含 `..`"
          },
          {
            "status": 400,
            "code": "is_directory",
            "description": "目标是目录"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或上级目录不存在"
          },
          {
            "status": 413,
            "code": "too_large",
            "description": "内容超过 4 MiB"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "操作超时，可能已部分完成"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期，写操作被拒绝"
          }
        ]
      }
    },
    "/instances/{id}/files/upload": {
      "post": {
        "operationId": "uploadFile",
        "summary": "上传文件",
        "description": "以 `multipart/form-data` 上传一个文件到 `path` 指定的目录，文件名取表单字段 `file` 的文件名（只取最后一段）。主控先把文件完整接收并计算 SHA-256，再转发给节点。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- 只接收第一个名为 `file` 的字段，其他字段忽略。\n- **同名文件会被覆盖**；目标同名项是目录时返回 `400 is_directory`。\n- 目标目录必须已存在。\n- 单个文件上限为该节点的 `max_upload_bytes`（见列目录接口），超过返回 `413 upload_too_large`。\n- 大文件耗时较长，请设置足够长的客户端超时；网页面板在节点支持时改用直传（`upload-direct`）。\n- 实例已到期（`expired` 或已过到期时间）时返回 `409 instance_expired`。",
        "tags": [
          "files"
        ],
        "x-scope": "write",
        "x-long-running": true,
        "x-cli": "ocent file upload 42 ./EssentialsX.jar /plugins",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          },
          {
            "name": "path",
            "in": "query",
            "required": false,
            "description": "目标目录，默认 `/`",
            "schema": {
              "type": "string"
            },
            "example": "/plugins"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "要上传的文件；文件名即目标文件名"
                  }
                }
              },
              "encoding": {
                "file": {
                  "contentType": "application/octet-stream"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "上传完成",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileUploadResult"
                },
                "example": {
                  "message": "文件已上传",
                  "path": "/plugins/EssentialsX.jar",
                  "size": 1048576
                }
              }
            }
          },
          "400": {
            "description": "缺少文件、文件名无效、路径无效或表单格式错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "请选择要上传的文件",
                  "code": "missing_file"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限（`insufficient_scope`），或节点上的文件没有访问权限（`permission_denied`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "API 密钥缺少 write 权限",
                  "code": "insufficient_scope",
                  "required_scope": "write"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在（或不属于当前用户），或目标文件/目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件或目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "实例已到期，文件写操作被拒绝（读取与下载仍可用）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例已到期，请先续费",
                  "code": "instance_expired"
                }
              }
            }
          },
          "413": {
            "description": "文件超过节点上传上限。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "单个文件不能超过 5 GB",
                  "code": "upload_too_large"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "missing_file",
            "description": "表单中没有 `file` 字段"
          },
          {
            "status": 400,
            "code": "invalid_filename",
            "description": "文件名为空、`.` 或 `..`"
          },
          {
            "status": 400,
            "code": "upload_failed",
            "description": "上传中断或 multipart 格式无效"
          },
          {
            "status": 400,
            "code": "is_directory",
            "description": "目标同名项是目录"
          },
          {
            "status": 413,
            "code": "upload_too_large",
            "description": "超过节点允许的单个文件大小"
          },
          {
            "status": 400,
            "code": "invalid_path",
            "description": "路径为空（该接口要求非根路径时）、含 `..` 或 NUL"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或文件/目录不存在"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "操作超时，可能已部分完成"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期，写操作被拒绝"
          }
        ]
      }
    },
    "/instances/{id}/files/upload-direct": {
      "post": {
        "operationId": "createDirectUploadTicket",
        "summary": "申请直传地址",
        "description": "为一个文件签发一次性直传地址，客户端随后直接把文件发给节点，不经过主控中转。普通脚本直接用 `POST /instances/{id}/files/upload` 即可。\n\n使用方式：\n\n1. 调用本接口，传入目标目录 `path`、文件名 `name` 与准确的字节数 `size`。\n2. 在 `expires_at`（签发后 10 分钟）之前，对返回的 `url` 发送 `PUT`，请求体为文件原始字节，**不带** `Authorization` 头。字节数必须与 `size` 一致。\n3. 节点成功时返回 `200 {\"path\":\"...\",\"size\":...}`。\n\n- 地址只能使用一次（重复使用返回节点的 `409 token_used`），过期返回 `401 token_expired`，字节数不符返回 `400 size_mismatch`。\n- **同名文件会被覆盖**。\n- 节点未配置直传地址时返回 `409 direct_upload_unavailable`。\n- 签发即视为一次写操作；实例已到期（`expired` 或已过到期时间）时返回 `409 instance_expired`。",
        "tags": [
          "files"
        ],
        "x-scope": "write",
        "x-cli": "ocent api POST /instances/42/files/upload-direct --data '{\"path\":\"/plugins\",\"name\":\"EssentialsX.jar\",\"size\":1048576}' --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FileDirectUploadRequest"
              },
              "example": {
                "path": "/plugins",
                "name": "EssentialsX.jar",
                "size": 1048576
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "直传地址",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileDirectUploadTicket"
                },
                "example": {
                  "url": "https://node1.example.com:8443/direct-upload?token=eyJub2RlIjoiMSJ9.xxxxxxxx",
                  "path": "/plugins/EssentialsX.jar",
                  "size": 1048576,
                  "expires_at": "2026-11-24T09:10:00Z"
                }
              }
            }
          },
          "400": {
            "description": "参数格式无效、路径无效或文件名无效。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件名无效",
                  "code": "invalid_filename"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限（`insufficient_scope`），或节点上的文件没有访问权限（`permission_denied`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "API 密钥缺少 write 权限",
                  "code": "insufficient_scope",
                  "required_scope": "write"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在（或不属于当前用户），或目标文件/目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件或目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "实例已到期，或该节点不支持直传。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "该节点暂不支持直传",
                  "code": "direct_upload_unavailable"
                }
              }
            }
          },
          "413": {
            "description": "文件超过节点上传上限。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "单个文件不能超过 5 GB",
                  "code": "upload_too_large"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_input",
            "description": "请求体无法解析，或 `size` 为负数"
          },
          {
            "status": 400,
            "code": "invalid_path",
            "description": "目录路径含 `..` 或 NUL"
          },
          {
            "status": 400,
            "code": "invalid_filename",
            "description": "文件名为空、`.`、`..`，或含 `/`、`\\`、NUL"
          },
          {
            "status": 413,
            "code": "upload_too_large",
            "description": "`size` 超过节点允许的单个文件大小"
          },
          {
            "status": 409,
            "code": "direct_upload_unavailable",
            "description": "节点未配置直传地址"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在"
          }
        ]
      }
    },
    "/instances/{id}/files/directory": {
      "post": {
        "operationId": "createDirectory",
        "summary": "创建目录",
        "description": "创建一个目录。上级目录必须已存在（不会逐级创建）；同名文件或目录已存在时返回 `409 already_exists`。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- 实例已到期（`expired` 或已过到期时间）时返回 `409 instance_expired`。",
        "tags": [
          "files"
        ],
        "x-scope": "write",
        "x-cli": "ocent file mkdir 42 /backups",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FilePathRequest"
              },
              "example": {
                "path": "/backups"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "目录已创建",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileDirectoryResult"
                },
                "example": {
                  "message": "目录已创建",
                  "path": "/backups"
                }
              }
            }
          },
          "400": {
            "description": "缺少路径或路径无效。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "目录路径无效",
                  "code": "invalid_path"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限（`insufficient_scope`），或节点上的文件没有访问权限（`permission_denied`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "API 密钥缺少 write 权限",
                  "code": "insufficient_scope",
                  "required_scope": "write"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在（或不属于当前用户），或目标文件/目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件或目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "同名项已存在，或实例已到期。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "目标文件已存在",
                  "code": "already_exists"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_path",
            "description": "缺少 `path`、路径为 `/` 或含 `..`"
          },
          {
            "status": 409,
            "code": "already_exists",
            "description": "同名文件或目录已存在"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在或上级目录不存在"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "操作超时，可能已部分完成"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期，写操作被拒绝"
          }
        ]
      }
    },
    "/instances/{id}/files/rename": {
      "post": {
        "operationId": "renameFile",
        "summary": "重命名或移动单个文件",
        "description": "把 `from` 重命名为 `to`（可跨目录，相当于 `mv`）。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- **`to` 已存在且是文件时会被直接覆盖**；`to` 是非空目录时返回 `409 already_exists`。调用前如需避免覆盖，请先列目录确认。\n- `to` 的上级目录必须已存在。\n- `from`、`to` 都不能是 `/`。\n- 批量移动且不覆盖同名项请用 `POST /instances/{id}/files/move`。\n- 实例已到期（`expired` 或已过到期时间）时返回 `409 instance_expired`。",
        "tags": [
          "files"
        ],
        "x-scope": "write",
        "x-danger": "destructive",
        "x-cli": "ocent file rename 42 /old.txt /new.txt",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FileRenameRequest"
              },
              "example": {
                "from": "/world",
                "to": "/world_backup"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "已重命名",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessageResponse"
                },
                "example": {
                  "message": "已重命名"
                }
              }
            }
          },
          "400": {
            "description": "缺少路径或路径无效。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "请输入原路径和新路径",
                  "code": "invalid_path"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限（`insufficient_scope`），或节点上的文件没有访问权限（`permission_denied`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "API 密钥缺少 write 权限",
                  "code": "insufficient_scope",
                  "required_scope": "write"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在（或不属于当前用户），或目标文件/目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件或目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "目标是非空目录，或实例已到期。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "目标文件已存在",
                  "code": "already_exists"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_path",
            "description": "缺少 `from`/`to`、路径为 `/` 或含 `..`"
          },
          {
            "status": 409,
            "code": "already_exists",
            "description": "目标是已存在的非空目录"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或文件/目录不存在"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "操作超时，可能已部分完成"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期，写操作被拒绝"
          }
        ]
      }
    },
    "/instances/{id}/files/move": {
      "post": {
        "operationId": "moveFiles",
        "summary": "批量移动到目录",
        "description": "把多个文件或目录移动到一个已存在的目录 `destination` 中，保留原名。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- **不覆盖**：目标目录中已有同名项的条目会被跳过，而不是整批失败。跳过的条目在 `skipped` 中列出，`code` 为：\n  - `same_location`：已在目标目录中\n  - `target_exists`：目标目录中已有同名项\n  - `into_itself`：不能把目录移进它自己或其子目录\n  - `not_found`：源文件不存在\n  - `failed`：其他失败（如节点上实例丢失、目标目录在中途被删除，此后的条目全部记为失败）\n- `paths` 为 1–1000 项，重复项会去重；不能包含 `/`。\n- 同名检查与实际移动之间不是原子的：游戏进程或 SFTP 在这期间新建的同名文件仍可能被覆盖。\n- 单批最长约 60 秒。\n- 实例已到期（`expired` 或已过到期时间）时返回 `409 instance_expired`。",
        "tags": [
          "files"
        ],
        "x-scope": "write",
        "x-cli": "ocent file move 42 /old /a.txt /logs",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FileMoveRequest"
              },
              "example": {
                "paths": [
                  "/a.txt",
                  "/logs"
                ],
                "destination": "/old"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "移动结果（可能部分跳过）",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileMoveResult"
                },
                "example": {
                  "moved": [
                    {
                      "from": "/a.txt",
                      "to": "/old/a.txt"
                    }
                  ],
                  "skipped": [
                    {
                      "path": "/logs",
                      "reason": "目标目录中已存在同名文件或目录",
                      "code": "target_exists"
                    }
                  ],
                  "message": "已移动 1 项，跳过 1 项"
                }
              }
            }
          },
          "400": {
            "description": "参数无效、目标目录无效或不是目录。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "请选择目标目录",
                  "code": "invalid_path"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限（`insufficient_scope`），或节点上的文件没有访问权限（`permission_denied`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "API 密钥缺少 write 权限",
                  "code": "insufficient_scope",
                  "required_scope": "write"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在，或目标目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "目标目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "实例已到期，文件写操作被拒绝（读取与下载仍可用）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例已到期，请先续费",
                  "code": "instance_expired"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_request",
            "description": "请求体无法解析"
          },
          {
            "status": 400,
            "code": "invalid_files",
            "description": "`paths` 为空或超过 1000 项"
          },
          {
            "status": 400,
            "code": "invalid_path",
            "description": "`destination` 为空或无效，或 `paths` 中有空路径、`/` 或含 `..`"
          },
          {
            "status": 400,
            "code": "not_directory",
            "description": "`destination` 不是目录"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或目标目录不存在"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "操作超时，可能已部分完成"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期，写操作被拒绝"
          }
        ]
      }
    },
    "/instances/{id}/files/delete": {
      "post": {
        "operationId": "deleteFiles",
        "summary": "批量删除",
        "description": "一次删除 `root` 目录下的多个直接子项；目录连同其内容一起删除，**不可恢复**。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- `files` 是 `root` 下的名称（单段，不含 `/`、`\\`，不能是 `.` 或 `..`），1–1000 项，重复项会去重。\n- 所有名称先校验，再开始删除；已不存在的名称会被忽略，`deleted` 是实际删除的数量。\n- `root` 省略时为 `/`。\n- 最长约 5 分钟。\n- 实例已到期（`expired` 或已过到期时间）时返回 `409 instance_expired`。",
        "tags": [
          "files"
        ],
        "x-scope": "write",
        "x-danger": "destructive",
        "x-cli": "ocent file rm 42 /logs/a.log /logs/b.log --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FileBatchRequest"
              },
              "example": {
                "root": "/logs",
                "files": [
                  "a.log",
                  "b.log"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "已删除",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileDeleteResult"
                },
                "example": {
                  "message": "已删除",
                  "deleted": 2
                }
              }
            }
          },
          "400": {
            "description": "参数无效。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "请选择要删除的文件",
                  "code": "invalid_files"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限（`insufficient_scope`），或节点上的文件没有访问权限（`permission_denied`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "API 密钥缺少 write 权限",
                  "code": "insufficient_scope",
                  "required_scope": "write"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在（或不属于当前用户），或目标文件/目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件或目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "实例已到期，文件写操作被拒绝（读取与下载仍可用）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例已到期，请先续费",
                  "code": "instance_expired"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_request",
            "description": "请求体无法解析"
          },
          {
            "status": 400,
            "code": "invalid_files",
            "description": "`files` 为空、超过 1000 项或含无效名称"
          },
          {
            "status": 400,
            "code": "invalid_path",
            "description": "`root` 含 `..` 或 NUL"
          },
          {
            "status": 400,
            "code": "not_directory",
            "description": "`root` 不是目录"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或文件/目录不存在"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "操作超时，可能已部分完成"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期，写操作被拒绝"
          }
        ]
      }
    },
    "/instances/{id}/files/compress": {
      "post": {
        "operationId": "compressFiles",
        "summary": "压缩文件",
        "description": "把 `root` 目录下的若干直接子项打包为 `root/name`，返回压缩包的文件条目。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- `format` 只支持 `zip` 或 `tar.gz`；`name` 是单段文件名，扩展名由调用方自行决定。\n- `files` 规则同批量删除：`root` 下的名称，1–1000 项。\n- `root` 省略时为 `/`。\n- 同名压缩包已存在时返回 `409 already_exists`，不会覆盖。\n- 压缩包大小受实例剩余磁盘额度限制，超过时中止并返回 `413 too_large`，不留下压缩包。\n- 最长 30 分钟，超时中止且不生成压缩包。\n- 实例已到期（`expired` 或已过到期时间）时返回 `409 instance_expired`。",
        "tags": [
          "files"
        ],
        "x-scope": "write",
        "x-long-running": true,
        "x-cli": "ocent file compress 42 --name backup.zip --root / --format zip world server.properties",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FileCompressRequest"
              },
              "example": {
                "root": "/",
                "files": [
                  "world",
                  "server.properties"
                ],
                "name": "backup.zip",
                "format": "zip"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "压缩包的文件条目",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileEntry"
                },
                "example": {
                  "name": "backup.zip",
                  "path": "/backup.zip",
                  "is_dir": false,
                  "size": 73400320,
                  "modified_at": "2026-11-24T09:05:00Z",
                  "mode": "-rw-r-----"
                }
              }
            }
          },
          "400": {
            "description": "参数无效。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "压缩格式只支持 zip 或 tar.gz",
                  "code": "invalid_format"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限（`insufficient_scope`），或节点上的文件没有访问权限（`permission_denied`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "API 密钥缺少 write 权限",
                  "code": "insufficient_scope",
                  "required_scope": "write"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在（或不属于当前用户），或目标文件/目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件或目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "同名压缩包已存在，或实例已到期。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "同名压缩包已存在，请换一个文件名",
                  "code": "already_exists"
                }
              }
            }
          },
          "413": {
            "description": "超过实例剩余磁盘空间。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "压缩包超过实例剩余磁盘空间，已中止，未生成压缩包",
                  "code": "too_large"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_request",
            "description": "请求体无法解析"
          },
          {
            "status": 400,
            "code": "invalid_path",
            "description": "`root` 含 `..` 或 NUL"
          },
          {
            "status": 400,
            "code": "invalid_files",
            "description": "`files` 为空、超过 1000 项或含无效名称"
          },
          {
            "status": 400,
            "code": "invalid_filename",
            "description": "`name` 为空或不是单段文件名"
          },
          {
            "status": 400,
            "code": "invalid_format",
            "description": "`format` 不是 `zip` 或 `tar.gz`"
          },
          {
            "status": 409,
            "code": "already_exists",
            "description": "同名压缩包已存在"
          },
          {
            "status": 413,
            "code": "too_large",
            "description": "超过实例剩余磁盘额度，未生成压缩包"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "超过 30 分钟已中止，未生成压缩包"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或文件/目录不存在"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期，写操作被拒绝"
          }
        ]
      }
    },
    "/instances/{id}/files/decompress": {
      "post": {
        "operationId": "decompressFile",
        "summary": "解压文件",
        "description": "把压缩包解压到一个已存在的目录，返回写出的文件数、目录数、字节数与跳过数。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- 支持 `.zip`、`.tar`、`.tar.gz`、`.tgz`（按扩展名判断，大小写不敏感），其他格式返回 `415 unsupported_archive`；损坏、加密或无法读取的压缩包返回 `400 invalid_archive`。\n- `destination` 省略或为空时解压到压缩包所在目录。\n- **目标目录中的同名文件会被覆盖**；符号链接、设备文件以及与已有文件/目录类型冲突的条目会被跳过，计入 `skipped`。\n- 解压总量受实例剩余磁盘额度限制（实例未设置磁盘额度时按节点的单次上限），超过时中止并返回 `413 too_large`，此时**可能已写出部分文件**，请检查后清理。\n- 最长 30 分钟，超时中止（可能已部分解压）。\n- 实例已到期（`expired` 或已过到期时间）时返回 `409 instance_expired`。",
        "tags": [
          "files"
        ],
        "x-scope": "write",
        "x-long-running": true,
        "x-cli": "ocent file decompress 42 /backup.zip --dest /restore",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FileDecompressRequest"
              },
              "example": {
                "path": "/backup.zip",
                "destination": "/restore"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "解压统计",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileDecompressResult"
                },
                "example": {
                  "files": 1824,
                  "directories": 96,
                  "bytes": 215482368,
                  "skipped": 0
                }
              }
            }
          },
          "400": {
            "description": "参数无效或压缩包损坏。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "压缩包已损坏、加密或无法读取",
                  "code": "invalid_archive"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限（`insufficient_scope`），或节点上的文件没有访问权限（`permission_denied`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "API 密钥缺少 write 权限",
                  "code": "insufficient_scope",
                  "required_scope": "write"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在，或压缩包/解压目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "压缩包或解压目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "实例已到期，文件写操作被拒绝（读取与下载仍可用）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例已到期，请先续费",
                  "code": "instance_expired"
                }
              }
            }
          },
          "413": {
            "description": "超过实例剩余磁盘空间或条目数限制。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "解压内容超过实例剩余磁盘空间或条目数限制，已中止；可能已有部分文件写出，请检查后清理",
                  "code": "too_large"
                }
              }
            }
          },
          "415": {
            "description": "不支持的压缩格式。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "不支持的压缩格式，仅支持 zip、tar、tar.gz、tgz",
                  "code": "unsupported_archive"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_path",
            "description": "缺少 `path`、路径为 `/`、含 `..`，或 `destination` 无效"
          },
          {
            "status": 400,
            "code": "invalid_archive",
            "description": "压缩包已损坏、加密或无法读取"
          },
          {
            "status": 400,
            "code": "not_directory",
            "description": "`destination` 不是目录"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或压缩包/解压目录不存在"
          },
          {
            "status": 413,
            "code": "too_large",
            "description": "超过剩余磁盘额度或条目数限制；可能已部分写出"
          },
          {
            "status": 415,
            "code": "unsupported_archive",
            "description": "扩展名不是 zip、tar、tar.gz、tgz"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "超过 30 分钟已中止，可能已部分解压"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期，写操作被拒绝"
          }
        ]
      }
    },
    "/instances/{id}/files/chmod": {
      "post": {
        "operationId": "chmodFile",
        "summary": "修改权限",
        "description": "修改一个文件或目录的权限位；`recursive` 为 `true` 时同时修改目录内的全部内容。\n\n路径是实例数据目录内的虚拟绝对路径，以 `/` 开头（`/` 即数据目录根）；`\\` 视为 `/`，含 `..` 段的路径返回 `400 invalid_path`。\n\n- `mode` 是三位八进制数 `000`–`777`，也接受带前导 0 的四位写法（如 `0755`）；只能设置 rwx 九位，不会设置 setuid、setgid 或 sticky。\n- 不能修改根目录 `/`（`400 invalid_path`）；目标是符号链接时返回 `400 is_symlink`。\n- 递归修改超过 10 万项时返回 `413 too_large`，请分批或改用 SFTP。\n- 返回的 `changed` 是实际修改的条目数，`mode` 是规范化后的三位值。\n- 最长约 5 分钟。\n- 实例已到期（`expired` 或已过到期时间）时返回 `409 instance_expired`。",
        "tags": [
          "files"
        ],
        "x-scope": "write",
        "x-cli": "ocent file chmod 42 /start.sh 755",
        "parameters": [
          {
            "$ref": "#/components/parameters/InstanceId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FileChmodRequest"
              },
              "example": {
                "path": "/start.sh",
                "mode": "755",
                "recursive": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "权限已修改",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FileChmodResult"
                },
                "example": {
                  "message": "权限已修改",
                  "changed": 1,
                  "mode": "755"
                }
              }
            }
          },
          "400": {
            "description": "参数无效。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "权限值无效，请输入 000-777 的三位八进制数",
                  "code": "invalid_mode"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限（`insufficient_scope`），或节点上的文件没有访问权限（`permission_denied`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "API 密钥缺少 write 权限",
                  "code": "insufficient_scope",
                  "required_scope": "write"
                }
              }
            }
          },
          "404": {
            "description": "实例不存在（或不属于当前用户），或目标文件/目录不存在。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件或目录不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "实例已到期，文件写操作被拒绝（读取与下载仍可用）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例已到期，请先续费",
                  "code": "instance_expired"
                }
              }
            }
          },
          "413": {
            "description": "递归修改的条目过多。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件过多（超过 10 万项），请分批修改或使用 SFTP",
                  "code": "too_large"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "节点 Agent 不可达或返回未识别的错误。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作失败",
                  "code": "agent_file_error"
                }
              }
            }
          },
          "504": {
            "description": "文件操作超时；操作可能已部分完成，请刷新目录查看结果。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "文件操作超时，请稍后刷新查看结果",
                  "code": "timeout"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_request",
            "description": "请求体无法解析"
          },
          {
            "status": 400,
            "code": "invalid_path",
            "description": "路径为空、为 `/` 或含 `..`"
          },
          {
            "status": 400,
            "code": "invalid_mode",
            "description": "`mode` 不是 000–777 的三位八进制数"
          },
          {
            "status": 400,
            "code": "is_symlink",
            "description": "目标是符号链接"
          },
          {
            "status": 413,
            "code": "too_large",
            "description": "递归修改超过 10 万项"
          },
          {
            "status": 403,
            "code": "permission_denied",
            "description": "节点上该文件没有访问权限"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "实例不存在，或文件/目录不存在"
          },
          {
            "status": 502,
            "code": "agent_file_error",
            "description": "节点 Agent 不可达或返回未识别的错误"
          },
          {
            "status": 504,
            "code": "timeout",
            "description": "操作超时，可能已部分完成"
          },
          {
            "status": 409,
            "code": "instance_expired",
            "description": "实例已到期，写操作被拒绝"
          }
        ]
      }
    },
    "/vps": {
      "get": {
        "operationId": "listVps",
        "summary": "列出云服务器",
        "description": "列出当前用户的云服务器，按 ID 倒序，不分页。\n\n- 默认不含已释放（`terminated`）的机器；`all=1` 时包含。\n- 创建失败且已退款的机器（`status` 为 `error`、`has_machine` 为 `false`）会一直显示，直到用户释放它。\n- 处于过渡状态（`provisioning`、`starting`、`stopping`、`rebooting`、`reinstalling`）且超过 15 秒未同步的机器，会先向云服务商刷新一次状态再返回。",
        "tags": [
          "vps"
        ],
        "x-scope": "read",
        "x-cli": "ocent vps list --all",
        "parameters": [
          {
            "name": "all",
            "in": "query",
            "required": false,
            "description": "为 `1` 时包含已释放的云服务器",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            },
            "example": "1"
          }
        ],
        "responses": {
          "200": {
            "description": "云服务器列表",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSList"
                },
                "example": {
                  "items": [
                    {
                      "id": 7,
                      "name": "my-vps",
                      "provider": "ucloud",
                      "status": "running",
                      "status_detail": "",
                      "last_error": "",
                      "region": "cn-sh2",
                      "region_name": "上海",
                      "plan_id": 2,
                      "plan_name": "2 核 2G",
                      "bundle_id": "ulh.c2m2s40b30t800",
                      "cpu_cores": 2,
                      "memory_mb": 2048,
                      "disk_gb": 40,
                      "bandwidth_mbps": 30,
                      "traffic_gb": 800,
                      "traffic_used_gb": 12,
                      "traffic_total_gb": 800,
                      "monthly_price_cents": 4900,
                      "renew_months": 1,
                      "renew_price_cents": 4900,
                      "image_name": "Ubuntu 24.04",
                      "os_type": "Linux",
                      "public_ip": "203.0.113.10",
                      "username": "root",
                      "has_machine": true,
                      "expires_at": "2026-12-24T08:00:00Z",
                      "auto_renew": false,
                      "expired_at": null,
                      "release_at": null,
                      "terminated_at": null,
                      "created_at": "2026-11-24T08:00:00Z",
                      "updated_at": "2026-11-24T08:03:00Z"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      },
      "post": {
        "operationId": "createVps",
        "summary": "购买云服务器",
        "description": "从余额扣费购买一台云服务器。首期费用（`months` 个月，按当前折扣计价）在同一事务中扣款并生成订单，然后请求云服务商创建机器；请求最长约 1 分钟。\n\n- 套餐、镜像与付费周期见 `GET /vps/store`；镜像必须与套餐属于同一站点和地域。\n- `months` 为 1、3 或 12，默认 1；所选周期同时成为该机器的自动续费周期。价格 = 月价 × 月数 × 该周期的 `discount_percent` ÷ 100（向下取整到分，月付不打折）。\n- **建议带 `expected_price_cents`**：实际价格与之不同时返回 `409 price_changed`（带 `price_cents`），且不扣费。\n- `auto_renew` **默认为 `true`**：到期时自动从余额续费。\n- `password` 留空时由平台生成，并只在本次响应的 `password` 字段返回一次；也可之后用 `GET /vps/{id}/password` 读取。\n- 部分站点要求账户已完成实名认证（`403 realname_required` / `realname_unavailable`），实名只能在网页面板完成。\n- 10 秒内以同一名称重复购买同一套餐会返回 `409 vps_duplicate`。\n- 云服务商明确失败时自动全额退款并返回 `502 vps_provider_error`；结果不确定时仍返回 `201`，机器保持 `provisioning`，平台后台继续确认，约 10 分钟内仍未创建成功会自动退款。\n- 创建通常需要 1–3 分钟，请轮询 `GET /vps/{id}` 直到 `status` 变为 `running`。\n- 客户端超时或断线时扣费可能已经发生，请先用 `GET /vps` 或钱包流水核对，不要直接重发。",
        "tags": [
          "vps"
        ],
        "x-scope": "billing",
        "x-danger": "billing",
        "x-rate-limit": "10 次/分钟/用户",
        "x-cli": "ocent vps create --plan 2 --image 5 --name my-vps --months 1 --expected-price 4900 --yes",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VPSCreateRequest"
              },
              "example": {
                "plan_id": 2,
                "image_id": 5,
                "name": "my-vps",
                "months": 1,
                "auto_renew": false,
                "expected_price_cents": 4900
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "已扣款，机器创建中",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSCreateResult"
                },
                "example": {
                  "vps": {
                    "id": 7,
                    "name": "my-vps",
                    "provider": "ucloud",
                    "status": "provisioning",
                    "status_detail": "",
                    "last_error": "",
                    "region": "cn-sh2",
                    "region_name": "上海",
                    "plan_id": 2,
                    "plan_name": "2 核 2G",
                    "bundle_id": "ulh.c2m2s40b30t800",
                    "cpu_cores": 2,
                    "memory_mb": 2048,
                    "disk_gb": 40,
                    "bandwidth_mbps": 30,
                    "traffic_gb": 800,
                    "traffic_used_gb": 12,
                    "traffic_total_gb": 800,
                    "monthly_price_cents": 4900,
                    "renew_months": 1,
                    "renew_price_cents": 4900,
                    "image_name": "Ubuntu 24.04",
                    "os_type": "Linux",
                    "public_ip": "",
                    "username": "root",
                    "has_machine": true,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": false,
                    "expired_at": null,
                    "release_at": null,
                    "terminated_at": null,
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:00:01Z"
                  },
                  "order": {
                    "id": 1024,
                    "kind": "vps_purchase",
                    "amount_cents": 4900,
                    "status": "paid",
                    "created_at": "2026-11-24T08:00:00Z"
                  },
                  "message": "云服务器创建中，通常需要 1-3 分钟",
                  "password": "Xk7#mP2q-Lw9^zR4"
                }
              }
            }
          },
          "400": {
            "description": "参数无效、套餐或镜像不可用。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "所选套餐不存在或已下架",
                  "code": "invalid_plan"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientBalance"
          },
          "403": {
            "description": "密钥缺少 billing 权限，或该站点需要先完成实名认证。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "购买云服务器前请先完成实名认证",
                  "code": "realname_required"
                }
              }
            }
          },
          "409": {
            "description": "重复提交，或价格已变化（带 `price_cents`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "价格已变化，请确认新的价格后重试",
                  "code": "price_changed",
                  "price_cents": 4900
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "云服务商创建失败，费用已自动退回。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务商返回错误：库存不足",
                  "code": "vps_provider_error"
                }
              }
            }
          },
          "503": {
            "description": "平台未开启云服务器功能，或该云服务器所属站点未配置。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器功能未开启",
                  "code": "vps_disabled"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_input",
            "description": "请求体无法解析，或缺少 `plan_id` / `image_id`"
          },
          {
            "status": 400,
            "code": "invalid_months",
            "description": "`months` 不是 1、3、12"
          },
          {
            "status": 400,
            "code": "invalid_name",
            "description": "`name` 去除首尾空白后为空、超过 60 个字符或含控制字符"
          },
          {
            "status": 400,
            "code": "invalid_password",
            "description": "密码不符合规则"
          },
          {
            "status": 400,
            "code": "invalid_plan",
            "description": "套餐不存在或已下架"
          },
          {
            "status": 400,
            "code": "invalid_image",
            "description": "镜像不可用或与套餐不在同一站点/地域"
          },
          {
            "status": 402,
            "code": "insufficient_balance",
            "description": "余额不足"
          },
          {
            "status": 403,
            "code": "realname_required",
            "description": "该站点要求先完成实名认证"
          },
          {
            "status": 403,
            "code": "realname_unavailable",
            "description": "该站点要求实名，但平台暂未开放实名认证"
          },
          {
            "status": 409,
            "code": "price_changed",
            "description": "实际价格与 `expected_price_cents` 不符，未扣费；响应带 `price_cents`"
          },
          {
            "status": 409,
            "code": "vps_duplicate",
            "description": "10 秒内重复提交相同的购买"
          },
          {
            "status": 502,
            "code": "vps_provider_error",
            "description": "云服务商明确失败（已退款），或创建超时已退款"
          },
          {
            "status": 503,
            "code": "vps_disabled",
            "description": "平台未开启云服务器，或该套餐所属站点未配置"
          }
        ]
      }
    },
    "/vps/{id}": {
      "get": {
        "operationId": "getVps",
        "summary": "云服务器详情",
        "description": "返回一台云服务器。距上次与云服务商同步超过 15 秒时会先刷新状态、公网 IP 与流量；刷新失败时返回数据库中的数据，不报错。",
        "tags": [
          "vps"
        ],
        "x-scope": "read",
        "x-cli": "ocent vps get 7",
        "parameters": [
          {
            "$ref": "#/components/parameters/VpsId"
          }
        ],
        "responses": {
          "200": {
            "description": "云服务器",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSResponse"
                },
                "example": {
                  "vps": {
                    "id": 7,
                    "name": "my-vps",
                    "provider": "ucloud",
                    "status": "running",
                    "status_detail": "",
                    "last_error": "",
                    "region": "cn-sh2",
                    "region_name": "上海",
                    "plan_id": 2,
                    "plan_name": "2 核 2G",
                    "bundle_id": "ulh.c2m2s40b30t800",
                    "cpu_cores": 2,
                    "memory_mb": 2048,
                    "disk_gb": 40,
                    "bandwidth_mbps": 30,
                    "traffic_gb": 800,
                    "traffic_used_gb": 12,
                    "traffic_total_gb": 800,
                    "monthly_price_cents": 4900,
                    "renew_months": 1,
                    "renew_price_cents": 4900,
                    "image_name": "Ubuntu 24.04",
                    "os_type": "Linux",
                    "public_ip": "203.0.113.10",
                    "username": "root",
                    "has_machine": true,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": false,
                    "expired_at": null,
                    "release_at": null,
                    "terminated_at": null,
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:03:00Z"
                  }
                }
              }
            }
          },
          "400": {
            "description": "路径 ID 不是正整数。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "无效的资源编号",
                  "code": "invalid_id"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "云服务器不存在，或不属于当前用户。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-error-codes": [
          {
            "status": 404,
            "code": "not_found",
            "description": "云服务器不存在或不属于当前用户"
          }
        ]
      },
      "patch": {
        "operationId": "updateVps",
        "summary": "修改名称或自动续费",
        "description": "修改云服务器的名称或自动续费开关；两个字段都可选，只改传入的字段。\n\n- `name` 去除首尾空白后 1–60 个字符，不能含控制字符。\n- 已释放的机器返回 `409 vps_terminated`。\n- 把 `auto_renew` 从关闭改为开启时，API 密钥还需要 **billing** 权限（到期会自动从余额扣费），否则返回 `403 insufficient_scope`；关闭不需要。",
        "tags": [
          "vps"
        ],
        "x-scope": "write",
        "x-scope-note": "把 `auto_renew` 从关闭改为开启另需 billing",
        "x-cli": "ocent api PATCH /vps/7 --data '{\"name\":\"web-1\",\"auto_renew\":false}' --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/VpsId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VPSUpdateRequest"
              },
              "example": {
                "name": "web-1",
                "auto_renew": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "修改后的云服务器",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSResponse"
                },
                "example": {
                  "vps": {
                    "id": 7,
                    "name": "web-1",
                    "provider": "ucloud",
                    "status": "running",
                    "status_detail": "",
                    "last_error": "",
                    "region": "cn-sh2",
                    "region_name": "上海",
                    "plan_id": 2,
                    "plan_name": "2 核 2G",
                    "bundle_id": "ulh.c2m2s40b30t800",
                    "cpu_cores": 2,
                    "memory_mb": 2048,
                    "disk_gb": 40,
                    "bandwidth_mbps": 30,
                    "traffic_gb": 800,
                    "traffic_used_gb": 12,
                    "traffic_total_gb": 800,
                    "monthly_price_cents": 4900,
                    "renew_months": 1,
                    "renew_price_cents": 4900,
                    "image_name": "Ubuntu 24.04",
                    "os_type": "Linux",
                    "public_ip": "203.0.113.10",
                    "username": "root",
                    "has_machine": true,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": false,
                    "expired_at": null,
                    "release_at": null,
                    "terminated_at": null,
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:03:00Z"
                  }
                }
              }
            }
          },
          "400": {
            "description": "参数无效。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "实例名称长度需为 1-60 个字符",
                  "code": "invalid_name"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "description": "密钥缺少权限；开启自动续费需要 billing。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "开启自动续费后到期会自动从余额扣费，API 密钥缺少 billing 权限",
                  "code": "insufficient_scope",
                  "required_scope": "billing"
                }
              }
            }
          },
          "404": {
            "description": "云服务器不存在，或不属于当前用户。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "云服务器已释放。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器已释放",
                  "code": "vps_terminated"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "503": {
            "description": "平台未开启云服务器功能，或该云服务器所属站点未配置。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器功能未开启",
                  "code": "vps_disabled"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_input",
            "description": "请求体无法解析"
          },
          {
            "status": 400,
            "code": "invalid_name",
            "description": "名称为空、超过 60 个字符或含控制字符"
          },
          {
            "status": 403,
            "code": "insufficient_scope",
            "description": "开启自动续费但密钥没有 billing（`required_scope` 为 `billing`）"
          },
          {
            "status": 409,
            "code": "vps_terminated",
            "description": "已释放"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "云服务器不存在或不属于当前用户"
          },
          {
            "status": 503,
            "code": "vps_disabled",
            "description": "平台未开启云服务器，或该机器所属站点未配置"
          }
        ]
      },
      "delete": {
        "operationId": "releaseVps",
        "summary": "释放云服务器",
        "description": "**立即释放**云服务器：在云服务商处删除机器与全部数据，**不可恢复**，并按规则把退款计入余额。\n\n- 运行中的机器会先强制断电再删除，整个过程可能需要一两分钟。\n- 退款只针对首期购买价：购买后 3 天内退 80%，7 天内 50%，10 天内 20%，之后不退；续费金额不退。请先用 `GET /vps/{id}/release-refund` 预估。\n- 创建失败、已退款的机器（`error` 且 `has_machine` 为 `false`）释放时只关闭记录，不再退款。\n- `provisioning` 返回 `409 vps_provisioning`，已释放返回 `409 vps_terminated`；其他状态（含 `expired`、`error`、`reinstalling`）都可以释放。\n- 云服务商删除失败时返回 `502 vps_provider_error`，机器不会被标记为已释放。",
        "tags": [
          "vps"
        ],
        "x-scope": "billing",
        "x-danger": "destructive",
        "x-long-running": true,
        "x-rate-limit": "60 次/分钟/用户（电源操作、重装、重置密码、释放合计）",
        "x-cli": "ocent vps release 7 --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/VpsId"
          }
        ],
        "responses": {
          "200": {
            "description": "已释放",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSReleaseResult"
                },
                "example": {
                  "message": "云服务器已释放，已退回 ¥39.20 到余额",
                  "refund_cents": 3920
                }
              }
            }
          },
          "400": {
            "description": "路径 ID 不是正整数。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "无效的资源编号",
                  "code": "invalid_id"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "云服务器不存在，或不属于当前用户。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "当前状态不能释放。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器正在创建中，请稍后再试",
                  "code": "vps_provisioning"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "云服务商返回错误；超时时结果未知，请稍后刷新查看。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务商返回错误：请求失败，请稍后重试",
                  "code": "vps_provider_error"
                }
              }
            }
          },
          "503": {
            "description": "平台未开启云服务器功能，或该云服务器所属站点未配置。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器功能未开启",
                  "code": "vps_disabled"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_id",
            "description": "路径 ID 不是正整数"
          },
          {
            "status": 409,
            "code": "vps_provisioning",
            "description": "正在创建中"
          },
          {
            "status": 409,
            "code": "vps_terminated",
            "description": "已释放"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "云服务器不存在或不属于当前用户"
          },
          {
            "status": 502,
            "code": "vps_provider_error",
            "description": "云服务商返回错误或超时（超时时结果未知）"
          },
          {
            "status": 503,
            "code": "vps_disabled",
            "description": "平台未开启云服务器，或该机器所属站点未配置"
          },
          {
            "status": 409,
            "code": "vps_error",
            "description": "状态未知，请稍后再试"
          }
        ]
      }
    },
    "/vps/{id}/actions": {
      "post": {
        "operationId": "vpsPowerAction",
        "summary": "开机、关机、重启或强制断电",
        "description": "对云服务器执行电源操作，成功后进入对应的过渡状态（`start` → `starting`，`stop`/`poweroff` → `stopping`，`reboot` → `rebooting`），需轮询 `GET /vps/{id}` 等待结束。\n\n- `action`：`start` 开机、`stop` 关机、`reboot` 重启、`poweroff` 强制断电（可能丢失未写盘数据）。大小写不敏感。\n- 允许的状态：`running`、`stopped`、`starting`、`stopping`、`rebooting`。其他状态返回 409：`reinstalling` → `vps_busy`，`provisioning` → `vps_provisioning`，`expired` → `vps_expired`，`error` → `vps_error`，`terminated` → `vps_terminated`。\n- 云服务商已接受指令、但机器状态在此期间被改变（如刚好到期）时返回 `409 vps_busy`，响应额外带当前的 `vps` 对象。",
        "tags": [
          "vps"
        ],
        "x-scope": "write",
        "x-rate-limit": "60 次/分钟/用户（电源操作、重装、重置密码、释放合计）",
        "x-cli": "ocent vps start 7",
        "parameters": [
          {
            "$ref": "#/components/parameters/VpsId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VPSActionRequest"
              },
              "example": {
                "action": "reboot"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "指令已发送",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSActionResult"
                },
                "example": {
                  "vps": {
                    "id": 7,
                    "name": "my-vps",
                    "provider": "ucloud",
                    "status": "rebooting",
                    "status_detail": "",
                    "last_error": "",
                    "region": "cn-sh2",
                    "region_name": "上海",
                    "plan_id": 2,
                    "plan_name": "2 核 2G",
                    "bundle_id": "ulh.c2m2s40b30t800",
                    "cpu_cores": 2,
                    "memory_mb": 2048,
                    "disk_gb": 40,
                    "bandwidth_mbps": 30,
                    "traffic_gb": 800,
                    "traffic_used_gb": 12,
                    "traffic_total_gb": 800,
                    "monthly_price_cents": 4900,
                    "renew_months": 1,
                    "renew_price_cents": 4900,
                    "image_name": "Ubuntu 24.04",
                    "os_type": "Linux",
                    "public_ip": "203.0.113.10",
                    "username": "root",
                    "has_machine": true,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": false,
                    "expired_at": null,
                    "release_at": null,
                    "terminated_at": null,
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:03:00Z"
                  },
                  "message": "已发送重启指令"
                }
              }
            }
          },
          "400": {
            "description": "`action` 无效。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "无效的云服务器操作",
                  "code": "invalid_action"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "云服务器不存在，或不属于当前用户。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "当前状态不允许该操作；或指令已发送但状态刚刚变化（带 `vps`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器已到期，请先续费",
                  "code": "vps_expired"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "云服务商返回错误；超时时结果未知，请稍后刷新查看。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务商返回错误：请求失败，请稍后重试",
                  "code": "vps_provider_error"
                }
              }
            }
          },
          "503": {
            "description": "平台未开启云服务器功能，或该云服务器所属站点未配置。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器功能未开启",
                  "code": "vps_disabled"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_action",
            "description": "`action` 缺失或不是 start / stop / reboot / poweroff"
          },
          {
            "status": 409,
            "code": "vps_busy",
            "description": "正在重装系统；或指令已被云服务商接受，但状态刚刚变化（响应带 `vps`）"
          },
          {
            "status": 409,
            "code": "vps_provisioning",
            "description": "正在创建中"
          },
          {
            "status": 409,
            "code": "vps_expired",
            "description": "已到期，请先续费"
          },
          {
            "status": 409,
            "code": "vps_error",
            "description": "状态异常"
          },
          {
            "status": 409,
            "code": "vps_terminated",
            "description": "已释放"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "云服务器不存在或不属于当前用户"
          },
          {
            "status": 502,
            "code": "vps_provider_error",
            "description": "云服务商返回错误或超时（超时时结果未知）"
          },
          {
            "status": 503,
            "code": "vps_disabled",
            "description": "平台未开启云服务器，或该机器所属站点未配置"
          }
        ]
      }
    },
    "/vps/{id}/reinstall": {
      "post": {
        "operationId": "reinstallVps",
        "summary": "重装系统",
        "description": "用平台提供的镜像重装系统，**清空系统盘全部数据**。接受后返回 `202`，机器进入 `reinstalling`，通常需要几分钟，请轮询 `GET /vps/{id}`。\n\n- `image_id` 来自 `GET /vps/{id}/images`，必须与机器同一站点和地域且仍在售。\n- `password` 留空时由平台生成，并只在本次响应的 `password` 字段返回；登录用户名随系统类型变为 `root`（Linux）或 `Administrator`（Windows）。\n- 除电源操作允许的状态外，`error` 状态且仍有机器（`has_machine` 为 `true`）时也可以重装。\n- 云服务商已接受但状态在此期间被改变时仍返回 `202`，`message` 会说明，机器保持当前状态。",
        "tags": [
          "vps"
        ],
        "x-scope": "write",
        "x-danger": "destructive",
        "x-rate-limit": "60 次/分钟/用户（电源操作、重装、重置密码、释放合计）",
        "x-cli": "ocent vps reinstall 7 --image 5 --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/VpsId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VPSReinstallRequest"
              },
              "example": {
                "image_id": 5,
                "password": ""
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "已开始重装",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSReinstallResult"
                },
                "example": {
                  "vps": {
                    "id": 7,
                    "name": "my-vps",
                    "provider": "ucloud",
                    "status": "reinstalling",
                    "status_detail": "正在重装系统",
                    "last_error": "",
                    "region": "cn-sh2",
                    "region_name": "上海",
                    "plan_id": 2,
                    "plan_name": "2 核 2G",
                    "bundle_id": "ulh.c2m2s40b30t800",
                    "cpu_cores": 2,
                    "memory_mb": 2048,
                    "disk_gb": 40,
                    "bandwidth_mbps": 30,
                    "traffic_gb": 800,
                    "traffic_used_gb": 12,
                    "traffic_total_gb": 800,
                    "monthly_price_cents": 4900,
                    "renew_months": 1,
                    "renew_price_cents": 4900,
                    "image_name": "Ubuntu 24.04",
                    "os_type": "Linux",
                    "public_ip": "203.0.113.10",
                    "username": "root",
                    "has_machine": true,
                    "expires_at": "2026-12-24T08:00:00Z",
                    "auto_renew": false,
                    "expired_at": null,
                    "release_at": null,
                    "terminated_at": null,
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:03:00Z"
                  },
                  "message": "已开始重装系统，通常需要几分钟",
                  "password": "Xk7#mP2q-Lw9^zR4"
                }
              }
            }
          },
          "400": {
            "description": "镜像不可用或密码不符合规则。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "所选系统镜像不可用，请重新选择",
                  "code": "invalid_image"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "云服务器不存在，或不属于当前用户。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "当前状态不允许重装。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器正在创建中，请稍后再试",
                  "code": "vps_provisioning"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "云服务商返回错误；超时时结果未知，请稍后刷新查看。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务商返回错误：请求失败，请稍后重试",
                  "code": "vps_provider_error"
                }
              }
            }
          },
          "503": {
            "description": "平台未开启云服务器功能，或该云服务器所属站点未配置。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器功能未开启",
                  "code": "vps_disabled"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_image",
            "description": "缺少 `image_id`，或镜像不可用/不在同一站点与地域"
          },
          {
            "status": 400,
            "code": "invalid_password",
            "description": "密码不符合规则"
          },
          {
            "status": 409,
            "code": "vps_busy",
            "description": "正在重装系统"
          },
          {
            "status": 409,
            "code": "vps_provisioning",
            "description": "正在创建中"
          },
          {
            "status": 409,
            "code": "vps_expired",
            "description": "已到期，请先续费"
          },
          {
            "status": 409,
            "code": "vps_error",
            "description": "创建失败、没有机器"
          },
          {
            "status": 409,
            "code": "vps_terminated",
            "description": "已释放"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "云服务器不存在或不属于当前用户"
          },
          {
            "status": 502,
            "code": "vps_provider_error",
            "description": "云服务商返回错误或超时（超时时结果未知）"
          },
          {
            "status": 503,
            "code": "vps_disabled",
            "description": "平台未开启云服务器，或该机器所属站点未配置"
          }
        ]
      }
    },
    "/vps/{id}/password": {
      "post": {
        "operationId": "resetVpsPassword",
        "summary": "重置登录密码",
        "description": "重置 `root`（Linux）或 `Administrator`（Windows）的登录密码，旧密码立即失效。\n\n- 请求体可省略；`password` 为空或省略时由平台生成，并只在本次响应的 `password` 字段返回。\n- 密码规则：8–30 位，只能包含大小写字母、数字和常见符号，且至少包含大写、小写、数字、特殊字符中的三类。\n- 允许的状态：`running`、`stopped`、`starting`、`stopping`、`rebooting`。其他状态返回 409：`reinstalling` → `vps_busy`，`provisioning` → `vps_provisioning`，`expired` → `vps_expired`，`error` → `vps_error`，`terminated` → `vps_terminated`。",
        "tags": [
          "vps"
        ],
        "x-scope": "write",
        "x-danger": "destructive",
        "x-rate-limit": "60 次/分钟/用户（电源操作、重装、重置密码、释放合计）",
        "x-cli": "ocent vps password-reset 7 --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/VpsId"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VPSPasswordRequest"
              },
              "example": {
                "password": ""
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "密码已重置",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSPasswordResetResult"
                },
                "example": {
                  "message": "密码已重置",
                  "password": "Xk7#mP2q-Lw9^zR4"
                }
              }
            }
          },
          "400": {
            "description": "请求体无法解析或密码不符合规则。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "密码需包含大写字母、小写字母、数字、特殊字符中的至少三类",
                  "code": "invalid_password"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "云服务器不存在，或不属于当前用户。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "当前状态不允许重置密码。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器正在重装系统，请稍后再试",
                  "code": "vps_busy"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "云服务商返回错误；超时时结果未知，请稍后刷新查看。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务商返回错误：请求失败，请稍后重试",
                  "code": "vps_provider_error"
                }
              }
            }
          },
          "503": {
            "description": "平台未开启云服务器功能，或该云服务器所属站点未配置。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器功能未开启",
                  "code": "vps_disabled"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_password",
            "description": "请求体无法解析，或密码不符合规则"
          },
          {
            "status": 409,
            "code": "vps_busy",
            "description": "正在重装系统"
          },
          {
            "status": 409,
            "code": "vps_provisioning",
            "description": "正在创建中"
          },
          {
            "status": 409,
            "code": "vps_expired",
            "description": "已到期，请先续费"
          },
          {
            "status": 409,
            "code": "vps_error",
            "description": "状态异常"
          },
          {
            "status": 409,
            "code": "vps_terminated",
            "description": "已释放"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "云服务器不存在或不属于当前用户"
          },
          {
            "status": 502,
            "code": "vps_provider_error",
            "description": "云服务商返回错误或超时（超时时结果未知）"
          },
          {
            "status": 503,
            "code": "vps_disabled",
            "description": "平台未开启云服务器，或该机器所属站点未配置"
          }
        ]
      },
      "get": {
        "operationId": "getVpsPassword",
        "summary": "查看登录凭据",
        "description": "返回云服务器的登录用户名与当前密码（平台保存的最近一次设置的密码）。\n\n- 读取凭据属于 **write** 权限，只有 read 权限的密钥会被拒绝。\n- 用户在机器内自行修改过的密码平台无从得知，此时返回的是旧密码。\n- 平台没有保存密码时 `password` 为空字符串。",
        "tags": [
          "vps"
        ],
        "x-scope": "write",
        "x-cli": "ocent vps password 7",
        "parameters": [
          {
            "$ref": "#/components/parameters/VpsId"
          }
        ],
        "responses": {
          "200": {
            "description": "登录凭据",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSCredential"
                },
                "example": {
                  "username": "root",
                  "password": "Xk7#mP2q-Lw9^zR4"
                }
              }
            }
          },
          "400": {
            "description": "路径 ID 不是正整数。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "无效的资源编号",
                  "code": "invalid_id"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "云服务器不存在，或不属于当前用户。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-error-codes": [
          {
            "status": 404,
            "code": "not_found",
            "description": "云服务器不存在或不属于当前用户"
          }
        ]
      }
    },
    "/vps/{id}/images": {
      "get": {
        "operationId": "listVpsReinstallImages",
        "summary": "可重装的系统镜像",
        "description": "列出该云服务器所在站点与地域当前可用的系统镜像，即重装系统时 `image_id` 的可选值。与商店不同，即使该地域已没有在售套餐也会列出。",
        "tags": [
          "vps"
        ],
        "x-scope": "read",
        "x-cli": "ocent vps images 7",
        "parameters": [
          {
            "$ref": "#/components/parameters/VpsId"
          }
        ],
        "responses": {
          "200": {
            "description": "镜像列表",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSImageList"
                },
                "example": {
                  "items": [
                    {
                      "id": 5,
                      "provider": "ucloud",
                      "region": "cn-sh2",
                      "name": "Ubuntu 24.04",
                      "os_type": "Linux",
                      "os_name": "Ubuntu 24.04 64位"
                    },
                    {
                      "id": 6,
                      "provider": "ucloud",
                      "region": "cn-sh2",
                      "name": "Windows Server 2022",
                      "os_type": "Windows",
                      "os_name": "Windows Server 2022 数据中心版 64位"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "路径 ID 不是正整数。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "无效的资源编号",
                  "code": "invalid_id"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "云服务器不存在，或不属于当前用户。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-error-codes": [
          {
            "status": 404,
            "code": "not_found",
            "description": "云服务器不存在或不属于当前用户"
          }
        ]
      }
    },
    "/vps/{id}/renew": {
      "post": {
        "operationId": "renewVps",
        "summary": "续费云服务器",
        "description": "从余额扣费为云服务器续费，到期时间顺延。请求体可省略。\n\n- `months` 为 1、3 或 12，默认为机器自己的续费周期（`renew_months`）；手动续费不会改变 `renew_months`。\n- 价格：按机器自己的周期续费时使用购买时快照的 `renew_price_cents`；按其他周期续费时为 月价快照 × 月数 × 当前折扣。\n- **建议带 `expected_price_cents`**：实际价格与之不同时返回 `409 price_changed`（带 `price_cents`），且不扣费。\n- 允许的状态：`running`、`stopped`、`starting`、`stopping`、`rebooting`、`reinstalling`、`expired`；`provisioning`、`error`、`terminated` 返回 409。\n- `expired` 的机器续费前会向云服务商确认机器仍存在（已被回收时返回 `409 vps_error`）；续费成功后恢复为 `stopped`，需要再手动开机。\n- 10 秒内重复续费同一台机器返回 `409 vps_duplicate`。\n- 客户端超时或断线时扣费可能已经发生，请先用 `GET /vps/{id}` 核对 `expires_at`，不要直接重发。",
        "tags": [
          "vps"
        ],
        "x-scope": "billing",
        "x-danger": "billing",
        "x-rate-limit": "20 次/分钟/用户",
        "x-cli": "ocent vps renew 7 --months 3 --expected-price 13965 --yes",
        "parameters": [
          {
            "$ref": "#/components/parameters/VpsId"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VPSRenewRequest"
              },
              "example": {
                "months": 3,
                "expected_price_cents": 13965
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "续费成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSRenewResult"
                },
                "example": {
                  "vps": {
                    "id": 7,
                    "name": "my-vps",
                    "provider": "ucloud",
                    "status": "running",
                    "status_detail": "",
                    "last_error": "",
                    "region": "cn-sh2",
                    "region_name": "上海",
                    "plan_id": 2,
                    "plan_name": "2 核 2G",
                    "bundle_id": "ulh.c2m2s40b30t800",
                    "cpu_cores": 2,
                    "memory_mb": 2048,
                    "disk_gb": 40,
                    "bandwidth_mbps": 30,
                    "traffic_gb": 800,
                    "traffic_used_gb": 12,
                    "traffic_total_gb": 800,
                    "monthly_price_cents": 4900,
                    "renew_months": 1,
                    "renew_price_cents": 4900,
                    "image_name": "Ubuntu 24.04",
                    "os_type": "Linux",
                    "public_ip": "203.0.113.10",
                    "username": "root",
                    "has_machine": true,
                    "expires_at": "2027-03-24T08:00:00Z",
                    "auto_renew": false,
                    "expired_at": null,
                    "release_at": null,
                    "terminated_at": null,
                    "created_at": "2026-11-24T08:00:00Z",
                    "updated_at": "2026-11-24T08:03:00Z"
                  },
                  "order": {
                    "id": 1025,
                    "kind": "vps_renewal",
                    "amount_cents": 13965,
                    "status": "paid",
                    "created_at": "2026-11-24T09:00:00Z"
                  },
                  "expires_at": "2027-03-24T08:00:00Z",
                  "message": "续费成功"
                }
              }
            }
          },
          "400": {
            "description": "`months` 无效或请求体无法解析。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "付费周期仅支持按月、按季度或按年",
                  "code": "invalid_months"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "402": {
            "$ref": "#/components/responses/InsufficientBalance"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "云服务器不存在，或不属于当前用户。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "409": {
            "description": "当前状态无法续费、重复提交，或价格已变化（带 `price_cents`）。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "价格已变化，请确认新的价格后重试",
                  "code": "price_changed",
                  "price_cents": 13965
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          },
          "502": {
            "description": "云服务商返回错误；超时时结果未知，请稍后刷新查看。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务商返回错误：请求失败，请稍后重试",
                  "code": "vps_provider_error"
                }
              }
            }
          },
          "503": {
            "description": "平台未开启云服务器功能，或该云服务器所属站点未配置。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器功能未开启",
                  "code": "vps_disabled"
                }
              }
            }
          }
        },
        "x-error-codes": [
          {
            "status": 400,
            "code": "invalid_months",
            "description": "`months` 不是 1、3、12，或请求体无法解析"
          },
          {
            "status": 402,
            "code": "insufficient_balance",
            "description": "余额不足"
          },
          {
            "status": 409,
            "code": "price_changed",
            "description": "实际价格与 `expected_price_cents` 不符，未扣费；响应带 `price_cents`"
          },
          {
            "status": 409,
            "code": "vps_duplicate",
            "description": "10 秒内重复续费"
          },
          {
            "status": 409,
            "code": "vps_provisioning",
            "description": "正在创建中"
          },
          {
            "status": 409,
            "code": "vps_error",
            "description": "状态异常、创建失败，或已到期的机器已被云服务商回收"
          },
          {
            "status": 409,
            "code": "vps_busy",
            "description": "已到期的机器在确认后状态又发生变化，请刷新后重试"
          },
          {
            "status": 409,
            "code": "vps_terminated",
            "description": "已释放"
          },
          {
            "status": 502,
            "code": "vps_provider_error",
            "description": "确认已到期机器是否存在时云服务商出错"
          },
          {
            "status": 404,
            "code": "not_found",
            "description": "云服务器不存在或不属于当前用户"
          },
          {
            "status": 503,
            "code": "vps_disabled",
            "description": "平台未开启云服务器，或该机器所属站点未配置"
          }
        ]
      }
    },
    "/vps/{id}/release-refund": {
      "get": {
        "operationId": "getVpsReleaseRefund",
        "summary": "释放退款预估",
        "description": "预估此刻释放该云服务器能退回的金额，不做任何改动。实际退款按发起释放时计算。\n\n- 只退首期购买价：购买后 3 天内 80%，7 天内 50%，10 天内 20%，之后为 0；续费金额不退，向下取整到分。\n- 已释放、没有机器（创建失败已全额退款）、购买订单已不是已支付状态或已退过款时，所有金额为 0、时间为 `null`。",
        "tags": [
          "vps"
        ],
        "x-scope": "read",
        "x-cli": "ocent api GET /vps/7/release-refund",
        "parameters": [
          {
            "$ref": "#/components/parameters/VpsId"
          }
        ],
        "responses": {
          "200": {
            "description": "退款预估",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VPSReleaseRefundQuote"
                },
                "example": {
                  "purchase_price_cents": 4900,
                  "purchased_at": "2026-11-24T08:00:00Z",
                  "refund_percent": 80,
                  "refund_cents": 3920,
                  "refund_until": "2026-11-27T08:00:00Z"
                }
              }
            }
          },
          "400": {
            "description": "路径 ID 不是正整数。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "无效的资源编号",
                  "code": "invalid_id"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "description": "云服务器不存在，或不属于当前用户。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "error": "云服务器不存在",
                  "code": "not_found"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-error-codes": [
          {
            "status": 404,
            "code": "not_found",
            "description": "云服务器不存在或不属于当前用户"
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "ock_...",
        "description": "在「账户 → API 密钥」创建，形如 `ock_` 加 48 位小写十六进制。只在创建时显示一次。"
      }
    },
    "parameters": {
      "InstanceId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "游戏服务器实例 ID",
        "schema": {
          "type": "integer",
          "format": "int64",
          "minimum": 1
        },
        "example": 42
      },
      "VpsId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "云服务器 ID",
        "schema": {
          "type": "integer",
          "format": "int64",
          "minimum": 1
        },
        "example": 7
      },
      "Limit": {
        "name": "limit",
        "in": "query",
        "required": false,
        "description": "每页条数，1–100，默认 20。不是整数或小于 1 时按默认值处理，超过 100 时按 100 处理，不返回 400；以响应中的 `limit` 为准",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 20
        },
        "example": 20
      },
      "Offset": {
        "name": "offset",
        "in": "query",
        "required": false,
        "description": "偏移量，0–1000000，默认 0。不是整数或小于 0 时按默认值处理，超过上限时按上限处理，不返回 400；以响应中的 `offset` 为准",
        "schema": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000,
          "default": 0
        },
        "example": 0
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "description": "错误响应。按 `code` 判断错误类型，`error` 仅用于展示。少数错误带额外字段。",
        "required": [
          "error",
          "code"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "中文可读的错误消息，文案可能调整"
          },
          "code": {
            "type": "string",
            "description": "snake_case 机器可读错误码"
          },
          "required_scope": {
            "type": "string",
            "description": "仅 `insufficient_scope`：缺少的权限范围",
            "enum": [
              "read",
              "write",
              "billing"
            ]
          },
          "field": {
            "type": "string",
            "description": "仅 `invalid_variable`：出错的变量名"
          },
          "instance_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "仅 `provision_failed`：已退款的实例 ID"
          },
          "diff_cents": {
            "type": "integer",
            "format": "int64",
            "description": "仅 `price_changed`（改套餐）：当前实际差价，单位分"
          },
          "hourly_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "仅 `price_changed`（改套餐，按小时实例）：新的每小时价格，单位分"
          },
          "price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "仅 `price_changed`（云服务器）：当前实际价格，单位分"
          }
        },
        "additionalProperties": true,
        "example": {
          "error": "资源不存在",
          "code": "not_found"
        }
      },
      "MessageResponse": {
        "type": "object",
        "description": "只包含提示消息的成功响应。",
        "required": [
          "message"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "中文提示消息"
          }
        },
        "example": {
          "message": "操作成功"
        }
      },
      "User": {
        "type": "object",
        "description": "当前用户。不包含当前 API 密钥的信息（名称、权限）。",
        "required": [
          "id",
          "email",
          "display_name",
          "role",
          "balance_cents",
          "oc_coins",
          "email_verified",
          "invite_code",
          "created_at",
          "realname_verified"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "email": {
            "type": "string",
            "description": "登录邮箱",
            "format": "email"
          },
          "display_name": {
            "type": "string",
            "description": "显示名称"
          },
          "role": {
            "type": "string",
            "description": "账户角色",
            "enum": [
              "user",
              "admin"
            ]
          },
          "balance_cents": {
            "type": "integer",
            "format": "int64",
            "description": "钱包余额，单位分"
          },
          "oc_coins": {
            "type": "integer",
            "description": "OC币积分（整数个数，不是金额）",
            "format": "int64"
          },
          "email_verified": {
            "type": "boolean",
            "description": "邮箱是否已验证"
          },
          "invite_code": {
            "type": "string",
            "description": "邀请码"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "realname_verified": {
            "type": "boolean",
            "description": "是否已通过实名认证"
          }
        },
        "example": {
          "id": 1001,
          "email": "you@example.com",
          "display_name": "示例用户",
          "role": "user",
          "balance_cents": 12345,
          "oc_coins": 120,
          "email_verified": true,
          "invite_code": "K7MQ2XPA",
          "created_at": "2026-11-01T08:00:00Z",
          "realname_verified": false
        }
      },
      "InstanceNode": {
        "type": "object",
        "description": "节点（服务器所在的物理机房节点）。",
        "required": [
          "id",
          "name",
          "status",
          "public_host"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "name": {
            "type": "string",
            "description": "节点名称"
          },
          "status": {
            "type": "string",
            "description": "节点状态",
            "enum": [
              "pending",
              "online",
              "offline",
              "error"
            ]
          },
          "public_host": {
            "type": "string",
            "description": "节点公网主机名，玩家与 SFTP 连接此地址"
          }
        }
      },
      "NodePlan": {
        "type": "object",
        "description": "节点套餐，决定价格与资源。",
        "required": [
          "id",
          "node_id",
          "name",
          "cpu_cores",
          "memory_mb",
          "disk_mb",
          "monthly_price_cents",
          "hourly_price_cents",
          "sort_order",
          "enabled"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "node_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "所属节点 ID"
          },
          "name": {
            "type": "string",
            "description": "套餐名称"
          },
          "cpu_cores": {
            "type": "number",
            "description": "CPU 核数，可为小数"
          },
          "memory_mb": {
            "type": "integer",
            "description": "内存，MB",
            "format": "int64"
          },
          "disk_mb": {
            "type": "integer",
            "description": "磁盘额度，MB（不是文件系统硬配额）",
            "format": "int64"
          },
          "monthly_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "月付价格，单位分"
          },
          "hourly_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "运行一小时的价格，单位分；0 表示不支持按小时计费"
          },
          "sort_order": {
            "type": "integer",
            "description": "排序值，越小越靠前"
          },
          "enabled": {
            "type": "boolean",
            "description": "是否在售"
          }
        }
      },
      "StoreNode": {
        "description": "商店中的节点及其在售套餐。",
        "allOf": [
          {
            "$ref": "#/components/schemas/InstanceNode"
          },
          {
            "type": "object",
            "description": "",
            "required": [
              "plans"
            ],
            "properties": {
              "plans": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/NodePlan"
                },
                "description": "该节点在售套餐"
              }
            }
          }
        ]
      },
      "ImagePortSpec": {
        "type": "object",
        "description": "游戏版本声明的端口。",
        "required": [
          "container_port",
          "protocol",
          "primary",
          "mirror"
        ],
        "properties": {
          "container_port": {
            "type": "integer",
            "description": "容器端口；`mirror` 端口为 0"
          },
          "protocol": {
            "type": "string",
            "description": "协议；`tcp_udp` 会展开成 TCP、UDP 两条映射，共用一个宿主机端口",
            "enum": [
              "tcp",
              "udp",
              "tcp_udp"
            ]
          },
          "primary": {
            "type": "boolean",
            "description": "是否为主端口（玩家连接的端口），恰好一个为 true"
          },
          "mirror": {
            "type": "boolean",
            "description": "镜像端口：宿主机端口与容器端口相同，用于在 Steam 列表中公布自身端口的游戏"
          }
        }
      },
      "DockerImageOption": {
        "type": "object",
        "description": "可选的运行镜像。",
        "required": [
          "name",
          "image"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "显示名称，如 `Java 21`"
          },
          "image": {
            "type": "string",
            "description": "镜像地址，开服或修改设置时作为 `docker_image` 传入"
          }
        }
      },
      "VariableOption": {
        "type": "object",
        "description": "下拉选择型变量的选项。",
        "required": [
          "label",
          "value"
        ],
        "properties": {
          "label": {
            "type": "string",
            "description": "显示文本"
          },
          "value": {
            "type": "string",
            "description": "取值"
          }
        }
      },
      "VariableDefinition": {
        "type": "object",
        "description": "游戏版本的变量定义（只含面板可见的变量）。密码类变量的默认值在商店中被清空。",
        "required": [
          "key",
          "name",
          "description",
          "default_value",
          "input_type",
          "options",
          "rule",
          "user_editable",
          "required_on_create"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "变量名，作为环境变量传给游戏进程"
          },
          "name": {
            "type": "string",
            "description": "显示名称"
          },
          "description": {
            "type": "string",
            "description": "说明"
          },
          "default_value": {
            "type": "string",
            "description": "默认值"
          },
          "input_type": {
            "type": "string",
            "description": "输入类型",
            "enum": [
              "text",
              "select",
              "password"
            ]
          },
          "options": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/VariableOption"
            },
            "description": "`select` 的选项；其他类型为空数组"
          },
          "rule": {
            "type": "string",
            "description": "取值须整体匹配的 Go RE2 正则；空表示不限制"
          },
          "user_editable": {
            "type": "boolean",
            "description": "用户是否可修改"
          },
          "required_on_create": {
            "type": "boolean",
            "description": "开服时是否必须填写非空值"
          }
        }
      },
      "InstanceVariable": {
        "description": "实例当前变量：变量定义加当前值。隐藏/密码变量只控制面板显示，游戏进程仍能读取；模板替换不做 shell 转义。",
        "allOf": [
          {
            "$ref": "#/components/schemas/VariableDefinition"
          },
          {
            "type": "object",
            "description": "",
            "required": [
              "value"
            ],
            "properties": {
              "value": {
                "type": "string",
                "description": "当前值（实例值，未设置时为默认值）"
              },
              "value_redacted": {
                "type": "boolean",
                "description": "为 true 表示密钥没有 `write` 权限，密码类变量的值已被清空"
              }
            }
          }
        ]
      },
      "InstanceImage": {
        "type": "object",
        "description": "游戏版本（商店 `versions[]` 与实例 `image` 共用此结构）。",
        "required": [
          "id",
          "group_id",
          "name",
          "version",
          "description",
          "docker_image",
          "docker_images",
          "ports",
          "mount_path",
          "enabled",
          "startup_command_locked",
          "variables",
          "has_install",
          "curseforge_modpacks",
          "workshop_app_id",
          "workshop_dir"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "group_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "所属游戏 ID"
          },
          "name": {
            "type": "string",
            "description": "版本名称"
          },
          "version": {
            "type": "string",
            "description": "版本号"
          },
          "description": {
            "type": "string",
            "description": "说明"
          },
          "docker_image": {
            "type": "string",
            "description": "默认运行镜像"
          },
          "docker_images": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DockerImageOption"
            },
            "description": "可选运行镜像"
          },
          "ports": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ImagePortSpec"
            },
            "description": "声明的端口"
          },
          "mount_path": {
            "type": "string",
            "description": "容器内数据目录"
          },
          "enabled": {
            "type": "boolean",
            "description": "是否在售"
          },
          "startup_command_locked": {
            "type": "boolean",
            "description": "为 true 时只有管理员能修改启动参数"
          },
          "variables": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/VariableDefinition"
            },
            "description": "用户可见的变量定义"
          },
          "has_install": {
            "type": "boolean",
            "description": "是否有安装步骤（开服或重装时运行）"
          },
          "curseforge_modpacks": {
            "type": "boolean",
            "description": "是否支持从 CurseForge 整合包开服"
          },
          "workshop_app_id": {
            "type": "integer",
            "description": "Steam 创意工坊 AppID；大于 0 表示支持创意工坊",
            "format": "int64"
          },
          "workshop_dir": {
            "type": "string",
            "description": "创意工坊物品目录模板；空为默认"
          }
        }
      },
      "InstanceGame": {
        "type": "object",
        "description": "实例所属游戏的简要信息。",
        "required": [
          "id",
          "name",
          "cover_url",
          "banner_url"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "name": {
            "type": "string",
            "description": "游戏名称"
          },
          "cover_url": {
            "type": "string",
            "description": "封面图地址，可能为空"
          },
          "banner_url": {
            "type": "string",
            "description": "横幅图地址，可能为空"
          }
        }
      },
      "InstancePort": {
        "type": "object",
        "description": "实例的一条端口映射（已展开为单一协议）。",
        "required": [
          "container_port",
          "host_port",
          "protocol"
        ],
        "properties": {
          "container_port": {
            "type": "integer",
            "description": "容器端口"
          },
          "host_port": {
            "type": "integer",
            "description": "节点上的公网端口，玩家连接 `connect_host:host_port`"
          },
          "protocol": {
            "type": "string",
            "description": "协议",
            "enum": [
              "tcp",
              "udp"
            ]
          }
        }
      },
      "InstancePrimaryPort": {
        "type": "object",
        "description": "主端口。同一端口同时发布 TCP 与 UDP 时 `protocol` 为 `tcp_udp`。",
        "required": [
          "container_port",
          "host_port",
          "protocol"
        ],
        "properties": {
          "container_port": {
            "type": "integer",
            "description": "容器端口（即 `SERVER_PORT`）"
          },
          "host_port": {
            "type": "integer",
            "description": "节点上的公网端口"
          },
          "protocol": {
            "type": "string",
            "description": "协议",
            "enum": [
              "tcp",
              "udp",
              "tcp_udp"
            ]
          }
        }
      },
      "Instance": {
        "type": "object",
        "description": "游戏服务器实例。套餐、价格与资源是购买或改套餐时的快照，之后商品调整不影响已有实例。",
        "required": [
          "id",
          "name",
          "status",
          "status_detail",
          "last_error",
          "node",
          "connect_host",
          "image",
          "game",
          "plan_id",
          "plan_name",
          "cpu_cores",
          "memory_mb",
          "disk_mb",
          "monthly_price_cents",
          "renewal_price_cents",
          "recurring_coupon_code",
          "billing_mode",
          "hourly_price_cents",
          "hourly_storage_price_cents",
          "hourly_storage_percent",
          "hourly_storage_paid",
          "expires_at",
          "auto_renew",
          "delete_at",
          "startup_command",
          "docker_image",
          "mount_path",
          "ports",
          "primary_port",
          "variables",
          "install_status",
          "install_error",
          "installed_at",
          "has_install",
          "modpack_id",
          "modpack_name",
          "modpack_version",
          "modpack_icon_url",
          "curseforge_project_id",
          "curseforge_file_id",
          "curseforge_slug",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "name": {
            "type": "string",
            "description": "实例名称"
          },
          "status": {
            "type": "string",
            "description": "实例状态",
            "enum": [
              "provisioning",
              "installing",
              "install_failed",
              "starting",
              "running",
              "stopped",
              "error",
              "expired"
            ]
          },
          "status_detail": {
            "type": "string",
            "description": "状态补充说明"
          },
          "last_error": {
            "type": "string",
            "description": "最近一次错误"
          },
          "node": {
            "$ref": "#/components/schemas/InstanceNode"
          },
          "connect_host": {
            "type": "string",
            "description": "玩家连接地址（节点公网主机名）"
          },
          "image": {
            "$ref": "#/components/schemas/InstanceImage"
          },
          "game": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/InstanceGame"
              },
              {
                "type": "null"
              }
            ],
            "description": "所属游戏；游戏已删除时为 null"
          },
          "plan_id": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "description": "套餐 ID 快照；可能为 null"
          },
          "plan_name": {
            "type": "string",
            "description": "套餐名称快照"
          },
          "cpu_cores": {
            "type": "number",
            "description": "CPU 核数快照"
          },
          "memory_mb": {
            "type": "integer",
            "description": "内存快照，MB",
            "format": "int64"
          },
          "disk_mb": {
            "type": "integer",
            "description": "磁盘额度快照，MB；不是文件系统硬配额，只用于部分压缩解压的上限",
            "format": "int64"
          },
          "monthly_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "套餐月付原价快照，单位分"
          },
          "renewal_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "实际续费价，单位分；有循环优惠码时低于原价"
          },
          "recurring_coupon_code": {
            "type": "string",
            "description": "循环优惠码；无则为空串"
          },
          "billing_mode": {
            "type": "string",
            "description": "计费方式",
            "enum": [
              "monthly",
              "hourly"
            ]
          },
          "hourly_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "按小时实例运行一小时的价格，单位分"
          },
          "hourly_storage_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "按小时实例停机一小时的存储价格，单位分"
          },
          "hourly_storage_percent": {
            "type": "integer",
            "description": "停机存储价占运行价的百分比"
          },
          "hourly_storage_paid": {
            "type": "boolean",
            "description": "当前小时是否已按存储价扣费（此时开机会补扣差价）"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "auto_renew": {
            "type": "boolean",
            "description": "到期是否自动从余额续费"
          },
          "delete_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "已到期实例将被自动删除（含数据，不可恢复）的时刻；未到期为 null"
          },
          "startup_command": {
            "type": "string",
            "description": "启动参数（不含平台自动添加的 `exec`）"
          },
          "docker_image": {
            "type": "string",
            "description": "当前运行镜像"
          },
          "mount_path": {
            "type": "string",
            "description": "容器内数据目录"
          },
          "ports": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InstancePort"
            },
            "description": "展开后的端口映射（`tcp_udp` 展开为 TCP、UDP 两条，共用一个宿主机端口），包含版本声明的端口与用户添加的自定义端口：版本端口展开后最多 10 条，自定义端口另有最多 10 个（`tcp_udp` 算一个），因此总条数可能超过 10。"
          },
          "primary_port": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/InstancePrimaryPort"
              },
              {
                "type": "null"
              }
            ],
            "description": "主端口；没有映射时为 null"
          },
          "variables": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InstanceVariable"
            },
            "description": "面板可见的变量及当前值"
          },
          "install_status": {
            "type": "string",
            "description": "安装状态",
            "enum": [
              "",
              "installing",
              "installed",
              "failed"
            ]
          },
          "install_error": {
            "type": "string",
            "description": "安装失败原因"
          },
          "installed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "最近一次安装完成时间"
          },
          "has_install": {
            "type": "boolean",
            "description": "是否有安装步骤"
          },
          "modpack_id": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "description": "平台整合包 ID；无则为 null"
          },
          "modpack_name": {
            "type": "string",
            "description": "整合包名称快照（含 CurseForge 整合包）"
          },
          "modpack_version": {
            "type": "string",
            "description": "整合包版本快照"
          },
          "modpack_icon_url": {
            "type": "string",
            "description": "整合包图标地址，可能为空"
          },
          "curseforge_project_id": {
            "type": "integer",
            "description": "CurseForge 项目 ID；0 表示不是 CurseForge 整合包",
            "format": "int64"
          },
          "curseforge_file_id": {
            "type": "integer",
            "description": "CurseForge 文件 ID；0 表示不是 CurseForge 整合包",
            "format": "int64"
          },
          "curseforge_slug": {
            "type": "string",
            "description": "CurseForge 项目 slug"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "example": {
          "id": 42,
          "name": "my-server",
          "status": "running",
          "status_detail": "",
          "last_error": "",
          "node": {
            "id": 1,
            "name": "华东一区",
            "status": "online",
            "public_host": "node1.example.com"
          },
          "connect_host": "node1.example.com",
          "image": {
            "id": 10,
            "group_id": 2,
            "name": "Paper",
            "version": "1.21",
            "description": "",
            "docker_image": "example/minecraft:java21",
            "docker_images": [
              {
                "name": "Java 21",
                "image": "example/minecraft:java21"
              }
            ],
            "ports": [
              {
                "container_port": 25565,
                "protocol": "tcp",
                "primary": true,
                "mirror": false
              }
            ],
            "mount_path": "/data",
            "enabled": true,
            "startup_command_locked": false,
            "variables": [],
            "has_install": true,
            "curseforge_modpacks": false,
            "workshop_app_id": 0,
            "workshop_dir": ""
          },
          "game": {
            "id": 2,
            "name": "Minecraft",
            "cover_url": "",
            "banner_url": ""
          },
          "plan_id": 3,
          "plan_name": "标准 4G",
          "cpu_cores": 2,
          "memory_mb": 4096,
          "disk_mb": 20480,
          "monthly_price_cents": 3000,
          "renewal_price_cents": 3000,
          "recurring_coupon_code": "",
          "billing_mode": "monthly",
          "hourly_price_cents": 0,
          "hourly_storage_price_cents": 0,
          "hourly_storage_percent": 10,
          "hourly_storage_paid": false,
          "expires_at": "2026-12-24T08:00:00Z",
          "auto_renew": true,
          "delete_at": null,
          "startup_command": "java -Xmx{{SERVER_MEMORY}}M -jar server.jar nogui",
          "docker_image": "example/minecraft:java21",
          "mount_path": "/data",
          "ports": [
            {
              "container_port": 25565,
              "host_port": 30001,
              "protocol": "tcp"
            }
          ],
          "primary_port": {
            "container_port": 25565,
            "host_port": 30001,
            "protocol": "tcp"
          },
          "variables": [
            {
              "key": "EULA",
              "name": "同意 EULA",
              "description": "",
              "default_value": "TRUE",
              "input_type": "select",
              "options": [
                {
                  "label": "同意",
                  "value": "TRUE"
                }
              ],
              "rule": "",
              "user_editable": true,
              "required_on_create": false,
              "value": "TRUE"
            }
          ],
          "install_status": "installed",
          "install_error": "",
          "installed_at": "2026-11-24T08:05:00Z",
          "has_install": true,
          "modpack_id": null,
          "modpack_name": "",
          "modpack_version": "",
          "modpack_icon_url": "",
          "curseforge_project_id": 0,
          "curseforge_file_id": 0,
          "curseforge_slug": "",
          "created_at": "2026-11-24T08:00:00Z",
          "updated_at": "2026-11-24T08:06:00Z"
        }
      },
      "InstanceResponse": {
        "type": "object",
        "description": "单个实例。",
        "required": [
          "instance"
        ],
        "properties": {
          "instance": {
            "$ref": "#/components/schemas/Instance"
          }
        }
      },
      "InstanceList": {
        "type": "object",
        "description": "实例列表，按 ID 倒序，不分页。",
        "required": [
          "items"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Instance"
            }
          }
        }
      },
      "SFTPCredential": {
        "type": "object",
        "description": "SFTP 连接凭据（含明文密码，需 `write`）。",
        "required": [
          "host",
          "port",
          "username",
          "password"
        ],
        "properties": {
          "host": {
            "type": "string",
            "description": "SFTP 主机（节点公网主机名）"
          },
          "port": {
            "type": "integer",
            "description": "SFTP 端口"
          },
          "username": {
            "type": "string",
            "description": "用户名"
          },
          "password": {
            "type": "string",
            "description": "明文密码"
          }
        }
      },
      "Order": {
        "type": "object",
        "description": "订单。`amount_cents` 始终为实际扣款金额。",
        "required": [
          "id",
          "user_id",
          "kind",
          "amount_cents",
          "status",
          "provider",
          "provider_ref",
          "discount_cents",
          "coupon_code",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "user_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "所属用户 ID"
          },
          "kind": {
            "type": "string",
            "description": "订单类型，如 `instance_purchase`（开服）、`instance_renewal`（续费）、`instance_hourly`（按小时计费）、`plan_upgrade`（改套餐差价）、`instance_delete_refund`（删除退款）、`vps_purchase`、`vps_renewal`、`vps_release_refund`；会随功能增加，不要假设是固定集合"
          },
          "amount_cents": {
            "type": "integer",
            "format": "int64",
            "description": "实际扣款金额，单位分"
          },
          "status": {
            "type": "string",
            "description": "订单状态",
            "enum": [
              "pending",
              "paid",
              "failed",
              "refunded"
            ]
          },
          "provider": {
            "type": "string",
            "description": "支付来源，余额支付为 `balance`"
          },
          "provider_ref": {
            "type": "string",
            "description": "支付来源侧的参考号"
          },
          "instance_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "关联的游戏服务器实例 ID（如有）"
          },
          "vps_instance_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "关联的云服务器 ID（如有）"
          },
          "discount_cents": {
            "type": "integer",
            "format": "int64",
            "description": "优惠码抵扣金额，单位分"
          },
          "coupon_code": {
            "type": "string",
            "description": "使用的优惠码；无则为空串"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "VPSOrder": {
        "type": "object",
        "description": "云服务器购买或续费响应中的订单摘要。",
        "required": [
          "id",
          "kind",
          "amount_cents",
          "status",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "kind": {
            "type": "string",
            "description": "订单类型",
            "enum": [
              "vps_purchase",
              "vps_renewal"
            ]
          },
          "amount_cents": {
            "type": "integer",
            "format": "int64",
            "description": "实际扣款金额，单位分"
          },
          "status": {
            "type": "string",
            "description": "订单状态",
            "enum": [
              "pending",
              "paid",
              "failed",
              "refunded"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WalletSummary": {
        "type": "object",
        "description": "钱包概况。",
        "required": [
          "balance_cents",
          "income_cents",
          "spent_cents",
          "oc_coins"
        ],
        "properties": {
          "balance_cents": {
            "type": "integer",
            "format": "int64",
            "description": "当前余额，单位分"
          },
          "income_cents": {
            "type": "integer",
            "format": "int64",
            "description": "累计入账，单位分：所有正数流水之和（含充值、退款、返利等入账），不等于净充值"
          },
          "spent_cents": {
            "type": "integer",
            "format": "int64",
            "description": "累计支出，单位分"
          },
          "oc_coins": {
            "type": "integer",
            "description": "OC币积分",
            "format": "int64"
          }
        },
        "example": {
          "balance_cents": 12345,
          "income_cents": 50000,
          "spent_cents": 37655,
          "oc_coins": 120
        }
      },
      "WalletTransaction": {
        "type": "object",
        "description": "钱包流水。",
        "required": [
          "id",
          "user_id",
          "type",
          "amount_cents",
          "balance_after_cents",
          "description",
          "reference_type",
          "reference_id",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "user_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "所属用户 ID"
          },
          "type": {
            "type": "string",
            "description": "流水类型，如 `recharge`、`instance_purchase`、`instance_renewal`、`vps_purchase`；会随功能增加，不要假设是固定集合"
          },
          "amount_cents": {
            "type": "integer",
            "format": "int64",
            "description": "变动金额，单位分；正数为入账，负数为扣款"
          },
          "balance_after_cents": {
            "type": "integer",
            "format": "int64",
            "description": "变动后余额，单位分"
          },
          "description": {
            "type": "string",
            "description": "说明"
          },
          "reference_type": {
            "type": "string",
            "description": "关联对象类型，如 `order`"
          },
          "reference_id": {
            "type": "integer",
            "description": "关联对象 ID",
            "format": "int64"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "OCCoinTransaction": {
        "type": "object",
        "description": "OC币流水。",
        "required": [
          "id",
          "user_id",
          "type",
          "amount",
          "balance_after",
          "description",
          "reference_type",
          "reference_id",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "user_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "所属用户 ID"
          },
          "type": {
            "type": "string",
            "description": "流水类型，如 `recharge_bonus`、`admin_adjust`；会随功能增加"
          },
          "amount": {
            "type": "integer",
            "description": "变动积分；正数为增加，负数为扣减",
            "format": "int64"
          },
          "balance_after": {
            "type": "integer",
            "description": "变动后积分",
            "format": "int64"
          },
          "description": {
            "type": "string",
            "description": "说明"
          },
          "reference_type": {
            "type": "string",
            "description": "关联对象类型"
          },
          "reference_id": {
            "type": "integer",
            "description": "关联对象 ID",
            "format": "int64"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WalletTransactionPage": {
        "type": "object",
        "description": "钱包流水分页，按 ID 倒序。",
        "required": [
          "items",
          "total",
          "limit",
          "offset"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WalletTransaction"
            }
          },
          "total": {
            "type": "integer",
            "description": "总条数",
            "format": "int64"
          },
          "limit": {
            "type": "integer",
            "description": "本页条数上限"
          },
          "offset": {
            "type": "integer",
            "description": "偏移量"
          }
        }
      },
      "OCCoinTransactionPage": {
        "type": "object",
        "description": "OC币流水分页，按 ID 倒序。",
        "required": [
          "items",
          "total",
          "limit",
          "offset"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OCCoinTransaction"
            }
          },
          "total": {
            "type": "integer",
            "description": "总条数",
            "format": "int64"
          },
          "limit": {
            "type": "integer",
            "description": "本页条数上限"
          },
          "offset": {
            "type": "integer",
            "description": "偏移量"
          }
        }
      },
      "FileEntry": {
        "type": "object",
        "description": "目录中的一个条目。",
        "required": [
          "name",
          "path",
          "is_dir",
          "size",
          "modified_at",
          "mode"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "文件名"
          },
          "path": {
            "type": "string",
            "description": "相对实例数据目录的路径，以 `/` 开头"
          },
          "is_dir": {
            "type": "boolean",
            "description": "是否为目录"
          },
          "size": {
            "type": "integer",
            "description": "大小，字节",
            "format": "int64"
          },
          "modified_at": {
            "type": "string",
            "format": "date-time"
          },
          "mode": {
            "type": "string",
            "description": "权限，如 `-rw-r--r--`"
          }
        }
      },
      "FileList": {
        "type": "object",
        "description": "目录列表。",
        "required": [
          "path",
          "entries",
          "max_upload_bytes"
        ],
        "properties": {
          "path": {
            "type": "string",
            "description": "当前目录，以 `/` 开头"
          },
          "entries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/FileEntry"
            }
          },
          "max_upload_bytes": {
            "type": "integer",
            "description": "该节点允许上传的单个文件上限，字节",
            "format": "int64"
          }
        }
      },
      "FileContent": {
        "type": "object",
        "description": "文本文件内容（UTF-8，最大 4 MiB）。",
        "required": [
          "path",
          "content",
          "size",
          "modified_at"
        ],
        "properties": {
          "path": {
            "type": "string",
            "description": "文件路径"
          },
          "content": {
            "type": "string",
            "description": "文件内容"
          },
          "size": {
            "type": "integer",
            "description": "大小，字节",
            "format": "int64"
          },
          "modified_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "VPS": {
        "type": "object",
        "description": "云服务器。套餐、价格与配置是购买时的快照。",
        "required": [
          "id",
          "name",
          "provider",
          "status",
          "status_detail",
          "last_error",
          "region",
          "region_name",
          "plan_id",
          "plan_name",
          "bundle_id",
          "cpu_cores",
          "memory_mb",
          "disk_gb",
          "bandwidth_mbps",
          "traffic_gb",
          "traffic_used_gb",
          "traffic_total_gb",
          "monthly_price_cents",
          "renew_months",
          "renew_price_cents",
          "image_name",
          "os_type",
          "public_ip",
          "username",
          "has_machine",
          "expires_at",
          "auto_renew",
          "expired_at",
          "release_at",
          "terminated_at",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "name": {
            "type": "string",
            "description": "名称"
          },
          "provider": {
            "type": "string",
            "description": "上游站点标识"
          },
          "status": {
            "type": "string",
            "description": "状态",
            "enum": [
              "provisioning",
              "running",
              "stopped",
              "starting",
              "stopping",
              "rebooting",
              "reinstalling",
              "expired",
              "terminated",
              "error"
            ]
          },
          "status_detail": {
            "type": "string",
            "description": "状态补充说明"
          },
          "last_error": {
            "type": "string",
            "description": "最近一次错误"
          },
          "region": {
            "type": "string",
            "description": "地域 ID"
          },
          "region_name": {
            "type": "string",
            "description": "地域名称"
          },
          "plan_id": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "description": "套餐 ID；可能为 null"
          },
          "plan_name": {
            "type": "string",
            "description": "套餐名称快照"
          },
          "bundle_id": {
            "type": "string",
            "description": "上游规格 ID"
          },
          "cpu_cores": {
            "type": "integer",
            "description": "CPU 核数"
          },
          "memory_mb": {
            "type": "integer",
            "description": "内存，MB",
            "format": "int64"
          },
          "disk_gb": {
            "type": "integer",
            "description": "系统盘，GB"
          },
          "bandwidth_mbps": {
            "type": "integer",
            "description": "带宽，Mbps"
          },
          "traffic_gb": {
            "type": "integer",
            "description": "每月流量包，GB；0 表示不限"
          },
          "traffic_used_gb": {
            "type": "integer",
            "description": "本期已用流量，GB"
          },
          "traffic_total_gb": {
            "type": "integer",
            "description": "本期总流量，GB"
          },
          "monthly_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "月付价格快照，单位分"
          },
          "renew_months": {
            "type": "integer",
            "description": "自动续费周期（月）",
            "enum": [
              1,
              3,
              12
            ]
          },
          "renew_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "自动续费一期的价格，单位分"
          },
          "image_name": {
            "type": "string",
            "description": "系统镜像名称"
          },
          "os_type": {
            "type": "string",
            "description": "系统类型",
            "enum": [
              "Linux",
              "Windows"
            ]
          },
          "public_ip": {
            "type": "string",
            "description": "公网 IP；创建完成前可能为空"
          },
          "username": {
            "type": "string",
            "description": "登录用户名"
          },
          "has_machine": {
            "type": "boolean",
            "description": "上游是否已有机器；`error` 且为 false 表示创建失败、已退款"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "auto_renew": {
            "type": "boolean",
            "description": "到期是否自动从余额续费"
          },
          "expired_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "进入 `expired` 的时间"
          },
          "release_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "到期后将被自动释放的时间；仅 `expired` 时有值"
          },
          "terminated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "释放时间"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "example": {
          "id": 7,
          "name": "my-vps",
          "provider": "ucloud",
          "status": "running",
          "status_detail": "",
          "last_error": "",
          "region": "cn-sh2",
          "region_name": "上海",
          "plan_id": 2,
          "plan_name": "2 核 2G",
          "bundle_id": "ulh.c2m2s40b30t800",
          "cpu_cores": 2,
          "memory_mb": 2048,
          "disk_gb": 40,
          "bandwidth_mbps": 30,
          "traffic_gb": 800,
          "traffic_used_gb": 12,
          "traffic_total_gb": 800,
          "monthly_price_cents": 4900,
          "renew_months": 1,
          "renew_price_cents": 4900,
          "image_name": "Ubuntu 24.04",
          "os_type": "Linux",
          "public_ip": "203.0.113.10",
          "username": "root",
          "has_machine": true,
          "expires_at": "2026-12-24T08:00:00Z",
          "auto_renew": false,
          "expired_at": null,
          "release_at": null,
          "terminated_at": null,
          "created_at": "2026-11-24T08:00:00Z",
          "updated_at": "2026-11-24T08:03:00Z"
        }
      },
      "VPSResponse": {
        "type": "object",
        "description": "单个云服务器。",
        "required": [
          "vps"
        ],
        "properties": {
          "vps": {
            "$ref": "#/components/schemas/VPS"
          }
        }
      },
      "VPSList": {
        "type": "object",
        "description": "云服务器列表，不分页。",
        "required": [
          "items"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/VPS"
            }
          }
        }
      },
      "VPSPlan": {
        "type": "object",
        "description": "云服务器套餐。",
        "required": [
          "id",
          "provider",
          "region",
          "region_name",
          "name",
          "description",
          "cpu_cores",
          "memory_mb",
          "disk_gb",
          "bandwidth_mbps",
          "traffic_gb",
          "monthly_price_cents"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "provider": {
            "type": "string",
            "description": "上游站点标识"
          },
          "region": {
            "type": "string",
            "description": "地域 ID"
          },
          "region_name": {
            "type": "string",
            "description": "地域名称"
          },
          "name": {
            "type": "string",
            "description": "套餐名称"
          },
          "description": {
            "type": "string",
            "description": "说明"
          },
          "cpu_cores": {
            "type": "integer",
            "description": "CPU 核数"
          },
          "memory_mb": {
            "type": "integer",
            "description": "内存，MB",
            "format": "int64"
          },
          "disk_gb": {
            "type": "integer",
            "description": "系统盘，GB"
          },
          "bandwidth_mbps": {
            "type": "integer",
            "description": "带宽，Mbps"
          },
          "traffic_gb": {
            "type": "integer",
            "description": "每月流量包，GB；0 表示不限"
          },
          "monthly_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "月付价格，单位分"
          }
        }
      },
      "VPSImage": {
        "type": "object",
        "description": "云服务器系统镜像。",
        "required": [
          "id",
          "provider",
          "region",
          "name",
          "os_type",
          "os_name"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "provider": {
            "type": "string",
            "description": "上游站点标识"
          },
          "region": {
            "type": "string",
            "description": "地域 ID"
          },
          "name": {
            "type": "string",
            "description": "镜像名称"
          },
          "os_type": {
            "type": "string",
            "description": "系统类型",
            "enum": [
              "Linux",
              "Windows"
            ]
          },
          "os_name": {
            "type": "string",
            "description": "系统名称"
          }
        }
      },
      "VPSPeriod": {
        "type": "object",
        "description": "付费周期与折扣。",
        "required": [
          "months",
          "label",
          "discount_percent"
        ],
        "properties": {
          "months": {
            "type": "integer",
            "description": "月数",
            "enum": [
              1,
              3,
              12
            ]
          },
          "label": {
            "type": "string",
            "description": "显示名称，如「按月」「按季度」「按年」"
          },
          "discount_percent": {
            "type": "integer",
            "description": "该周期价格占原价的百分比：100 表示不打折（月付固定为 100），例如 95 表示九五折、85 表示八五折。周期价格 = 月价 × 月数 × discount_percent ÷ 100（向下取整到分）。",
            "minimum": 50,
            "maximum": 100
          }
        }
      },
      "AccountMeResponse": {
        "type": "object",
        "description": "`GET /auth/me` 的响应。",
        "required": [
          "user"
        ],
        "properties": {
          "user": {
            "$ref": "#/components/schemas/User"
          }
        }
      },
      "StoreModpack": {
        "type": "object",
        "description": "商店中的整合包。只列出已上架、整合包文件可供节点下载、且所属版本在售的整合包。",
        "required": [
          "id",
          "group_id",
          "game_image_id",
          "name",
          "version",
          "description",
          "docker_image",
          "startup_command",
          "run_install_script",
          "file_size",
          "sort_order",
          "icon_url"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "group_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "所属游戏 ID"
          },
          "game_image_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "基于的游戏版本 ID"
          },
          "name": {
            "type": "string",
            "description": "整合包名称"
          },
          "version": {
            "type": "string",
            "description": "整合包版本"
          },
          "description": {
            "type": "string",
            "description": "说明"
          },
          "docker_image": {
            "type": "string",
            "description": "运行镜像"
          },
          "startup_command": {
            "type": "string",
            "description": "启动命令"
          },
          "run_install_script": {
            "type": "boolean",
            "description": "是否同时运行基础版本的安装脚本；为 false 时开服表单不要求填写版本变量"
          },
          "file_size": {
            "type": "integer",
            "format": "int64",
            "description": "整合包文件大小，字节"
          },
          "sort_order": {
            "type": "integer",
            "description": "排序值，越小越靠前"
          },
          "icon_url": {
            "type": "string",
            "description": "图标地址，可能为空"
          }
        }
      },
      "StoreGameGroup": {
        "type": "object",
        "description": "商店中的游戏，含在售版本与整合包。",
        "required": [
          "id",
          "name",
          "description",
          "min_cpu_cores",
          "min_memory_mb",
          "min_disk_mb",
          "sort_order",
          "enabled",
          "cover_url",
          "banner_url",
          "versions",
          "modpacks"
        ],
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1
          },
          "name": {
            "type": "string",
            "description": "游戏名称"
          },
          "description": {
            "type": "string",
            "description": "说明"
          },
          "min_cpu_cores": {
            "type": "number",
            "description": "套餐最低 CPU 核数，可为小数；0 表示不限"
          },
          "min_memory_mb": {
            "type": "integer",
            "format": "int64",
            "description": "套餐最低内存，MB；0 表示不限"
          },
          "min_disk_mb": {
            "type": "integer",
            "format": "int64",
            "description": "套餐最低磁盘额度，MB；0 表示不限"
          },
          "sort_order": {
            "type": "integer",
            "description": "排序值，越小越靠前"
          },
          "enabled": {
            "type": "boolean",
            "description": "是否在售（商店中恒为 true）"
          },
          "cover_url": {
            "type": "string",
            "description": "封面图地址（相对路径），可能为空"
          },
          "banner_url": {
            "type": "string",
            "description": "横幅图地址（相对路径），可能为空"
          },
          "versions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InstanceImage"
            },
            "description": "在售版本，按 ID 倒序；至少一个"
          },
          "modpacks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StoreModpack"
            },
            "description": "可选整合包，按排序值与 ID 升序；没有时为空数组"
          }
        }
      },
      "StoreCatalog": {
        "type": "object",
        "description": "`GET /store` 的响应。",
        "required": [
          "nodes",
          "groups"
        ],
        "properties": {
          "nodes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StoreNode"
            },
            "description": "在售节点，按名称升序"
          },
          "groups": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StoreGameGroup"
            },
            "description": "在售游戏，按排序值与 ID 升序"
          }
        }
      },
      "StoreVPSRegion": {
        "type": "object",
        "description": "云服务器商店中的一个（站点, 地域）组合。",
        "required": [
          "provider",
          "region",
          "region_name",
          "realname_required",
          "plans",
          "images"
        ],
        "properties": {
          "provider": {
            "type": "string",
            "description": "上游站点标识，如 `ucloud`（国内站）、`ucloud_global`（国际站）"
          },
          "region": {
            "type": "string",
            "description": "地域 ID；不同站点之间可能重复"
          },
          "region_name": {
            "type": "string",
            "description": "地域名称"
          },
          "realname_required": {
            "type": "boolean",
            "description": "当前用户在该站点购买前是否还需完成实名认证"
          },
          "plans": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/VPSPlan"
            },
            "description": "该地域在售套餐，至少一个"
          },
          "images": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/VPSImage"
            },
            "description": "该地域可选系统镜像，至少一个"
          }
        }
      },
      "StoreVPSPaymentChannel": {
        "type": "object",
        "description": "网页面板可用的直接支付渠道（开放 API 购买只能用余额）。",
        "required": [
          "channel",
          "name"
        ],
        "properties": {
          "channel": {
            "type": "string",
            "description": "渠道标识",
            "enum": [
              "alipay",
              "wechat"
            ]
          },
          "name": {
            "type": "string",
            "description": "渠道名称"
          }
        }
      },
      "StoreVPSCatalog": {
        "type": "object",
        "description": "`GET /vps/store` 的响应。",
        "required": [
          "enabled",
          "grace_days",
          "regions",
          "realname_required",
          "realname_enabled",
          "payment_channels",
          "periods"
        ],
        "properties": {
          "enabled": {
            "type": "boolean",
            "description": "平台是否开放云服务器；为 false 时 `regions` 与 `payment_channels` 为空数组"
          },
          "grace_days": {
            "type": "integer",
            "description": "到期后停机保留的天数，过后释放"
          },
          "regions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StoreVPSRegion"
            },
            "description": "可购买的地域"
          },
          "realname_required": {
            "type": "boolean",
            "description": "任一已配置站点要求实名且当前用户尚未实名时为 true"
          },
          "realname_enabled": {
            "type": "boolean",
            "description": "平台当前是否提供实名认证"
          },
          "payment_channels": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StoreVPSPaymentChannel"
            },
            "description": "除余额外可直接支付的渠道"
          },
          "periods": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/VPSPeriod"
            },
            "description": "付费周期与折扣（1、3、12 个月）"
          }
        }
      },
      "CouponPreviewRequest": {
        "type": "object",
        "description": "优惠码试算请求。",
        "required": [
          "code",
          "node_id",
          "image_id",
          "plan_id"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "优惠码；会去除首尾空白并转为大写。有效优惠码为 3–32 位 A–Z、0–9、`-`、`_`",
            "example": "SAVE5"
          },
          "node_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "节点 ID",
            "example": 1
          },
          "image_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "游戏版本 ID（商店 `versions[].id`）",
            "example": 10
          },
          "plan_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "该节点下的套餐 ID",
            "example": 3
          },
          "billing_mode": {
            "type": "string",
            "description": "计划使用的计费方式；省略为 `monthly`。`hourly` 直接返回 `coupon_not_supported`",
            "enum": [
              "monthly",
              "hourly"
            ],
            "default": "monthly"
          }
        }
      },
      "CouponPreviewResponse": {
        "type": "object",
        "description": "优惠码试算结果。金额均为整数分，按套餐月价计算。",
        "required": [
          "code",
          "name",
          "discount_type",
          "percent_off",
          "amount_off_cents",
          "recurring",
          "original_cents",
          "discount_cents",
          "paid_cents",
          "renewal_price_cents"
        ],
        "properties": {
          "code": {
            "type": "string",
            "description": "规范化后的优惠码（大写）"
          },
          "name": {
            "type": "string",
            "description": "优惠码名称"
          },
          "discount_type": {
            "type": "string",
            "description": "折扣类型：`percent` 百分比、`fixed` 固定金额",
            "enum": [
              "percent",
              "fixed"
            ]
          },
          "percent_off": {
            "type": "integer",
            "description": "百分比折扣减去的比例（1–99，20 即 8 折）；固定金额券为 0"
          },
          "amount_off_cents": {
            "type": "integer",
            "format": "int64",
            "description": "固定减免金额，单位分；百分比券为 0"
          },
          "recurring": {
            "type": "boolean",
            "description": "true 为循环券（每次续费都打折），false 为新购券（只优惠首月）"
          },
          "original_cents": {
            "type": "integer",
            "format": "int64",
            "description": "原价（套餐月价），单位分"
          },
          "discount_cents": {
            "type": "integer",
            "format": "int64",
            "description": "优惠金额，单位分；不超过原价"
          },
          "paid_cents": {
            "type": "integer",
            "format": "int64",
            "description": "折后应付，单位分"
          },
          "renewal_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "之后每次续费的价格，单位分：循环券为折后价，新购券为原价"
          }
        }
      },
      "InstanceCurseForgeChoice": {
        "type": "object",
        "description": "CurseForge 整合包文件。只能用于标记了 `curseforge_modpacks` 的版本，且不能与 `modpack_id` 同时使用；两个 ID 都必须非 0。",
        "required": [
          "project_id",
          "file_id"
        ],
        "properties": {
          "project_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "CurseForge 项目 ID"
          },
          "file_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "CurseForge 文件 ID"
          }
        }
      },
      "InstanceCreateRequest": {
        "type": "object",
        "description": "开服请求。按月开通 1 个月（没有月数参数），按小时预付第 1 小时。",
        "required": [
          "name",
          "image_id",
          "node_id",
          "plan_id"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2,
            "maxLength": 60,
            "description": "实例名称，去掉首尾空白后 2–60 个字符"
          },
          "image_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "游戏版本 ID（商店 `groups[].versions[].id`）"
          },
          "node_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "节点 ID"
          },
          "plan_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "该节点下的套餐 ID"
          },
          "billing_mode": {
            "type": "string",
            "enum": [
              "monthly",
              "hourly"
            ],
            "default": "monthly",
            "description": "计费方式，空为 `monthly`。`hourly` 需要套餐 `hourly_price_cents > 0`，不支持优惠码，`auto_renew` 固定为 true。"
          },
          "auto_renew": {
            "type": "boolean",
            "default": true,
            "description": "到期是否自动从余额续费；按小时实例忽略"
          },
          "docker_image": {
            "type": "string",
            "description": "运行镜像，须是版本 `docker_images[].image` 之一；空为默认。使用整合包时被忽略。"
          },
          "startup_command": {
            "type": "string",
            "maxLength": 4096,
            "description": "启动参数，最多 4096 字节且不能含 NUL；空为版本（或整合包）默认值。不需要写 `exec`，平台会自动处理；只能引用已定义的变量。版本锁定启动参数（`startup_command_locked`）时只能为空或等于默认值。"
          },
          "variables": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "maxLength": 1024
            },
            "description": "`{变量名: 值}`。只能填 `user_editable` 的变量；值最多 1024 字节，不能含换行或 NUL，`select` 类型须是选项之一，有 `rule` 时须整体匹配该正则。"
          },
          "modpack_id": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "description": "平台整合包 ID；null 或 0 为原版"
          },
          "curseforge": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/InstanceCurseForgeChoice"
              },
              {
                "type": "null"
              }
            ],
            "description": "从 CurseForge 整合包开服；与 `modpack_id` 互斥"
          },
          "coupon_code": {
            "type": "string",
            "description": "优惠码，只作用于首月；按小时计费时必须为空"
          }
        }
      },
      "InstanceActionRequest": {
        "type": "object",
        "required": [
          "action"
        ],
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "start",
              "stop",
              "restart",
              "kill"
            ],
            "description": "`start` 开机、`stop` 正常停止（游戏的停止命令）、`restart` 重启、`kill` 强制停止（SIGKILL，未保存的数据可能丢失）。大小写与首尾空白不敏感。"
          }
        }
      },
      "InstanceActionResult": {
        "type": "object",
        "required": [
          "status",
          "message",
          "warnings"
        ],
        "properties": {
          "status": {
            "type": "string",
            "description": "操作后的实例状态（节点未报告时 start/restart 记为 `running`，stop/kill 记为 `stopped`）"
          },
          "message": {
            "type": "string",
            "description": "固定为「操作成功」"
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "节点或模板渲染给出的提示（如变量未定义），没有时为空数组"
          }
        }
      },
      "InstanceSettingsRequest": {
        "type": "object",
        "description": "字段均可选，但至少提供一项。",
        "minProperties": 1,
        "properties": {
          "startup_command": {
            "type": "string",
            "maxLength": 4096,
            "description": "新的启动参数，最多 4096 字节且不能含 NUL；保存时去掉开头的 `exec`。修改会重建容器（数据保留，运行中会重启）。版本锁定时只能重新提交当前值。"
          },
          "docker_image": {
            "type": "string",
            "description": "运行镜像，须是版本提供的选项（整合包实例也可选整合包的运行镜像）；与当前相同视为未修改。修改会重建容器。"
          },
          "auto_renew": {
            "type": "boolean",
            "description": "自动续费开关；按小时实例忽略。从关闭改为开启时 API 密钥另需 `billing`。"
          }
        }
      },
      "InstanceUpdateResult": {
        "type": "object",
        "required": [
          "instance",
          "message",
          "warnings"
        ],
        "properties": {
          "instance": {
            "$ref": "#/components/schemas/Instance"
          },
          "message": {
            "type": "string",
            "description": "中文提示消息"
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "节点或模板渲染给出的提示（如变量未定义），没有时为空数组"
          }
        }
      },
      "InstanceVariablesRequest": {
        "type": "object",
        "required": [
          "variables"
        ],
        "properties": {
          "variables": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "maxLength": 1024
            },
            "description": "`{变量名: 值}`。只能填 `user_editable` 的变量；值最多 1024 字节，不能含换行或 NUL，`select` 类型须是选项之一，有 `rule` 时须整体匹配该正则。",
            "minProperties": 1
          }
        }
      },
      "InstanceAcceptedResult": {
        "type": "object",
        "description": "已被接受的长任务（重新安装、切换游戏）。",
        "required": [
          "instance",
          "message"
        ],
        "properties": {
          "instance": {
            "$ref": "#/components/schemas/Instance"
          },
          "message": {
            "type": "string",
            "description": "中文提示消息"
          }
        }
      },
      "InstanceSwitchGameRequest": {
        "type": "object",
        "required": [
          "image_id",
          "confirm_name"
        ],
        "properties": {
          "image_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "目标游戏版本 ID，可以是其他游戏"
          },
          "confirm_name": {
            "type": "string",
            "description": "必须与当前实例名称完全一致（区分大小写，不去空白），确认清空的是这台实例"
          },
          "docker_image": {
            "type": "string",
            "description": "运行镜像，须是目标版本 `docker_images[].image` 之一；空为默认。使用整合包时被忽略。"
          },
          "modpack_id": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "description": "目标版本下的平台整合包 ID；null 或 0 为原版"
          },
          "curseforge": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/InstanceCurseForgeChoice"
              },
              {
                "type": "null"
              }
            ],
            "description": "切换到 CurseForge 整合包；与 `modpack_id` 互斥"
          },
          "variables": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "maxLength": 1024
            },
            "description": "`{变量名: 值}`。只能填 `user_editable` 的变量；值最多 1024 字节，不能含换行或 NUL，`select` 类型须是选项之一，有 `rule` 时须整体匹配该正则。"
          },
          "startup_command": {
            "type": "string",
            "maxLength": 4096,
            "description": "启动参数，最多 4096 字节且不能含 NUL；空为版本（或整合包）默认值。不需要写 `exec`，平台会自动处理；只能引用已定义的变量。版本锁定启动参数（`startup_command_locked`）时只能为空或等于默认值。"
          }
        }
      },
      "InstanceRenewResult": {
        "type": "object",
        "required": [
          "message",
          "expires_at",
          "order"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "按月实例为「续费成功」，按小时实例为「已恢复按小时计费」"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "新的到期时间"
          },
          "order": {
            "$ref": "#/components/schemas/Order"
          }
        }
      },
      "InstanceMinResources": {
        "type": "object",
        "description": "游戏的最低配置；0 表示不限制。",
        "required": [
          "cpu_cores",
          "memory_mb",
          "disk_mb"
        ],
        "properties": {
          "cpu_cores": {
            "type": "number",
            "description": "最低 CPU 核数"
          },
          "memory_mb": {
            "type": "integer",
            "format": "int64",
            "description": "最低内存，MB"
          },
          "disk_mb": {
            "type": "integer",
            "format": "int64",
            "description": "最低磁盘额度，MB"
          }
        }
      },
      "InstancePlanOption": {
        "description": "可更换的套餐：节点套餐字段加更换报价。",
        "allOf": [
          {
            "$ref": "#/components/schemas/NodePlan"
          },
          {
            "type": "object",
            "required": [
              "current",
              "fits",
              "downgrade",
              "diff_cents",
              "renewal_price_cents",
              "recurring_discount_kept"
            ],
            "properties": {
              "current": {
                "type": "boolean",
                "description": "是否为实例当前套餐"
              },
              "fits": {
                "type": "boolean",
                "description": "是否满足游戏最低配置；false 时更换会被拒绝（`plan_too_small`）"
              },
              "downgrade": {
                "type": "boolean",
                "description": "是否为降级（价格低于当前）；降级不能选择（`plan_downgrade_disabled`）"
              },
              "diff_cents": {
                "type": "integer",
                "format": "int64",
                "description": "此刻更换需补的差价，单位分：按剩余整天数（不足一天按一天）在 30 天月内折算，向上取整；降级与按小时实例恒为 0。提交 `POST /instances/{id}/plan` 时作为 `expected_diff_cents`。"
              },
              "renewal_price_cents": {
                "type": "integer",
                "format": "int64",
                "description": "更换后的续费价，单位分：按月实例为一个月的价格（循环优惠码仍适用时为优惠后价格），按小时实例为运行一小时的价格"
              },
              "recurring_discount_kept": {
                "type": "boolean",
                "description": "更换后循环优惠码是否仍然有效；没有循环优惠码或按小时实例为 false"
              },
              "hourly_storage_price_cents": {
                "type": "integer",
                "format": "int64",
                "description": "仅按小时实例：更换后停机一小时的存储价格，单位分"
              }
            }
          }
        ]
      },
      "InstancePlanOptions": {
        "type": "object",
        "required": [
          "billing_mode",
          "remaining_days",
          "min_resources",
          "items"
        ],
        "properties": {
          "billing_mode": {
            "type": "string",
            "enum": [
              "monthly",
              "hourly"
            ],
            "description": "实例计费方式"
          },
          "remaining_days": {
            "type": "integer",
            "format": "int64",
            "description": "距到期的剩余天数（不足一天按一天）；按小时实例为 0"
          },
          "min_resources": {
            "$ref": "#/components/schemas/InstanceMinResources"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InstancePlanOption"
            },
            "description": "同一节点上在售的套餐（含当前套餐），按排序值、月价、ID 排列。按小时实例只列出支持小时价的套餐（当前套餐总是列出）。"
          }
        }
      },
      "InstancePlanChangeRequest": {
        "type": "object",
        "required": [
          "plan_id",
          "expected_diff_cents"
        ],
        "properties": {
          "plan_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "目标套餐 ID，须为同一节点在售套餐"
          },
          "expected_diff_cents": {
            "type": "integer",
            "format": "int64",
            "description": "确认的差价，单位分，取自 `GET /instances/{id}/plans` 的 `diff_cents`；按小时实例传 0。与服务端计算不一致时返回 `409 price_changed`，不扣费。"
          },
          "expected_hourly_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "仅按小时实例，可选：确认的新小时价，单位分；不一致时返回 `409 price_changed`"
          }
        }
      },
      "InstancePlanChangeResult": {
        "type": "object",
        "required": [
          "instance",
          "diff_cents",
          "message",
          "warnings"
        ],
        "properties": {
          "instance": {
            "$ref": "#/components/schemas/Instance"
          },
          "diff_cents": {
            "type": "integer",
            "format": "int64",
            "description": "实际扣除的差价，单位分；按小时实例为 0"
          },
          "message": {
            "type": "string",
            "description": "中文提示消息"
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "节点或模板渲染给出的提示（如变量未定义），没有时为空数组"
          }
        }
      },
      "InstanceDeleteRefundQuote": {
        "type": "object",
        "description": "删除退款试算。按小时实例全部为 0（不退款）。",
        "required": [
          "monthly_price_cents",
          "remaining_days",
          "remaining_value_cents",
          "refundable_value_cents",
          "refund_percent",
          "refund_cents"
        ],
        "properties": {
          "monthly_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "实际月价（循环优惠后），单位分"
          },
          "remaining_days": {
            "type": "integer",
            "format": "int64",
            "description": "剩余整天数，不足一天的部分不计（当天不退）"
          },
          "remaining_value_cents": {
            "type": "integer",
            "format": "int64",
            "description": "剩余价值 = 月价 × 剩余天数 ÷ 30，向下取整，单位分"
          },
          "refundable_value_cents": {
            "type": "integer",
            "format": "int64",
            "description": "可退价值 = min(剩余价值, 该实例已付净额)，单位分"
          },
          "refund_percent": {
            "type": "integer",
            "description": "退款比例，按月实例为 80；按小时实例为 0"
          },
          "refund_cents": {
            "type": "integer",
            "format": "int64",
            "description": "退款金额 = 可退价值 × 比例 ÷ 100，向下取整，单位分"
          }
        }
      },
      "InstanceDeleteResult": {
        "type": "object",
        "required": [
          "message",
          "refund_cents"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "中文提示消息"
          },
          "refund_cents": {
            "type": "integer",
            "format": "int64",
            "description": "退回余额的金额，单位分；0 表示没有退款"
          }
        }
      },
      "InstanceInstallInfo": {
        "type": "object",
        "description": "最近一次安装的状态与日志。实例没有安装步骤且从未安装过时各字段为空。",
        "required": [
          "status",
          "error",
          "exit_code",
          "started_at",
          "finished_at",
          "log"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "",
              "installing",
              "installed",
              "failed"
            ],
            "description": "安装状态；空串表示没有安装记录"
          },
          "error": {
            "type": "string",
            "maxLength": 500,
            "description": "安装失败原因（最多 500 字节）"
          },
          "exit_code": {
            "type": [
              "integer",
              "null"
            ],
            "description": "安装脚本退出码；未结束时为 null"
          },
          "started_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "finished_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "log": {
            "type": "string",
            "description": "安装日志末尾（最多约 64 KiB）"
          }
        }
      },
      "InstanceNetworkPort": {
        "type": "object",
        "description": "网络页的一条端口。同一外网端口的 TCP 与 UDP 合并为一条 `tcp_udp`。",
        "required": [
          "container_port",
          "host_port",
          "protocol",
          "source",
          "primary",
          "remark",
          "mirror"
        ],
        "properties": {
          "container_port": {
            "type": "integer",
            "description": "容器端口"
          },
          "host_port": {
            "type": "integer",
            "description": "外网端口，玩家连接 `connect_host:host_port`"
          },
          "protocol": {
            "type": "string",
            "enum": [
              "tcp",
              "udp",
              "tcp_udp"
            ]
          },
          "source": {
            "type": "string",
            "enum": [
              "image",
              "custom"
            ],
            "description": "`image` 为游戏版本自带（不可删除），`custom` 为自行添加"
          },
          "primary": {
            "type": "boolean",
            "description": "是否为主端口"
          },
          "remark": {
            "type": "string",
            "description": "备注；版本自带端口为空串"
          },
          "mirror": {
            "type": "boolean",
            "description": "外网端口是否与容器端口相同"
          }
        }
      },
      "InstanceNetwork": {
        "type": "object",
        "required": [
          "connect_host",
          "items",
          "extra_count",
          "extra_limit"
        ],
        "properties": {
          "connect_host": {
            "type": "string",
            "description": "玩家连接地址（节点公网主机名）"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InstanceNetworkPort"
            },
            "description": "先列版本自带端口，再按添加顺序列自定义端口"
          },
          "extra_count": {
            "type": "integer",
            "description": "已添加的自定义端口数（`tcp_udp` 计 1 条）"
          },
          "extra_limit": {
            "type": "integer",
            "description": "自定义端口上限，目前为 10"
          }
        }
      },
      "InstanceNetworkChange": {
        "description": "端口变更后的网络页。",
        "allOf": [
          {
            "$ref": "#/components/schemas/InstanceNetwork"
          },
          {
            "type": "object",
            "required": [
              "message",
              "warnings"
            ],
            "properties": {
              "message": {
                "type": "string",
                "description": "中文提示消息"
              },
              "warnings": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "节点或模板渲染给出的提示（如变量未定义），没有时为空数组"
              }
            }
          }
        ]
      },
      "InstancePortAddRequest": {
        "type": "object",
        "required": [
          "protocol"
        ],
        "properties": {
          "container_port": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535,
            "description": "要开放的容器端口；`mirror` 为 true 时忽略，否则必填"
          },
          "protocol": {
            "type": "string",
            "enum": [
              "tcp",
              "udp",
              "tcp_udp"
            ],
            "description": "协议，大小写不敏感；`tcp+udp` 视同 `tcp_udp`"
          },
          "remark": {
            "type": "string",
            "maxLength": 40,
            "description": "备注，去掉首尾空白后最多 40 个字"
          },
          "mirror": {
            "type": "boolean",
            "default": false,
            "description": "为 true 时申请对等端口：自动挑一个空闲端口 P，容器端口与外网端口都为 P"
          }
        }
      },
      "InstanceSFTPResponse": {
        "type": "object",
        "required": [
          "sftp"
        ],
        "properties": {
          "sftp": {
            "$ref": "#/components/schemas/SFTPCredential"
          }
        }
      },
      "InstanceSteamQueryResult": {
        "type": "object",
        "description": "Steam A2S_INFO 查询结果。",
        "required": [
          "protocol",
          "sampled_at",
          "name",
          "map",
          "players",
          "max_players",
          "bots",
          "app_id",
          "version",
          "latency_ms"
        ],
        "properties": {
          "protocol": {
            "type": "string",
            "description": "查询协议，目前为 `a2s`"
          },
          "sampled_at": {
            "type": "string",
            "format": "date-time",
            "description": "采样时间"
          },
          "name": {
            "type": "string",
            "description": "服务器名称"
          },
          "map": {
            "type": "string",
            "description": "地图"
          },
          "players": {
            "type": "integer",
            "description": "在线人数（游戏自报，可能含机器人）"
          },
          "max_players": {
            "type": "integer",
            "description": "最大人数"
          },
          "bots": {
            "type": "integer",
            "description": "机器人数"
          },
          "app_id": {
            "type": "integer",
            "format": "int64",
            "description": "Steam AppID（游戏未报告时为 0）"
          },
          "version": {
            "type": "string",
            "description": "游戏版本"
          },
          "latency_ms": {
            "type": "number",
            "description": "节点到游戏进程的查询延迟，毫秒"
          }
        }
      },
      "InstanceWorkshopItem": {
        "type": "object",
        "description": "已安装的创意工坊物品。",
        "required": [
          "item_id",
          "title",
          "dir",
          "bytes",
          "files",
          "time_updated",
          "installed_at"
        ],
        "properties": {
          "item_id": {
            "type": "string",
            "description": "物品 ID（十进制字符串）"
          },
          "title": {
            "type": "string",
            "description": "标题"
          },
          "dir": {
            "type": "string",
            "description": "数据目录内的安装位置"
          },
          "bytes": {
            "type": "integer",
            "format": "int64",
            "description": "占用字节数"
          },
          "files": {
            "type": "integer",
            "format": "int64",
            "description": "文件数"
          },
          "time_updated": {
            "type": "integer",
            "format": "int64",
            "description": "物品在 Steam 上的更新时间（Unix 秒）"
          },
          "installed_at": {
            "type": "string",
            "description": "安装时间（RFC 3339）"
          }
        }
      },
      "InstanceWorkshopTaskItem": {
        "type": "object",
        "required": [
          "item_id",
          "status",
          "error",
          "bytes_done",
          "bytes_total"
        ],
        "properties": {
          "item_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "downloading",
              "transferring",
              "installing",
              "installed",
              "failed"
            ]
          },
          "error": {
            "type": "string",
            "description": "失败原因"
          },
          "bytes_done": {
            "type": "integer",
            "format": "int64"
          },
          "bytes_total": {
            "type": "integer",
            "format": "int64"
          }
        }
      },
      "InstanceWorkshopTask": {
        "type": "object",
        "description": "正在运行或最近一次的安装任务（节点重启后清空）。",
        "required": [
          "status",
          "started_at",
          "finished_at",
          "items"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "idle",
              "running",
              "done",
              "failed"
            ]
          },
          "started_at": {
            "type": "string",
            "description": "RFC 3339；没有任务时为空串"
          },
          "finished_at": {
            "type": "string",
            "description": "RFC 3339；未结束时为空串"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InstanceWorkshopTaskItem"
            }
          }
        }
      },
      "InstanceWorkshopState": {
        "type": "object",
        "required": [
          "app_id",
          "items",
          "task"
        ],
        "properties": {
          "app_id": {
            "type": "integer",
            "format": "int64",
            "description": "版本的 Steam 创意工坊 AppID"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InstanceWorkshopItem"
            }
          },
          "task": {
            "$ref": "#/components/schemas/InstanceWorkshopTask"
          }
        }
      },
      "InstanceWorkshopInstallRequest": {
        "type": "object",
        "required": [
          "item_ids"
        ],
        "properties": {
          "item_ids": {
            "type": "array",
            "minItems": 1,
            "maxItems": 50,
            "items": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,19}$"
            },
            "description": "1–50 个不同的物品 ID（十进制字符串，无前导零，重复的会去重）；安装后物品总数不能超过 200。已安装的物品会重新下载。"
          }
        }
      },
      "InstanceConsoleLogs": {
        "type": "object",
        "required": [
          "output",
          "status",
          "truncated"
        ],
        "properties": {
          "output": {
            "type": "string",
            "maxLength": 262144,
            "description": "控制台原文，包含 ANSI 颜色控制码与 `\\r`；最多 256 KiB"
          },
          "status": {
            "type": "string",
            "description": "节点报告的实例状态（如 `running`、`stopped`）；没有收到状态事件时为空串"
          },
          "truncated": {
            "type": "boolean",
            "description": "输出超过 256 KiB 时只保留末尾并设为 true"
          }
        }
      },
      "InstanceConsoleCommandRequest": {
        "type": "object",
        "required": [
          "command"
        ],
        "properties": {
          "command": {
            "type": "string",
            "minLength": 1,
            "maxLength": 1024,
            "description": "一条命令。末尾的 `\\r`/`\\n` 会被去掉，节点写入时自动追加换行；去掉后不能为空、最多 1024 字节、须为合法 UTF-8，且除制表符外不能含控制字符。"
          }
        }
      },
      "FileWriteRequest": {
        "type": "object",
        "description": "写入文本文件的请求。",
        "required": [
          "path"
        ],
        "properties": {
          "path": {
            "type": "string",
            "description": "目标文件路径，不能是 `/`",
            "example": "/server.properties"
          },
          "content": {
            "type": "string",
            "description": "完整文件内容（UTF-8），最大 4 MiB；省略等同空字符串",
            "maxLength": 4194304
          }
        }
      },
      "FileUploadResult": {
        "type": "object",
        "description": "上传结果。",
        "required": [
          "message",
          "path",
          "size"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "提示消息"
          },
          "path": {
            "type": "string",
            "description": "写入的文件路径"
          },
          "size": {
            "type": "integer",
            "format": "int64",
            "description": "文件大小，字节"
          }
        }
      },
      "FileDirectUploadRequest": {
        "type": "object",
        "description": "申请直传地址的请求。",
        "required": [
          "name",
          "size"
        ],
        "properties": {
          "path": {
            "type": "string",
            "description": "目标目录，默认 `/`",
            "example": "/plugins"
          },
          "name": {
            "type": "string",
            "description": "目标文件名：单段，不能含 `/`、`\\` 或 NUL，不能是 `.` 或 `..`",
            "example": "EssentialsX.jar"
          },
          "size": {
            "type": "integer",
            "format": "int64",
            "minimum": 0,
            "description": "文件的准确字节数；之后 PUT 的字节数必须与之相同",
            "example": 1048576
          }
        }
      },
      "FileDirectUploadTicket": {
        "type": "object",
        "description": "一次性直传地址。",
        "required": [
          "url",
          "path",
          "size",
          "expires_at"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri",
            "description": "直传地址（直连节点，已含一次性令牌）；对其发送 `PUT`，请求体为文件原始字节"
          },
          "path": {
            "type": "string",
            "description": "文件将写入的路径"
          },
          "size": {
            "type": "integer",
            "format": "int64",
            "description": "允许上传的字节数"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "地址失效时间（签发后 10 分钟，UTC）；只检查请求到达时间，已开始的传输可以完成"
          }
        }
      },
      "FilePathRequest": {
        "type": "object",
        "description": "只含一个路径的请求。",
        "required": [
          "path"
        ],
        "properties": {
          "path": {
            "type": "string",
            "description": "目标路径，不能是 `/`",
            "example": "/backups"
          }
        }
      },
      "FileDirectoryResult": {
        "type": "object",
        "description": "创建目录的结果。",
        "required": [
          "message",
          "path"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "提示消息"
          },
          "path": {
            "type": "string",
            "description": "规范化后的目录路径"
          }
        }
      },
      "FileRenameRequest": {
        "type": "object",
        "description": "重命名请求。",
        "required": [
          "from",
          "to"
        ],
        "properties": {
          "from": {
            "type": "string",
            "description": "原路径，不能是 `/`",
            "example": "/world"
          },
          "to": {
            "type": "string",
            "description": "新路径，不能是 `/`；已存在的文件会被覆盖",
            "example": "/world_backup"
          }
        }
      },
      "FileMoveRequest": {
        "type": "object",
        "description": "批量移动请求。",
        "required": [
          "paths",
          "destination"
        ],
        "properties": {
          "paths": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1000,
            "description": "要移动的文件或目录路径，不能是 `/`",
            "items": {
              "type": "string"
            },
            "example": [
              "/a.txt",
              "/logs"
            ]
          },
          "destination": {
            "type": "string",
            "description": "已存在的目标目录",
            "example": "/old"
          }
        }
      },
      "FileMoveResult": {
        "type": "object",
        "description": "批量移动结果。",
        "required": [
          "moved",
          "skipped",
          "message"
        ],
        "properties": {
          "moved": {
            "type": "array",
            "description": "已移动的条目",
            "items": {
              "type": "object",
              "required": [
                "from",
                "to"
              ],
              "properties": {
                "from": {
                  "type": "string",
                  "description": "原路径"
                },
                "to": {
                  "type": "string",
                  "description": "新路径"
                }
              }
            }
          },
          "skipped": {
            "type": "array",
            "description": "被跳过的条目",
            "items": {
              "type": "object",
              "required": [
                "path",
                "reason",
                "code"
              ],
              "properties": {
                "path": {
                  "type": "string",
                  "description": "原路径"
                },
                "reason": {
                  "type": "string",
                  "description": "中文原因"
                },
                "code": {
                  "type": "string",
                  "enum": [
                    "same_location",
                    "target_exists",
                    "into_itself",
                    "not_found",
                    "failed"
                  ],
                  "description": "跳过原因代码"
                }
              }
            }
          },
          "message": {
            "type": "string",
            "description": "如「已移动 1 项，跳过 1 项」"
          }
        }
      },
      "FileBatchRequest": {
        "type": "object",
        "description": "针对 `root` 下若干直接子项的批量请求。",
        "required": [
          "files"
        ],
        "properties": {
          "root": {
            "type": "string",
            "description": "所在目录，默认 `/`",
            "example": "/logs"
          },
          "files": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1000,
            "description": "`root` 下的名称（单段，不含 `/`、`\\`，不能是 `.`、`..`）",
            "items": {
              "type": "string"
            },
            "example": [
              "a.log",
              "b.log"
            ]
          }
        }
      },
      "FileDeleteResult": {
        "type": "object",
        "description": "批量删除结果。",
        "required": [
          "message",
          "deleted"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "提示消息"
          },
          "deleted": {
            "type": "integer",
            "format": "int64",
            "description": "实际删除的条目数（已不存在的名称不计）"
          }
        }
      },
      "FileCompressRequest": {
        "type": "object",
        "description": "压缩请求。",
        "required": [
          "files",
          "name",
          "format"
        ],
        "properties": {
          "root": {
            "type": "string",
            "description": "被压缩条目所在目录，压缩包也写在这里；默认 `/`",
            "example": "/"
          },
          "files": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1000,
            "description": "`root` 下要压缩的名称",
            "items": {
              "type": "string"
            },
            "example": [
              "world",
              "server.properties"
            ]
          },
          "name": {
            "type": "string",
            "description": "压缩包文件名（单段）",
            "example": "backup.zip"
          },
          "format": {
            "type": "string",
            "enum": [
              "zip",
              "tar.gz"
            ],
            "description": "压缩格式"
          }
        }
      },
      "FileDecompressRequest": {
        "type": "object",
        "description": "解压请求。",
        "required": [
          "path"
        ],
        "properties": {
          "path": {
            "type": "string",
            "description": "压缩包路径（.zip / .tar / .tar.gz / .tgz）",
            "example": "/backup.zip"
          },
          "destination": {
            "type": "string",
            "description": "已存在的解压目录；省略时为压缩包所在目录",
            "example": "/restore"
          }
        }
      },
      "FileDecompressResult": {
        "type": "object",
        "description": "解压统计。",
        "required": [
          "files",
          "directories",
          "bytes",
          "skipped"
        ],
        "properties": {
          "files": {
            "type": "integer",
            "format": "int64",
            "description": "写出的文件数"
          },
          "directories": {
            "type": "integer",
            "format": "int64",
            "description": "创建的目录数"
          },
          "bytes": {
            "type": "integer",
            "format": "int64",
            "description": "写出的字节数"
          },
          "skipped": {
            "type": "integer",
            "format": "int64",
            "description": "跳过的条目数（链接、设备文件、与已有文件/目录类型冲突的条目）"
          }
        }
      },
      "FileChmodRequest": {
        "type": "object",
        "description": "修改权限请求。",
        "required": [
          "path",
          "mode"
        ],
        "properties": {
          "path": {
            "type": "string",
            "description": "目标文件或目录，不能是 `/`",
            "example": "/start.sh"
          },
          "mode": {
            "type": "string",
            "pattern": "^0?[0-7]{3}$",
            "description": "三位八进制权限，如 `755`；也接受 `0755`",
            "example": "755"
          },
          "recursive": {
            "type": "boolean",
            "default": false,
            "description": "是否递归修改目录内的全部内容"
          }
        }
      },
      "FileChmodResult": {
        "type": "object",
        "description": "修改权限结果。",
        "required": [
          "message",
          "changed",
          "mode"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "提示消息"
          },
          "changed": {
            "type": "integer",
            "format": "int64",
            "description": "实际修改的条目数"
          },
          "mode": {
            "type": "string",
            "description": "规范化后的三位权限值"
          }
        }
      },
      "VPSCreateRequest": {
        "type": "object",
        "description": "购买云服务器的请求。",
        "required": [
          "plan_id",
          "image_id",
          "name"
        ],
        "properties": {
          "plan_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "套餐 ID（`GET /vps/store`）"
          },
          "image_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "镜像 ID，须与套餐同一站点和地域"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 60,
            "description": "名称：去除首尾空白后 1–60 个字符，不能含控制字符"
          },
          "password": {
            "type": "string",
            "description": "登录密码；留空由平台生成。8–30 位，只能包含大小写字母、数字和常见符号 ``()`~!@#$%^&*-+=_|{}[]:;'<>,.?/``，且至少包含大写、小写、数字、特殊字符中的三类",
            "minLength": 0,
            "maxLength": 30
          },
          "auto_renew": {
            "type": "boolean",
            "default": true,
            "description": "到期是否自动从余额续费，**默认 true**"
          },
          "months": {
            "type": "integer",
            "enum": [
              1,
              3,
              12
            ],
            "default": 1,
            "description": "付费周期（月），同时成为自动续费周期"
          },
          "expected_price_cents": {
            "type": "integer",
            "format": "int64",
            "minimum": 0,
            "description": "确认的首期价格（分）；与实际不符时返回 `409 price_changed` 且不扣费"
          }
        }
      },
      "VPSCreateResult": {
        "type": "object",
        "description": "购买结果。",
        "required": [
          "vps",
          "order",
          "message"
        ],
        "properties": {
          "vps": {
            "$ref": "#/components/schemas/VPS"
          },
          "order": {
            "$ref": "#/components/schemas/VPSOrder"
          },
          "message": {
            "type": "string",
            "description": "提示消息；结果不确定时说明正在确认"
          },
          "password": {
            "type": "string",
            "description": "平台生成的密码；只有请求未提供密码时才返回，且只返回这一次"
          }
        }
      },
      "VPSUpdateRequest": {
        "type": "object",
        "description": "修改云服务器设置；字段都可选。",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 60,
            "description": "新名称：去除首尾空白后 1–60 个字符，不能含控制字符"
          },
          "auto_renew": {
            "type": "boolean",
            "description": "自动续费开关；从关闭改为开启时密钥另需 billing"
          }
        }
      },
      "VPSActionRequest": {
        "type": "object",
        "description": "电源操作。",
        "required": [
          "action"
        ],
        "properties": {
          "action": {
            "type": "string",
            "enum": [
              "start",
              "stop",
              "reboot",
              "poweroff"
            ],
            "description": "`poweroff` 为强制断电"
          }
        }
      },
      "VPSActionResult": {
        "type": "object",
        "description": "电源操作结果。",
        "required": [
          "vps",
          "message"
        ],
        "properties": {
          "vps": {
            "$ref": "#/components/schemas/VPS"
          },
          "message": {
            "type": "string",
            "description": "提示消息"
          }
        }
      },
      "VPSReinstallRequest": {
        "type": "object",
        "description": "重装系统请求。",
        "required": [
          "image_id"
        ],
        "properties": {
          "image_id": {
            "type": "integer",
            "format": "int64",
            "minimum": 1,
            "description": "镜像 ID（`GET /vps/{id}/images`）"
          },
          "password": {
            "type": "string",
            "description": "登录密码；留空由平台生成。8–30 位，只能包含大小写字母、数字和常见符号 ``()`~!@#$%^&*-+=_|{}[]:;'<>,.?/``，且至少包含大写、小写、数字、特殊字符中的三类",
            "minLength": 0,
            "maxLength": 30
          }
        }
      },
      "VPSReinstallResult": {
        "type": "object",
        "description": "重装已被接受。",
        "required": [
          "vps",
          "message"
        ],
        "properties": {
          "vps": {
            "$ref": "#/components/schemas/VPS"
          },
          "message": {
            "type": "string",
            "description": "提示消息"
          },
          "password": {
            "type": "string",
            "description": "平台生成的密码；只有请求未提供密码时才返回，且只返回这一次"
          }
        }
      },
      "VPSPasswordRequest": {
        "type": "object",
        "description": "重置密码请求；可省略整个请求体。",
        "properties": {
          "password": {
            "type": "string",
            "description": "登录密码；留空由平台生成。8–30 位，只能包含大小写字母、数字和常见符号 ``()`~!@#$%^&*-+=_|{}[]:;'<>,.?/``，且至少包含大写、小写、数字、特殊字符中的三类",
            "minLength": 0,
            "maxLength": 30
          }
        }
      },
      "VPSPasswordResetResult": {
        "type": "object",
        "description": "重置密码结果。",
        "required": [
          "message"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "提示消息"
          },
          "password": {
            "type": "string",
            "description": "平台生成的密码；只有请求未提供密码时才返回，且只返回这一次"
          }
        }
      },
      "VPSCredential": {
        "type": "object",
        "description": "登录凭据。",
        "required": [
          "username",
          "password"
        ],
        "properties": {
          "username": {
            "type": "string",
            "description": "`root`（Linux）或 `Administrator`（Windows）"
          },
          "password": {
            "type": "string",
            "description": "平台保存的密码；未保存时为空字符串"
          }
        }
      },
      "VPSImageList": {
        "type": "object",
        "description": "可重装的镜像列表，不分页。",
        "required": [
          "items"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/VPSImage"
            }
          }
        }
      },
      "VPSRenewRequest": {
        "type": "object",
        "description": "续费请求；可省略整个请求体。",
        "properties": {
          "months": {
            "type": "integer",
            "enum": [
              1,
              3,
              12
            ],
            "description": "续费月数；默认为机器的 `renew_months`"
          },
          "expected_price_cents": {
            "type": "integer",
            "format": "int64",
            "minimum": 0,
            "description": "确认的价格（分）；与实际不符时返回 `409 price_changed` 且不扣费"
          }
        }
      },
      "VPSRenewResult": {
        "type": "object",
        "description": "续费结果。",
        "required": [
          "vps",
          "order",
          "expires_at",
          "message"
        ],
        "properties": {
          "vps": {
            "$ref": "#/components/schemas/VPS"
          },
          "order": {
            "$ref": "#/components/schemas/VPSOrder"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "新的到期时间"
          },
          "message": {
            "type": "string",
            "description": "提示消息；已到期机器恢复时提示可重新开机"
          }
        }
      },
      "VPSReleaseRefundQuote": {
        "type": "object",
        "description": "释放退款预估，金额单位为分。",
        "required": [
          "purchase_price_cents",
          "purchased_at",
          "refund_percent",
          "refund_cents",
          "refund_until"
        ],
        "properties": {
          "purchase_price_cents": {
            "type": "integer",
            "format": "int64",
            "description": "首期购买价；不可退款时为 0"
          },
          "purchased_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "购买时间；无可退的购买订单时为 null"
          },
          "refund_percent": {
            "type": "integer",
            "format": "int64",
            "enum": [
              0,
              20,
              50,
              80
            ],
            "description": "当前退款比例（%）"
          },
          "refund_cents": {
            "type": "integer",
            "format": "int64",
            "description": "此刻释放可退回的金额"
          },
          "refund_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "当前比例截止时间；不退款时为 null"
          }
        }
      },
      "VPSReleaseResult": {
        "type": "object",
        "description": "释放结果。",
        "required": [
          "message",
          "refund_cents"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "提示消息"
          },
          "refund_cents": {
            "type": "integer",
            "format": "int64",
            "description": "实际退回余额的金额（分）"
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "请求无效：路径 ID 不是正整数、请求体无法解析或缺少必填字段。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "无效的资源编号",
              "code": "invalid_id"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "未认证：缺少认证头（`unauthorized`）、密钥无效或已删除（`invalid_api_key`）、密钥已过期（`api_key_expired`）。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "API 密钥无效或已被删除",
              "code": "invalid_api_key"
            }
          }
        }
      },
      "InsufficientBalance": {
        "description": "余额不足，需先在面板充值。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "余额不足",
              "code": "insufficient_balance"
            }
          }
        }
      },
      "Forbidden": {
        "description": "无权访问：密钥缺少权限（`insufficient_scope`，带 `required_scope`）、账号被禁用（`account_disabled`）或接口不对密钥开放（`api_key_forbidden`）。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "API 密钥缺少 write 权限",
              "code": "insufficient_scope",
              "required_scope": "write"
            }
          }
        }
      },
      "NotFound": {
        "description": "资源不存在或不属于你。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "资源不存在",
              "code": "not_found"
            }
          }
        }
      },
      "Conflict": {
        "description": "状态冲突：如实例正在创建或安装、已到期、价格已变化等，详见 `code`。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "实例正在安装，请稍后再试",
              "code": "instance_installing"
            }
          }
        }
      },
      "PayloadTooLarge": {
        "description": "请求体或内容超过限制（`body_too_large` / `too_large` / `upload_too_large`）。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "请求体过大",
              "code": "body_too_large"
            }
          }
        }
      },
      "RateLimited": {
        "description": "请求过于频繁。响应不带 `Retry-After`，请指数退避后重试。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "请求过于频繁，请稍后再试",
              "code": "rate_limited"
            }
          }
        }
      },
      "InternalError": {
        "description": "服务端内部错误，可稍后重试。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "服务器内部错误，请稍后重试",
              "code": "internal_error"
            }
          }
        }
      },
      "BadGateway": {
        "description": "节点执行失败（如 `agent_error`、`agent_unsupported`）。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "节点执行失败，请稍后重试",
              "code": "agent_error"
            }
          }
        }
      },
      "ServiceUnavailable": {
        "description": "节点或功能暂不可用（如 `node_offline`、`vps_disabled`、`rate_limit_unavailable`）。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "节点离线，暂时无法操作",
              "code": "node_offline"
            }
          }
        }
      },
      "GatewayTimeout": {
        "description": "节点响应超时，操作可能已部分完成，先查询状态再决定是否重试。",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            },
            "example": {
              "error": "节点响应超时",
              "code": "agent_timeout"
            }
          }
        }
      }
    }
  }
}
