{"title":"Computer Control API","slug":"computers","category":"api","summary":"远程控制已注册的计算机 — 排队命令、截屏、在远程机器上运行脚本。","audience":["human","llm"],"tags":["api","computers","remote-control","automation"],"difficulty":"advanced","updated":"2026-06-27","word_count":177,"read_minutes":1,"llm_context":"Two sides: user-facing (Mind Key/JWT) and agent-facing (Computer Token)\nRegister agent: POST /computers/register { install_code } → returns computer_token\nList: GET /computers/list (Mind Key or JWT)\nQueue command: POST /computers/:id/commands { type, payload }\nCommand types: screenshot, click, move, type, key, scroll, drag\nAgent poll: GET /computers/me/poll?wait=5 (Computer Token)\nAgent result: POST /computers/me/commands/:cid/result (Computer Token)\nOne-shot screenshot: GET /computers/:id/screenshot (waits 30s for result)\nPattern: register agent on remote machine → user queues commands → agent polls and executes\n","lang":"zh","translated":true,"requested_lang":"zh","content_markdown":"\n# Computer Control API\n\nComputer Control API 让你能够远程控制已注册的计算机。目标机器上会运行一个小型 Agent（`screen-remote-agent`），轮询命令、执行命令并回传结果。这使 LLM 驱动的 GUI 自动化成为可能。\n\n## 架构\n\n```\n┌─────────────┐  排队命令   ┌──────────┐  轮询  ┌─────────────────┐\n│ LLM Agent   │ ───────────▶ │ Synapse  │ ◀───── │ screen-remote   │\n│ (用户侧)    │              │  Server  │ ──────▶│ (在目标 PC 上) │\n└─────────────┘              └──────────┘ 结果   └─────────────────┘\n                                     ▲\n                                     │\n                              ┌─────────────┐\n                              │  Human UI   │\n                              │ (浏览器)    │\n                              └─────────────┘\n```\n\n## 用户侧端点（Mind Key 或 JWT）\n\n### GET /computers/list\n\n列出所有已注册的计算机。\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/computers/list\n```\n\n### GET /computers/:id\n\n获取单台计算机的详情。\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/computers/comp_001\n```\n\n### POST /computers/install-code\n\n为注册新计算机生成一个安装码。\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/computers/install-code \\\n  -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"computer_name\": \"office-mac\"}'\n```\n\n响应：`{ \"install_code\": \"ic_xyz789\", \"expires_at\": \"...\" }`\n\n### POST /computers/:id/commands\n\n为远程 Agent 排队一条待执行的命令。\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/computers/comp_001/commands \\\n  -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"type\": \"screenshot\",\n    \"payload\": {}\n  }'\n```\n\n响应：`{ \"command_id\": \"cmd_001\", \"status\": \"queued\" }`\n\n### GET /computers/:id/command（通过查询参数）\n\n通过 GET 方式排队命令（用于简单场景）。\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     \"https://synapse.schaefer.zone/computers/comp_001/command?type=screenshot\"\n```\n\n### GET /computers/:id/commands\n\n列出某台计算机最近的命令。\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     \"https://synapse.schaefer.zone/computers/comp_001/commands?limit=50\"\n```\n\n### GET /computers/:id/commands/:cid\n\n获取某条具体命令的状态与结果。\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/computers/comp_001/commands/cmd_001\n```\n\n### GET /computers/:id/screenshot\n\n一次性操作：排队截图命令并等待最多 30 秒拿结果。\n\n```bash\ncurl -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/computers/comp_001/screenshot > screenshot.png\n```\n\n### POST /computers/:id/disable\n\n禁用某台计算机（吊销其令牌，保留记录以备审计）。\n\n```bash\ncurl -X POST -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/computers/comp_001/disable\n```\n\n### DELETE /computers/:id\n\n永久删除某台计算机。\n\n```bash\ncurl -X DELETE -H \"Authorization: Bearer YOUR_MIND_KEY\" \\\n     https://synapse.schaefer.zone/computers/comp_001\n```\n\n## Agent 侧端点（Computer Token）\n\n以下端点由运行在目标机器上的 `screen-remote-agent` 使用。它们使用 Computer Token（由 `/computers/register` 返回），而不是 Mind Key。\n\n### POST /computers/register\n\n兑换安装码并获取 Computer Token。\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/computers/register \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"code\": \"ic_xyz789\",\n    \"computer_name\": \"office-mac\",\n    \"platform\": \"darwin\",\n    \"platform_release\": \"14.5.0\",\n    \"python\": \"3.12.4\"\n  }'\n```\n\n响应：`{ \"computer_id\": \"comp_001\", \"computer_token\": \"ct_...\" }`\n\n> [!CRITICAL]\n> 请妥善保存 `computer_token` — 它只显示一次，且所有 Agent 侧端点都需要它。\n\n### GET /computers/me/poll\n\n长轮询新命令。Agent 会在循环中调用此端点。\n\n```bash\ncurl -H \"Authorization: Bearer ct_YOUR_COMPUTER_TOKEN\" \\\n     \"https://synapse.schaefer.zone/computers/me/poll?wait=30\"\n```\n\n如果有待执行命令，则立即返回；否则等待 `wait` 秒后返回。\n\n### POST /computers/me/commands/:cid/result\n\n提交某条命令的执行结果。\n\n```bash\ncurl -X POST https://synapse.schaefer.zone/computers/me/commands/cmd_001/result \\\n  -H \"Authorization: Bearer ct_YOUR_COMPUTER_TOKEN\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"status\": \"done\",\n    \"result\": { \"screenshot_b64\": \"iVBORw0KG...\" }\n  }'\n```\n\n## 命令类型\n\n| 类型 | Payload | 说明 |\n|------|---------|-------------|\n| `screenshot` | `{}` | 截屏为 PNG（base64） |\n| `click` | `{x, y}` | 在指定坐标点击 |\n| `move` | `{x, y}` | 将鼠标移动到指定坐标 |\n| `type` | `{text}` | 在光标处输入文本 |\n| `key` | `{keys: [\"Ctrl\",\"c\"]}` | 按下组合键 |\n| `scroll` | `{deltaX, deltaY}` | 滚动滚轮 |\n| `drag` | `{fromX, fromY, toX, toY}` | 拖拽 |\n\n## 常见模式：LLM 驱动的 GUI 自动化\n\n```python\n# LLM Agent 工作流\n1. 列出计算机：GET /computers/list\n2. 截屏：GET /computers/:id/screenshot\n3. 分析截图（视觉模型）\n4. 排队点击：POST /computers/:id/commands {type:\"click\", payload:{x,y}}\n5. 等待结果：GET /computers/:id/commands/:cid\n6. 重新截屏验证\n7. 重复直到任务完成\n```\n\n## 下一步\n\n- [Browser 代理](/docs/api/browser) — 用于浏览器自动化的独立服务\n- [自托管 Agent 指南](/docs/guides/self-hosted-agents)\n","content_html":"<h1>Computer Control API</h1>\n<p>Computer Control API 让你能够远程控制已注册的计算机。目标机器上会运行一个小型 Agent（<code>screen-remote-agent</code>），轮询命令、执行命令并回传结果。这使 LLM 驱动的 GUI 自动化成为可能。</p>\n<h2>架构</h2>\n<pre><code class=\"hljs language-plaintext\">┌─────────────┐  排队命令   ┌──────────┐  轮询  ┌─────────────────┐\n│ LLM Agent   │ ───────────▶ │ Synapse  │ ◀───── │ screen-remote   │\n│ (用户侧)    │              │  Server  │ ──────▶│ (在目标 PC 上) │\n└─────────────┘              └──────────┘ 结果   └─────────────────┘\n                                     ▲\n                                     │\n                              ┌─────────────┐\n                              │  Human UI   │\n                              │ (浏览器)    │\n                              └─────────────┘</code></pre><h2>用户侧端点（Mind Key 或 JWT）</h2>\n<h3>GET /computers/list</h3>\n<p>列出所有已注册的计算机。</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/computers/list</code></pre><h3>GET /computers/:id</h3>\n<p>获取单台计算机的详情。</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/computers/comp_001</code></pre><h3>POST /computers/install-code</h3>\n<p>为注册新计算机生成一个安装码。</p>\n<pre><code class=\"hljs language-bash\">curl -X POST https://synapse.schaefer.zone/computers/install-code \\\n  -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{&quot;computer_name&quot;: &quot;office-mac&quot;}&#x27;</span></code></pre><p>响应：<code>{ &quot;install_code&quot;: &quot;ic_xyz789&quot;, &quot;expires_at&quot;: &quot;...&quot; }</code></p>\n<h3>POST /computers/:id/commands</h3>\n<p>为远程 Agent 排队一条待执行的命令。</p>\n<pre><code class=\"hljs language-bash\">curl -X POST https://synapse.schaefer.zone/computers/comp_001/commands \\\n  -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{\n    &quot;type&quot;: &quot;screenshot&quot;,\n    &quot;payload&quot;: {}\n  }&#x27;</span></code></pre><p>响应：<code>{ &quot;command_id&quot;: &quot;cmd_001&quot;, &quot;status&quot;: &quot;queued&quot; }</code></p>\n<h3>GET /computers/:id/command（通过查询参数）</h3>\n<p>通过 GET 方式排队命令（用于简单场景）。</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/computers/comp_001/command?type=screenshot&quot;</span></code></pre><h3>GET /computers/:id/commands</h3>\n<p>列出某台计算机最近的命令。</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/computers/comp_001/commands?limit=50&quot;</span></code></pre><h3>GET /computers/:id/commands/:cid</h3>\n<p>获取某条具体命令的状态与结果。</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/computers/comp_001/commands/cmd_001</code></pre><h3>GET /computers/:id/screenshot</h3>\n<p>一次性操作：排队截图命令并等待最多 30 秒拿结果。</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/computers/comp_001/screenshot &gt; screenshot.png</code></pre><h3>POST /computers/:id/disable</h3>\n<p>禁用某台计算机（吊销其令牌，保留记录以备审计）。</p>\n<pre><code class=\"hljs language-bash\">curl -X POST -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/computers/comp_001/disable</code></pre><h3>DELETE /computers/:id</h3>\n<p>永久删除某台计算机。</p>\n<pre><code class=\"hljs language-bash\">curl -X DELETE -H <span class=\"hljs-string\">&quot;Authorization: Bearer YOUR_MIND_KEY&quot;</span> \\\n     https://synapse.schaefer.zone/computers/comp_001</code></pre><h2>Agent 侧端点（Computer Token）</h2>\n<p>以下端点由运行在目标机器上的 <code>screen-remote-agent</code> 使用。它们使用 Computer Token（由 <code>/computers/register</code> 返回），而不是 Mind Key。</p>\n<h3>POST /computers/register</h3>\n<p>兑换安装码并获取 Computer Token。</p>\n<pre><code class=\"hljs language-bash\">curl -X POST https://synapse.schaefer.zone/computers/register \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{\n    &quot;code&quot;: &quot;ic_xyz789&quot;,\n    &quot;computer_name&quot;: &quot;office-mac&quot;,\n    &quot;platform&quot;: &quot;darwin&quot;,\n    &quot;platform_release&quot;: &quot;14.5.0&quot;,\n    &quot;python&quot;: &quot;3.12.4&quot;\n  }&#x27;</span></code></pre><p>响应：<code>{ &quot;computer_id&quot;: &quot;comp_001&quot;, &quot;computer_token&quot;: &quot;ct_...&quot; }</code></p>\n<div class=\"callout callout-critical\">请妥善保存 `computer_token` — 它只显示一次，且所有 Agent 侧端点都需要它。</div><h3>GET /computers/me/poll</h3>\n<p>长轮询新命令。Agent 会在循环中调用此端点。</p>\n<pre><code class=\"hljs language-bash\">curl -H <span class=\"hljs-string\">&quot;Authorization: Bearer ct_YOUR_COMPUTER_TOKEN&quot;</span> \\\n     <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/computers/me/poll?wait=30&quot;</span></code></pre><p>如果有待执行命令，则立即返回；否则等待 <code>wait</code> 秒后返回。</p>\n<h3>POST /computers/me/commands/:cid/result</h3>\n<p>提交某条命令的执行结果。</p>\n<pre><code class=\"hljs language-bash\">curl -X POST https://synapse.schaefer.zone/computers/me/commands/cmd_001/result \\\n  -H <span class=\"hljs-string\">&quot;Authorization: Bearer ct_YOUR_COMPUTER_TOKEN&quot;</span> \\\n  -H <span class=\"hljs-string\">&quot;Content-Type: application/json&quot;</span> \\\n  -d <span class=\"hljs-string\">&#x27;{\n    &quot;status&quot;: &quot;done&quot;,\n    &quot;result&quot;: { &quot;screenshot_b64&quot;: &quot;iVBORw0KG...&quot; }\n  }&#x27;</span></code></pre><h2>命令类型</h2>\n<table>\n<thead>\n<tr>\n<th>类型</th>\n<th>Payload</th>\n<th>说明</th>\n</tr>\n</thead>\n<tbody><tr>\n<td><code>screenshot</code></td>\n<td><code>{}</code></td>\n<td>截屏为 PNG（base64）</td>\n</tr>\n<tr>\n<td><code>click</code></td>\n<td><code>{x, y}</code></td>\n<td>在指定坐标点击</td>\n</tr>\n<tr>\n<td><code>move</code></td>\n<td><code>{x, y}</code></td>\n<td>将鼠标移动到指定坐标</td>\n</tr>\n<tr>\n<td><code>type</code></td>\n<td><code>{text}</code></td>\n<td>在光标处输入文本</td>\n</tr>\n<tr>\n<td><code>key</code></td>\n<td><code>{keys: [&quot;Ctrl&quot;,&quot;c&quot;]}</code></td>\n<td>按下组合键</td>\n</tr>\n<tr>\n<td><code>scroll</code></td>\n<td><code>{deltaX, deltaY}</code></td>\n<td>滚动滚轮</td>\n</tr>\n<tr>\n<td><code>drag</code></td>\n<td><code>{fromX, fromY, toX, toY}</code></td>\n<td>拖拽</td>\n</tr>\n</tbody></table>\n<h2>常见模式：LLM 驱动的 GUI 自动化</h2>\n<pre><code class=\"hljs language-python\"><span class=\"hljs-comment\"># LLM Agent 工作流</span>\n<span class=\"hljs-number\">1.</span> 列出计算机：GET /computers/<span class=\"hljs-built_in\">list</span>\n<span class=\"hljs-number\">2.</span> 截屏：GET /computers/:<span class=\"hljs-built_in\">id</span>/screenshot\n<span class=\"hljs-number\">3.</span> 分析截图（视觉模型）\n<span class=\"hljs-number\">4.</span> 排队点击：POST /computers/:<span class=\"hljs-built_in\">id</span>/commands {<span class=\"hljs-built_in\">type</span>:<span class=\"hljs-string\">&quot;click&quot;</span>, payload:{x,y}}\n<span class=\"hljs-number\">5.</span> 等待结果：GET /computers/:<span class=\"hljs-built_in\">id</span>/commands/:cid\n<span class=\"hljs-number\">6.</span> 重新截屏验证\n<span class=\"hljs-number\">7.</span> 重复直到任务完成</code></pre><h2>下一步</h2>\n<ul>\n<li><a href=\"/docs/api/browser\">Browser 代理</a> — 用于浏览器自动化的独立服务</li>\n<li><a href=\"/docs/guides/self-hosted-agents\">自托管 Agent 指南</a></li>\n</ul>\n","urls":{"html":"/docs/api/computers","text":"/docs/api/computers?format=text","json":"/docs/api/computers?format=json","llm":"/docs/api/computers?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}