# XABCloud > 给人和 AI agent 的云主机:选套餐,微信付款,约两分钟后得到一台可以 SSH 登录的独立 Linux 主机(独立公网 IP、root 权限)。 > > Cloud machines for people and their AI agents: pick a plan, pay with WeChat, and about two minutes later you have a Linux machine of your own to SSH into, with its own public IP and root access. 中文在前,英文在后,内容相同。Chinese first, English after; both say the same. ## 中文 这份说明写给 agent:怎样代你的用户开通和管理主机。接口都是 JSON,地址以 https://xabcloud.com 为根。 ### 你需要什么 - **一把密钥**:请用户在 https://xabcloud.com/me/ 登录,在「Agent 密钥」里生成后交给你。每个请求带 `Authorization: Bearer xabc_…`;请求体是 JSON 时带 `Content-Type: application/json`。 - **一把 SSH 公钥**:你自己生成密钥对,把公钥交上来,私钥留在用户的机器上。本站从不接触私钥。 ssh-keygen -t ed25519 -N "" -f ~/.ssh/xabcloud -C xabcloud - **用户付一次款**:你不能付款。下单后把付款码交给用户,用微信扫码。 出错时回答是 `{"error": {"message": "…", "status": 4xx}}`,`message` 是可以直接转述给用户的中文。 ### 开通一台主机 1. `GET https://xabcloud.com/api/catalog`(不需要密钥):在售的套餐 `plans`、地域 `regions`、系统镜像 `images`,以及时长上限 `terms`。价格单位是分:`price_month_fen` 是包月价,`price_year_fen` 是包年价。先把套餐和价格讲给用户,让用户选。 2. `POST https://xabcloud.com/api/orders`: {"kind": "new", "plan": "starter", "region": "us-west-2", "period": "month", "quantity": 1, "label": "博客", "ssh_public_key": "ssh-ed25519 AAAA…"} `period` 是 `month` 或 `year`,`quantity` 是几个月(1–11)或几年(1–3);`label` 是可选的备注名;`image` 可省略。回答里 `order.out_trade_no` 是订单号,`order.amount_fen` 是应付金额,`payment` 是付款方式。 3. 把付款码交给用户,任选一种: - `GET https://xabcloud.com/api/orders/{out_trade_no}/qr.txt`:用方块字符画的二维码,原样打印在终端里(浅色背景的终端加 `?invert=1`); - `payment.pay_page`:让用户在浏览器里打开,登录后显示二维码; - `payment.code_url`:微信支付链接,可自己生成二维码。 订单 30 分钟内有效(`payment.expires_at`)。 4. 每隔几秒 `GET https://xabcloud.com/api/orders/{out_trade_no}`,直到 `order.status` 变成 `paid`,这时 `order.instance` 是主机名(`xc-` 开头)。变成 `closed` 表示过期未付,需要重新下单。 5. 每隔几秒 `GET https://xabcloud.com/api/instances/{name}`,`instance.status` 依次是 `queued`、`creating`、`booting`,约两分钟后到 `running`,这时 `instance.ssh_command` 是登录命令,`instance.ipv4` 是公网地址。用你的私钥登录: ssh -i ~/.ssh/xabcloud ubuntu@ 默认账户 `ubuntu` 可以免密码 `sudo`。时长从主机到 `running` 起算,`instance.paid_until` 是到期时间。`failed` 表示开通遇到问题,平台已收到通知,已付的时长不受影响,请告诉用户稍候。 ### 管理主机 - `GET https://xabcloud.com/api/instances`:这个账户的全部主机。 - `GET https://xabcloud.com/api/instances/{name}`:一台主机和它的操作记录 `events`。 - `POST https://xabcloud.com/api/instances/{name}/reboot`:重启。 - `PUT https://xabcloud.com/api/instances/{name}/ports`:公网防火墙,整体替换。默认开放 22、80、443: {"ports": [{"protocol": "tcp", "from": 22, "to": 22}, {"protocol": "tcp", "from": 8000, "to": 8100}]} `protocol` 是 `tcp` 或 `udp`。列表里没有的端口一律关闭,去掉 22 就无法 SSH。 - `PATCH https://xabcloud.com/api/instances/{name}`,`{"label": "新备注名"}`。 - `DELETE https://xabcloud.com/api/instances/{name}?confirm={name}`:释放主机,磁盘数据立即销毁,剩余时长作废。密钥默认没有这项权限(回答 403):需要用户在控制台生成密钥时勾选允许,或由用户本人操作。执行前务必向用户确认。 - `GET https://xabcloud.com/api/orders`:订单记录。 ### 续费与到期 - 到期前 7 天、3 天、1 天,用户会收到邮件。没有自动扣款。 - 续费:`POST https://xabcloud.com/api/orders`,`{"kind": "renew", "instance": "xc-…", "period": "month", "quantity": 1}`,然后同样把付款码交给用户。时长加在原到期时间之后。 - 到期未续:主机停机(`suspended`),数据保留若干天(`/api/catalog` 的 `grace_days`,`instance.release_at` 是释放时间)。这期间续费,主机会重新启动(`resuming` → `running`),公网地址可能改变,以 `instance.ipv4` 为准。过期后主机被释放(`deleted`),数据无法找回。 ### 做不到的事 - 密钥不能生成或撤销密钥,也不能领取「临时登录凭证」(用户丢失私钥时的救急办法):这些要用户本人在控制台操作。 - 每个账户的主机数量有上限(`GET https://xabcloud.com/api/me` 的 `limits.max_instances`),超出时下单回答 409。 - 主机不得用于发送垃圾邮件、扫描或攻击他人、挖矿等用途,否则会被停机并封禁账户。 ### 管理员的密钥 管理员账户的密钥另外能读 `https://xabcloud.com/api/admin/` 之下的一切(只读),修改要在控制台里进行: - `/api/admin/overview`:账户数、各状态的主机数、收款和待处理事项 - `/api/admin/instances?q=&status=`、`/api/admin/instances/{name}`:全部主机,含所属邮箱、可用区和出错原因 - `/api/admin/orders?q=&status=`:全部订单,`status=attention` 是需要人工处理的 - `/api/admin/users?q=`:全部账户 - `/api/admin/plans`:全部套餐与地域,含停售的 ## English This guide is for agents: how to open and manage machines for your user. Every endpoint speaks JSON, and every address starts at https://xabcloud.com. ### What you need - **A key.** Ask your user to sign in at https://xabcloud.com/me/, generate one under 「Agent 密钥」 (Agent key) and hand it to you. Send `Authorization: Bearer xabc_…` with every request, and `Content-Type: application/json` when the body is JSON. - **An SSH public key.** Generate the key pair yourself, submit the public key, and leave the private key on your user's machine. This site never touches a private key. ssh-keygen -t ed25519 -N "" -f ~/.ssh/xabcloud -C xabcloud - **One payment from your user.** You cannot pay. After placing an order, hand the payment code to your user, who scans it with WeChat. An error is answered with `{"error": {"message": "…", "status": 4xx}}`. `message` is written in Chinese for the user, as are the names of plans and regions; translate them if your user reads another language, and refer to plans and regions by their `code`. ### Opening a machine 1. `GET https://xabcloud.com/api/catalog` (no key needed): the plans on sale (`plans`), the regions (`regions`), the system images (`images`) and the longest terms (`terms`). Prices are in fen, 100 to the yuan: `price_month_fen` for a month, `price_year_fen` for a year. Tell your user the plans and prices first, and let them choose. 2. `POST https://xabcloud.com/api/orders`: {"kind": "new", "plan": "starter", "region": "us-west-2", "period": "month", "quantity": 1, "label": "blog", "ssh_public_key": "ssh-ed25519 AAAA…"} `period` is `month` or `year`, and `quantity` is how many months (1–11) or years (1–3); `label` is an optional name of your own for the machine; `image` may be left out. In the answer, `order.out_trade_no` is the order number, `order.amount_fen` the amount due, and `payment` how to pay. 3. Hand the payment code to your user, in whichever way suits: - `GET https://xabcloud.com/api/orders/{out_trade_no}/qr.txt`: the QR code drawn in block characters, to print in the terminal as it is (add `?invert=1` for a terminal with a light background); - `payment.pay_page`: a page for the user to open in a browser, which shows the QR code once they are signed in; - `payment.code_url`: the WeChat Pay link, from which you can draw a QR code yourself. An order is good for 30 minutes (`payment.expires_at`). 4. Every few seconds, `GET https://xabcloud.com/api/orders/{out_trade_no}` until `order.status` is `paid`; `order.instance` is then the machine's name, which starts with `xc-`. `closed` means the order expired unpaid, and a new one has to be placed. 5. Every few seconds, `GET https://xabcloud.com/api/instances/{name}`. `instance.status` goes through `queued`, `creating` and `booting`, and reaches `running` after about two minutes; `instance.ssh_command` is then the command to log in, and `instance.ipv4` the public address. Log in with your private key: ssh -i ~/.ssh/xabcloud ubuntu@ The default account, `ubuntu`, has `sudo` without a password. The paid time starts when the machine reaches `running`, and `instance.paid_until` is when it ends. `failed` means something went wrong while the machine was being opened: the platform has been told and the paid time is not affected, so ask your user to wait. ### Managing machines - `GET https://xabcloud.com/api/instances`: every machine of this account. - `GET https://xabcloud.com/api/instances/{name}`: one machine and its history, `events`. - `POST https://xabcloud.com/api/instances/{name}/reboot`: reboot. - `PUT https://xabcloud.com/api/instances/{name}/ports`: the public firewall, replaced as a whole. 22, 80 and 443 are open by default: {"ports": [{"protocol": "tcp", "from": 22, "to": 22}, {"protocol": "tcp", "from": 8000, "to": 8100}]} `protocol` is `tcp` or `udp`. A port that is not in the list is closed; leave out 22 and SSH stops working. - `PATCH https://xabcloud.com/api/instances/{name}` with `{"label": "a new name"}`. - `DELETE https://xabcloud.com/api/instances/{name}?confirm={name}`: release the machine. Its disk is destroyed at once and the time left on it is forfeited. A key cannot do this by default (the answer is 403): the user has to allow it when generating the key in the console, or do it themselves. Always confirm with your user first. - `GET https://xabcloud.com/api/orders`: the account's orders. ### Renewal and expiry - The user is emailed 7 days, 3 days and 1 day before the time ends. Nothing is charged automatically. - To renew, `POST https://xabcloud.com/api/orders` with `{"kind": "renew", "instance": "xc-…", "period": "month", "quantity": 1}`, then hand the payment code to your user as before. The time is added after the current end. - A machine that is not renewed in time is stopped (`suspended`) and its data kept for some days (`grace_days` in `/api/catalog`; `instance.release_at` is when it will be released). Renewed within those days, it starts again (`resuming` → `running`); its public address may change, so read `instance.ipv4` again. After them it is released (`deleted`) and its data cannot be recovered. ### What cannot be done - A key cannot generate or revoke keys, nor obtain the temporary login credentials (the rescue for a user who has lost their private key): the user does these in the console. - An account may hold a limited number of machines (`limits.max_instances` in `GET https://xabcloud.com/api/me`); beyond it, an order is answered with 409. - Machines must not be used to send spam, to scan or attack others, to mine cryptocurrency and the like; a machine that is will be stopped and its account closed. ### An administrator's key The key of an administrator's account can also read everything under `https://xabcloud.com/api/admin/` (read only); changes are made in the console: - `/api/admin/overview`: the number of accounts, machines by status, income, and what is waiting for a person - `/api/admin/instances?q=&status=`, `/api/admin/instances/{name}`: every machine, with its owner's email, its availability zone and the reason for any failure - `/api/admin/orders?q=&status=`: every order; `status=attention` are the ones that need a person - `/api/admin/users?q=`: every account - `/api/admin/plans`: every plan and region, including those no longer on sale