HTTP 接口参考
每台运行 ketec 的 iPhone 都在局域网里提供这套 HTTP 接口。机器可读版本:/api/openapi.json (OpenAPI 3.1, 99 个接口).
Every phone running ketec hosts its own HTTP server. The address (phone IP and port) is shown on the App status page; the default port is 9800. Use phone-ip in examples as a placeholder for that address.
ketec runs in one of two modes:
- Agent mode: no extra hardware; touches, typing and UI-tree reading are injected through the iOS system testing/automation service.
- HID mode: an ESP32-S3 USB HID device plugged into the phone performs touches and key presses.
/api/control/* and /api/source are for Agent mode (in HID mode most /api/control/* calls are forwarded to the HID channel; w3cActions is Agent-only). /api/hid/* is for HID mode and needs the ESP32-S3 device for touch and key input. Each operation lists its modes in x-modes.
Conventions:
- Most endpoints are
GETwith query parameters; the server does not check the HTTP method. Endpoints documented asPOSTread a request body (JSON or binary). - Query values must be URL-encoded;
+decodes to a space, so send a literal plus as%2B. - Coordinates are physical screen pixels, the same as the screenshot pixels.
- Responses are JSON shaped like
{"success": bool, "data": ..., "message"?: string, "reason"?: string}unless stated otherwise (images, streams, file downloads, the log endpoints).message/reasonare human-readable (usually Chinese) and not stable; checksuccessand documented fields. - Missing or invalid parameters return HTTP 400; unknown paths return 404
{"success": false, "reason": "Not Found"}. Many action failures still use HTTP 200 withsuccess: false. - If the device license is not valid, most endpoints return
{"success": false, "error": "license", "message": ...}.
Security: there is no authentication. Anyone who can reach the port can control the phone, read the clipboard and files, and delete photos. Use it only on a trusted local network and never expose the port to the internet.
The /v1/heartbeat operation (tag License Service) runs on the cloud license service https://api.ketec.top, not on the phone; it is listed for reference.
Base URL: http://{phoneIp}:{port} (default port 9800)
设备
设备状态、截图、已安装应用、锁屏状态、亮度、音量与运行模式切换。
GET /api/status — 获取软件与设备状态
返回设备标识、屏幕尺寸、电量、当前运行模式、Agent/HID 可用性、脚本与录屏状态。对象里还包含额外的诊断字段,不属于稳定契约。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/status"
返回:
{
"success": true,
"data": {
"apiVersion": "330v223",
"appName": "ketec",
"appBundleId": "top.ketec.app",
"appVersion": "1.0.0",
"appBuildNumber": 330.223,
"bundleVersion": "330.223",
"appNo": "",
"deviceName": "iPhone",
"deviceModel": "iPhone13,2",
"osVersion": "16.1.1",
"deviceIp": "phone-ip",
"deviceId": "<device-id>",
"serverDeviceId": "<server-device-id>",
"udid": "<udid>",
"ecid": "<ecid>",
"orientation": "PORTRAIT",
"screenInfo": {
"width": 1170,
"height": 2532,
"scale": 3,
"logicWidth": 390,
"logicHeight": 844
},
"batteryInfo": {
"level": 87,
"isCharging": true
},
"volume": 0.5,
"brightness": 0.6,
"isLocked": false,
"selectedRunMode": "agent",
"agentConnected": true,
"agentAvailable": true,
"isHidConnected": false,
"hidModel": "",
"hidVersion": "",
"isRun": false,
"isShowUI": false,
"isRecording": false,
"isBroadcastConnected": false,
"isMirrorLive": false,
"isAuth": true,
"isLogin": true,
"isDebugMode": false,
"isVolumeControlEnabled": false,
"uptime": 86400,
"scriptModules": [
"appleOcr",
"device",
"action",
"hid",
"file",
"http",
"config",
"system",
"media",
"ime",
"app",
"node"
]
}
}GET /api/apps — 获取已安装应用列表
返回用户安装的应用。每项包含 appName、bundleIdentifier、bundleVersion(以及兼容旧调用方的 name、bundleId)。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/apps"
返回:
{
"success": true,
"data": [
{
"appName": "Settings",
"bundleIdentifier": "com.apple.Preferences",
"bundleVersion": "1.0",
"name": "Settings",
"bundleId": "com.apple.Preferences"
}
]
}GET /api/isLocked — 是否锁屏
返回锁屏状态。请结合 locked 与 source(结论来自哪一级判定:notify、keybag、display 或 none)一起读;data 是同值的兼容字段。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/isLocked"
返回:
{
"success": true,
"data": false,
"locked": false,
"source": "notify",
"diag": {
"notify": 0,
"keybag": 1,
"displayPower": "unavailable"
}
}GET /api/screenshot — 截图(二进制图片)
返回当前屏幕的 JPEG 或 PNG(以 Content-Type 为准)。图片像素与设备物理分辨率一致,在图上量得的坐标可直接用于点击接口。
运行模式: agent, hid
参数:
method(query, string; default "auto"; one of auto, xct, broadcast, replaykit, render, shortcuts): 截图通道。auto 依次尝试 xct、broadcast、replaykit、render。xct = 系统测试服务(Agent 模式);broadcast = 正在运行的屏幕直播的最新帧;replaykit = 进程内 ReplayKit;render = 仅 ketec 自己的窗口;shortcuts = 经 HID 设备触发辅助快捷指令(auto 不会选)。显式指定的通道失败不回落。meta(query, integer; default 0; one of 0, 1): 为 1 时只返回 JSON 回执(通道、字节数、尺寸),不返回图片。
示例:
curl "http://phone-ip:9800/api/screenshot"
返回: image/jpeg
GET /api/screenshotBase64 — 截图(Base64)
与 /api/screenshot 相同的截图,以 JSON 返回:data 为 Base64 图片,contentType 为图片类型。
运行模式: agent, hid
参数:
method(query, string; default "auto"; one of auto, xct, broadcast, replaykit, render, shortcuts): 截图通道。auto 依次尝试 xct、broadcast、replaykit、render。xct = 系统测试服务(Agent 模式);broadcast = 正在运行的屏幕直播的最新帧;replaykit = 进程内 ReplayKit;render = 仅 ketec 自己的窗口;shortcuts = 经 HID 设备触发辅助快捷指令(auto 不会选)。显式指定的通道失败不回落。meta(query, integer; default 0; one of 0, 1): 为 1 时只返回 JSON 回执(通道、字节数、尺寸),不返回图片。
示例:
curl "http://phone-ip:9800/api/screenshotBase64"
返回:
{
"success": true,
"method": "xct",
"bytes": 412345,
"w": 1170,
"h": 2532,
"format": "jpeg",
"blank": false,
"elapsedMs": 180,
"needsUserAction": false,
"contentType": "image/jpeg",
"data": "/9j/4AAQSkZJRgABAQ..."
}GET /api/takeMeToFront — App 切到前台
把 ketec 自身切到前台;已在前台时返回 alreadyFront=true。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/takeMeToFront"
返回:
{
"success": true,
"data": {
"bundleId": "top.ketec.app",
"alreadyFront": true
}
}GET /api/getScreenBrightness — 获取屏幕亮度
返回屏幕亮度,范围 0–1(保留两位小数)。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/getScreenBrightness"
返回:
{
"success": true,
"data": 0.6
}GET /api/setScreenBrightness — 设置屏幕亮度
设置屏幕亮度。传 brightness(或别名 value),范围 0–1。
运行模式: agent, hid
参数:
brightness(query, required, number): 亮度 0–1。别名:value。
示例:
curl "http://phone-ip:9800/api/setScreenBrightness?brightness=0.5"
返回:
{
"success": true
}GET /api/getVolume — 获取设备音量
返回系统输出音量,范围 0–1(保留两位小数)。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/getVolume"
返回:
{
"success": true,
"data": 0.5
}GET /api/setVolume — 设置设备音量
设置系统输出音量。传 volume(或别名 value),范围 0–1。
运行模式: agent, hid
参数:
volume(query, required, number): 音量 0–1。别名:value。
示例:
curl "http://phone-ip:9800/api/setVolume?volume=0.3"
返回:
{
"success": true
}GET /api/getRunMode — 获取当前运行模式
返回当前选择的运行模式(agent 或 hid)以及两个通道当前是否可用。也可通过 /api/control/getRunMode 访问。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/getRunMode"
返回:
{
"success": true,
"data": {
"runMode": "agent",
"agentAvailable": true,
"isHidConnected": false
}
}GET /api/setRunMode — 切换运行模式
在 Agent 与 HID 模式之间切换。切到 hid 会立即断开 Agent 自动化会话;Agent 通道不可用时切到 agent 会被拒绝(HTTP 409)。也可通过 /api/control/setRunMode 访问。
运行模式: agent, hid
参数:
mode(query, required, string; one of agent, hid): 目标运行模式。
示例:
curl "http://phone-ip:9800/api/setRunMode?mode=hid"
返回:
{
"success": true,
"data": {
"runMode": "hid",
"agentAvailable": true,
"isHidConnected": true
}
}脚本与软件包
执行 JavaScript 片段;上传、加载、运行、停止脚本软件包。
POST /api/runScript — 执行脚本(仅 JS)
在内置引擎中执行 JavaScript,返回最后一个表达式的值(无需写 return),例如 appleOcr.recognize('screen')。脚本串行执行;超过 timeout 秒接口先返回,脚本可能仍在继续运行。
运行模式: agent, hid
参数:
timeout(query, number; default 15): 等待结果的秒数,超时先返回。
请求体 (JSON):
{
"script": "let a = 1;\na + 1;"
}示例:
curl -X POST "http://phone-ip:9800/api/runScript" \
-H "Content-Type: application/json" \
-d '{"script": "let a = 1;\na + 1;"}'返回:
{
"success": true,
"resultType": "number",
"result": 2,
"data": {
"result": 2,
"logs": [],
"durationMs": 3
}
}GET /api/run — 运行脚本(当前软件包)
启动当前已加载软件包的入口脚本(见 /api/load、/api/sync)。若带 script 或 code 参数,则行为与 /api/runScript 相同。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/run"
返回:
{
"success": true,
"message": "运行成功"
}GET /api/runUI — 运行 UI
在 App 内显示当前已加载软件包的配置界面(isShowUI 变为 true)。软件包没有入口脚本时失败。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/runUI"
返回:
{
"success": true,
"message": "UI运行成功"
}GET /api/stop — 停止脚本
请求停止正在运行的软件包脚本(或正在执行的 /api/runScript 脚本)。没有脚本在运行时返回 success=false。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/stop"
返回:
{
"success": true,
"message": "停止成功"
}GET /api/load — 加载指定软件包
把指定 appNo 的软件包设为当前包;本地没有时先下载。脚本运行中会被拒绝。
运行模式: agent, hid
参数:
appNo(query, required, string): 软件包编号。
示例:
curl "http://phone-ip:9800/api/load?appNo=demo"
返回:
{
"success": true,
"message": "加载成功",
"data": {
"softwareName": "demo",
"downloaded": false,
"appNo": "demo"
}
}POST /api/sync — 同步脚本(上传软件包)
以原始请求体上传打包好的脚本工程(zip),并设为当前包。zip 根目录必须有名为 appId 的文件,其内容即软件包 appNo。
运行模式: agent, hid
参数:
projectName(query, string): 工程显示名(缺省为 appId)。
示例:
curl -X POST "http://phone-ip:9800/api/sync" \
-H "Content-Type: application/json" \
-d '{}'返回:
{
"success": true,
"message": "同步成功"
}Agent 控制
经 Agent 通道(无需硬件)进行点击、输入、按键、应用控制与读取界面树。面向 Agent 模式;HID 模式下大部分 /api/control/* 会转由 HID 通道执行。
GET /api/source — 节点 XML(界面树)
以 XML 返回前台 App 的无障碍元素树(XCUIElementType* 节点,含 frame、label、value 等)。仅 Agent 模式。meta=1 时改为返回 JSON 摘要而不是 XML。
运行模式: agent
参数:
mode(query, integer; default 1; one of 1, 2, 3): 抓取模式,与脚本 createNodeSelector({mode}) 的三种模式相同。1 = 一次取整棵树(每个节点 22 个属性、深度 50、子节点不限),默认值,最快最稳定。2 = 分段拼接:每次请求取 2 层、每个节点 13 个属性,再对每个被截断的节点单独请求、把子树挂回原位;适合长列表和很深的界面,较慢(每个容器一次请求)。3 = 分段拼接,每次只取 1 层(13 个属性,每层最多 256 个子节点)。模式 2 和 3 把子树挂回原位,不会返回重复节点。pid(query, integer): 要读取的 App 进程号;不传则读取前台 App。meta(query, integer; default 0; one of 0, 1): 为 1 时返回 JSON 元信息(目标、节点数、字节数、耗时),不返回 XML。max_depth(query, integer): 兼容参数;默认采集引擎忽略。timeout(query, integer): 兼容参数;默认采集引擎忽略。
示例:
curl "http://phone-ip:9800/api/source"
返回: text/xml
GET /api/activeAppInfo — 获取前台 App
返回当前前台 App 的名称、bundleId 与 pid(取自界面树根节点)。仅 Agent 模式(HID 模式请用 /api/hid/currentAppInfo)。
运行模式: agent
示例:
curl "http://phone-ip:9800/api/activeAppInfo"
返回:
{
"success": true,
"data": {
"name": "Settings",
"bundleId": "com.apple.Preferences",
"pid": 1234
}
}GET /api/control/click — 点击
在指定坐标点击(物理像素)。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
参数:
x(query, required, number): X 坐标(物理像素)。y(query, required, number): Y 坐标(物理像素)。duration(query, integer; default 0): 按住时长(毫秒)。jitter(query, boolean; default false): 对点击位置加少量随机偏移。
示例:
curl "http://phone-ip:9800/api/control/click?x=540&y=1200"
返回:
{
"success": true
}GET /api/control/doubleClick — 双击
在指定坐标双击(物理像素)。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
参数:
x(query, required, number): X 坐标(物理像素)。y(query, required, number): Y 坐标(物理像素)。duration(query, integer): 每次按下时长(毫秒)。interval(query, integer): 两次点击的间隔(毫秒)。jitter(query, boolean; default false): 加少量随机偏移。
示例:
curl "http://phone-ip:9800/api/control/doubleClick?x=540&y=1200"
返回:
{
"success": true
}GET /api/control/swipe — 滑动
从 (startX,startY) 滑到 (endX,endY),单位物理像素。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
参数:
startX(query, required, number): 起点 X(像素)。startY(query, required, number): 起点 Y(像素)。endX(query, required, number): 终点 X(像素)。endY(query, required, number): 终点 Y(像素)。duration(query, integer): 滑动时长(毫秒)。jitter(query, boolean; default false): 使用略带抖动的拟人轨迹。steps(query, integer): 轨迹中间点数量。
示例:
curl "http://phone-ip:9800/api/control/swipe?startX=540&startY=1800&endX=540&endY=600"
返回:
{
"success": true
}GET /api/control/input — 输入文字
向当前焦点输入框输入文字,需键盘已弹出。支持任意 Unicode 文本;ketec 键盘在屏时经键盘扩展插入。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
参数:
text(query, required, string): 要输入的文字。需 URL 编码;"+" 会被解码成空格,加号本身请写 %2B。
示例:
curl "http://phone-ip:9800/api/control/input?text=你好 ketec"
返回:
{
"success": true,
"data": "你好 ketec",
"elapsedMs": 120
}GET /api/control/inputSimple — 输入字符(逐键)
按逐键节奏输入文字(约每秒 15 字),适用于需要逐个按键事件的输入框。需键盘已弹出。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
参数:
text(query, required, string): 要输入的文字(URL 编码;加号写 %2B)。
示例:
curl "http://phone-ip:9800/api/control/inputSimple?text=abc123"
返回:
{
"success": true,
"data": "abc123",
"elapsedMs": 420
}GET /api/control/backspace — 退格
删除光标前的字符,需键盘已弹出。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
参数:
count(query, integer; default 1): 删除字符数。
示例:
curl "http://phone-ip:9800/api/control/backspace"
返回:
{
"success": true
}GET /api/control/enter — 回车
按回车键,需键盘已弹出。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
示例:
curl "http://phone-ip:9800/api/control/enter"
返回:
{
"success": true
}GET /api/control/home — 返回主页
回到主屏幕。Agent 通道没有硬件按键实现:请求会转交 HID 设备执行,只有连着 ESP32-S3 HID 设备时才有效,否则返回 success=false。
运行模式: agent
示例:
curl "http://phone-ip:9800/api/control/home"
返回:
{
"success": true,
"channel": "hid",
"button": "home"
}GET /api/control/recent — App 切换器
打开多任务切换器。与 /api/control/home 相同,需要连接 HID 设备。
运行模式: agent
示例:
curl "http://phone-ip:9800/api/control/recent"
返回:
{
"success": true,
"channel": "hid",
"button": "recent"
}GET /api/control/pressButton — 按按钮
经 HID 设备按下按钮(需连接 HID 设备,见 /api/control/home)。eject 显示/隐藏屏幕键盘;power 发送 Ctrl+Cmd+Q(iOS 锁屏快捷键);snapshot 发送 Cmd+Shift+3(系统截屏)。
运行模式: agent
参数:
button(query, required, string; one of home, volumeup, volumedown, mute, playpause, next, prev, brightnessup, brightnessdown, eject, globe, recent, search, snapshot, power): 按钮名(区分大小写)。appswitch 是 recent 的别名。
示例:
curl "http://phone-ip:9800/api/control/pressButton?button=volumeup"
返回:
{
"success": true,
"channel": "hid",
"button": "volumeup"
}POST /api/control/sendKey — 发送组合键
按下单键或组合键,如 ["COMMAND","a"]。键可以是单个字符或键名:COMMAND、LEFT_SHIFT、LEFT_CTRL、LEFT_ALT、RETURN、ESC、BACKSPACE、TAB、SPACE、DELETE、HOME、END、PAGE_UP、PAGE_DOWN、方向键 UP_ARROW 等、F1–F12;数字按 USB HID usage 码处理。也接受逗号分隔的查询参数 keys。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
请求体 (JSON):
{
"keys": [
"COMMAND",
"a"
]
}示例:
curl -X POST "http://phone-ip:9800/api/control/sendKey" \
-H "Content-Type: application/json" \
-d '{"keys": ["COMMAND", "a"]}'返回:
{
"success": true
}POST /api/control/w3cActions — W3C 动作序列
执行 W3C WebDriver actions:pointer 源(touch 或 mouse),步骤支持 pointerMove、pointerDown、pointerUp、pause;多个 pointer 源即多指手势。坐标为物理像素,时长单位毫秒。不支持的类型会明确报错。仅 Agent 模式(HID 模式下不转投)。
运行模式: agent
请求体 (JSON):
{
"actions": [
{
"type": "pointer",
"id": "finger1",
"parameters": {
"pointerType": "touch"
},
"actions": [
{
"type": "pointerMove",
"duration": 0,
"x": 540,
"y": 1800
},
{
"type": "pointerDown",
"button": 0
},
{
"type": "pointerMove",
"duration": 300,
"x": 540,
"y": 600
},
{
"type": "pointerUp",
"button": 0
}
]
}
]
}示例:
curl -X POST "http://phone-ip:9800/api/control/w3cActions" \
-H "Content-Type: application/json" \
-d '{"actions": [{"type": "pointer", "id": "finger1", "parameters": {"pointerType": "touch"}, "actions": [{"type": "pointerMove", "duration": 0, "x": 540, "y": 1800}, {"type": "pointerDown", "button": 0}, {"type": "pointerMove", "duration": 300, "x": 540, "y": 600}, {"type": "pointerUp", "button": 0}]}]}'返回:
{
"success": true
}GET /api/control/startApp — 打开 App
按 bundleId 启动 App。Agent 调用失败时会回落到系统 workspace 接口,并在回包中标记 deviation=true。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
参数:
bundleId(query, required, string): 目标 App 的 bundleId。
示例:
curl "http://phone-ip:9800/api/control/startApp?bundleId=com.apple.Preferences"
返回:
{
"success": true,
"via": "xct-ag",
"strict": false,
"bundleId": "com.apple.Preferences",
"action": "startApp"
}GET /api/control/activateApp — 激活 App(拉到前台)
把指定 bundleId 的 App 拉到前台,未运行时会启动。Agent 调用失败时会回落到系统 workspace 接口,并在回包中标记 deviation=true。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
参数:
bundleId(query, required, string): 目标 App 的 bundleId。
示例:
curl "http://phone-ip:9800/api/control/activateApp?bundleId=com.apple.Preferences"
返回:
{
"success": true,
"via": "xct-ag",
"strict": false,
"bundleId": "com.apple.Preferences",
"action": "activateApp"
}GET /api/control/stopApp — 停止 App
结束指定 bundleId 的 App 进程。Agent 调用失败时会回落到系统 workspace 接口,并在回包中标记 deviation=true。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
参数:
bundleId(query, required, string): 目标 App 的 bundleId。
示例:
curl "http://phone-ip:9800/api/control/stopApp?bundleId=com.apple.Preferences"
返回:
{
"success": true,
"via": "xct-ag",
"strict": false,
"bundleId": "com.apple.Preferences",
"action": "stopApp"
}GET /api/control/openURL — 打开 URL
用系统打开 URL 或 URL scheme(如 https://…、prefs:…)。处于 HID 模式时,该请求会改由 HID 通道执行。
运行模式: agent
参数:
url(query, required, string): 要打开的 URL(需 URL 编码)。
示例:
curl "http://phone-ip:9800/api/control/openURL?url=https://example.com"
返回:
{
"success": true
}HID 控制
经 ESP32-S3 USB HID 设备进行点击、输入与按键。在 HID 模式下、插着设备时使用。坐标为物理像素。
GET /api/hid/click — 点击(HID)
经 ESP32-S3 HID 设备在指定坐标点击。坐标为物理像素(与截图 1:1),不是逻辑点。回包给出请求坐标、实际发送坐标以及是否越界。
运行模式: hid
参数:
x(query, required, number): X 坐标(物理像素)。y(query, required, number): Y 坐标(物理像素)。duration(query, integer): 按住时长(毫秒)。mode(query, string; one of drag): drag = 按下、小幅移动、抬起;对部分系统弹框和菜单按钮更可靠。
示例:
curl "http://phone-ip:9800/api/hid/click?x=540&y=1200"
返回:
{
"success": true,
"data": {
"requested": {
"x": 540,
"y": 1200
},
"sent": {
"x": 540,
"y": 1200
},
"screenPx": {
"width": 1170,
"height": 2532
},
"outOfRange": false,
"mode": "absClick",
"pointerMode": "absolute",
"hint": "ok"
}
}GET /api/hid/doubleClick — 双击(HID)
经 HID 设备双击。坐标为物理像素(与截图 1:1),不是逻辑点。
运行模式: hid
参数:
x(query, required, number): X 坐标(物理像素)。y(query, required, number): Y 坐标(物理像素)。duration(query, integer; default 20): 每次按下时长(毫秒)。interval(query, integer; default 100): 两次点击间隔(毫秒)。
示例:
curl "http://phone-ip:9800/api/hid/doubleClick?x=540&y=1200"
返回:
{
"success": true
}GET /api/hid/swipe — 滑动(HID)
经 HID 设备沿多点轨迹滑动。坐标为物理像素(与截图 1:1),不是逻辑点。
运行模式: hid
参数:
startX(query, required, number): 起点 X(像素)。startY(query, required, number): 起点 Y(像素)。endX(query, required, number): 终点 X(像素)。endY(query, required, number): 终点 Y(像素)。jitter(query, boolean; default false): 中间点加随机偏移。steps(query, integer; default 10): 轨迹分段数。duration(query, integer; default 0): 大致总时长(毫秒,0 = 固件默认速度)。
示例:
curl "http://phone-ip:9800/api/hid/swipe?startX=540&startY=1800&endX=540&endY=600"
返回:
{
"success": true
}GET /api/hid/move — 移动坐标(HID)
把 HID 指针移动到指定位置(不按下)。配合 mouseDown / mouseUp 可组合自定义拖拽。坐标为物理像素(与截图 1:1),不是逻辑点。
运行模式: hid
参数:
x(query, required, number): X 坐标(物理像素)。y(query, required, number): Y 坐标(物理像素)。
示例:
curl "http://phone-ip:9800/api/hid/move?x=540&y=1200"
返回:
{
"success": true
}GET /api/hid/mouseDown — 鼠标按下(HID)
在当前 HID 指针位置按下并保持,直到调用 /api/hid/mouseUp。
运行模式: hid
示例:
curl "http://phone-ip:9800/api/hid/mouseDown"
返回:
{
"success": true
}GET /api/hid/mouseUp — 鼠标抬起(HID)
抬起 HID 指针。
运行模式: hid
示例:
curl "http://phone-ip:9800/api/hid/mouseUp"
返回:
{
"success": true
}GET /api/hid/input — 输入文字(HID)
HID 模式下输入文字(需键盘已弹出)。顺序:ketec 键盘在屏时走键盘扩展,否则经 HID 设备「剪贴板 + Cmd+V」。stage 表示实际走的路径;stage 为 3-custom1 时无法确认是否上屏。
运行模式: hid
参数:
text(query, required, string): 要输入的文字(任意 Unicode;URL 编码,加号写 %2B)。也可用 JSON 请求体 {"text": ...}。
示例:
curl "http://phone-ip:9800/api/hid/input?text=你好"
返回:
{
"success": true,
"data": true,
"stage": "2-clipboard"
}GET /api/hid/inputSimple — 输入字符(HID,仅 ASCII)
以逐个按键方式输入可打印 ASCII 字符(需键盘已弹出)。非 ASCII 文本返回 400;中文等请用 /api/hid/input。
运行模式: hid
参数:
text(query, required, string): 要输入的 ASCII 文本(URL 编码;加号写 %2B)。
示例:
curl "http://phone-ip:9800/api/hid/inputSimple?text=abc123"
返回:
{
"success": true
}GET /api/hid/backspace — 退格(HID)
经 HID 设备发送退格键(需键盘已弹出)。
运行模式: hid
参数:
count(query, integer; default 1): 按键次数。
示例:
curl "http://phone-ip:9800/api/hid/backspace"
返回:
{
"success": true
}GET /api/hid/enter — 回车(HID)
经 HID 设备发送回车键(需键盘已弹出)。
运行模式: hid
示例:
curl "http://phone-ip:9800/api/hid/enter"
返回:
{
"success": true
}GET /api/hid/home — 返回主页(HID)
经 HID 设备发送 Home 键。
运行模式: hid
示例:
curl "http://phone-ip:9800/api/hid/home"
返回:
{
"success": true
}GET /api/hid/recent — App 切换器(HID)
经 HID 设备连按两次 Home 打开多任务。
运行模式: hid
示例:
curl "http://phone-ip:9800/api/hid/recent"
返回:
{
"success": true
}GET /api/hid/pressButton — 按按钮(HID)
经 HID 设备按下按钮。eject 切换屏幕键盘显示(可选 state=show|hide),并在 data 中给出详情;power 发送 Ctrl+Cmd+Q(iOS 锁屏快捷键);snapshot 发送 Cmd+Shift+3(系统截屏)。未知按钮名返回 success=false。
运行模式: hid
参数:
button(query, required, string; one of home, volumeup, volumedown, mute, playpause, next, prev, brightnessup, brightnessdown, eject, globe, recent, search, snapshot, power): 按钮名(区分大小写)。state(query, string; one of show, hide): 仅 button=eject:强制显示或隐藏,而不是切换。
示例:
curl "http://phone-ip:9800/api/hid/pressButton?button=home"
返回:
{
"success": true
}POST /api/hid/sendKey — 发送组合键(HID)
经 HID 设备按下组合键,如 ["COMMAND","v"]。键可以是单个字符或键名:COMMAND、ENTER/RETURN、ESC、BACKSPACE、TAB、SPACE、CAPS_LOCK、INSERT、HOME、END、PAGE_UP、PAGE_DOWN、DELETE、方向键;数字按固件键码透传。也接受逗号分隔的查询参数 keys。
运行模式: hid
请求体 (JSON):
{
"keys": [
"COMMAND",
"v"
]
}示例:
curl -X POST "http://phone-ip:9800/api/hid/sendKey" \
-H "Content-Type: application/json" \
-d '{"keys": ["COMMAND", "v"]}'返回:
{
"success": true
}GET /api/hid/openApp — 打开 App
按 App 名称或 bundleId 启动 App,不依赖 HID 硬件。
运行模式: hid
参数:
name(query, required, string): App 名称或 bundleId(别名:bundleId)。
示例:
curl "http://phone-ip:9800/api/hid/openApp?name=Settings"
返回:
{
"success": true,
"data": {
"bundleId": "com.apple.Preferences"
}
}GET /api/hid/closeApp — 关闭 App
按 App 名称或 bundleId 结束 App。系统拒绝且连着 HID 设备时,ketec 用手势关闭(打开该 App → 回主屏 → 多任务 → 上划卡片),回包 via=hid-gesture。
运行模式: hid
参数:
name(query, required, string): App 名称或 bundleId(别名:bundleId)。
示例:
curl "http://phone-ip:9800/api/hid/closeApp?name=Settings"
返回:
{
"success": true,
"data": {
"bundleId": "com.apple.Preferences",
"via": "terminate"
}
}GET /api/hid/openURL — 打开 URL(HID 模式)
打开 URL。优先经 ketec 辅助快捷指令打开(ketec 在后台也可用,可处理不带 scheme 的地址),否则本地打开,无 scheme 时自动补 https://。
运行模式: hid
参数:
url(query, required, string): 要打开的 URL(需 URL 编码)。
示例:
curl "http://phone-ip:9800/api/hid/openURL?url=https://example.com"
返回:
{
"success": true,
"data": {
"url": "https://example.com"
}
}GET /api/hid/currentAppInfo — 获取前台 App(HID 模式)
不经 Agent 通道获取前台 App 的 bundleId 与名称。无法判断时返回失败与 message。
运行模式: hid
示例:
curl "http://phone-ip:9800/api/hid/currentAppInfo"
返回:
{
"success": true,
"data": {
"bundleId": "com.apple.Preferences",
"name": "Settings"
}
}GET /api/hid/deviceInfo — 获取 HID 设备信息
返回 ESP32-S3 HID 设备是否连接,以及最近一次上报的型号、固件版本、MAC 地址;同时请求设备刷新这些信息。
运行模式: hid
示例:
curl "http://phone-ip:9800/api/hid/deviceInfo"
返回:
{
"success": true,
"data": {
"connected": true,
"model": "<model>",
"version": "<firmware-version>",
"mac": "<mac>",
"lastResponse": "",
"transmitted": 128
}
}GET /api/hid/restartDevice — 重启 HID 设备
向 ESP32-S3 固件发送重启命令(不会重启手机)。设备会重新 USB 枚举,重连前的几秒内 HID 控制不可用。
运行模式: hid
示例:
curl "http://phone-ip:9800/api/hid/restartDevice"
返回:
{
"success": true
}GET /api/hid/shortcutScreenshot — 快捷指令截图
经 HID 设备触发 ketec 辅助快捷指令截屏;需已安装辅助快捷指令并连接 HID 设备。可能耗时数秒(超时 20 秒)。返回 PNG。
运行模式: hid
示例:
curl "http://phone-ip:9800/api/hid/shortcutScreenshot"
返回: image/png
GET /api/hid/shortcutScreenshotBase64 — 快捷指令截图 Base64
经 HID 设备触发 ketec 辅助快捷指令截屏;需已安装辅助快捷指令并连接 HID 设备。可能耗时数秒(超时 20 秒)。data 为 Base64 编码的 PNG。
运行模式: hid
示例:
curl "http://phone-ip:9800/api/hid/shortcutScreenshotBase64"
返回:
{
"success": true,
"data": "iVBORw0KGgoAAAANSUhEUgAA..."
}输入法(键盘)
经 ketec 键盘扩展输入文字(/api/ime/*)。大多数接口需要已启用 ketec 键盘且屏幕上有键盘弹出。
GET /api/ime/isOk — API 键盘是否可用
ketec 键盘已安装且当前可见时 success 为 true。data 给出详情(当前输入法、是否为 ketec 键盘、扩展最近一次心跳距今时长)。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/ime/isOk"
返回:
{
"success": true,
"superset": true,
"data": {
"keyboardInstalled": true,
"keyboardVisible": true,
"currentInputModeIdentifier": "<input-mode-id>",
"targetInputModeIdentifier": "<input-mode-id>",
"isOurKeyboard": true,
"lastPollAgoMs": 120,
"neverPolled": false
}
}GET /api/ime/input — 输入文字(API 键盘)
需在 iOS 设置中添加 ketec 键盘(并开启完全访问),且屏幕上有键盘弹出。若当前是其他键盘,ketec 会先切换到自己的键盘,再整段插入文字(任意 Unicode,含表情)。没有键盘弹出时失败并给出 reason。
运行模式: agent, hid
参数:
text(query, required, string): 要插入的文字(URL 编码;加号写 %2B)。也可用 JSON 请求体 {"text": ...}。
示例:
curl "http://phone-ip:9800/api/ime/input?text=你好👋"
返回:
{
"success": true,
"via": "unix-socket",
"data": "你好👋",
"readbackLen": 4,
"extKeyboardVisible": true
}GET /api/ime/paste — 粘贴文本(API 键盘)
需在 iOS 设置中添加 ketec 键盘(并开启完全访问),且屏幕上有键盘弹出。不带 text 时由键盘扩展粘贴当前剪贴板内容;带 text 时插入该文本。
运行模式: agent, hid
参数:
text(query, string): 可选,代替剪贴板内容插入的文本。
示例:
curl "http://phone-ip:9800/api/ime/paste"
返回:
{
"success": true,
"via": "unix-socket",
"readbackLen": 12
}GET /api/ime/getText — 获取已输入文本
需在 iOS 设置中添加 ketec 键盘(并开启完全访问),且屏幕上有键盘弹出。返回键盘看到的焦点输入框中光标前的文本。系统可能截断长文本;没有输入会话时返回空字符串。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/ime/getText"
返回:
{
"success": true,
"via": "unix-socket",
"data": "hello",
"readbackLen": 5
}GET /api/ime/clearText — 清空文本
需在 iOS 设置中添加 ketec 键盘(并开启完全访问),且屏幕上有键盘弹出。删除光标前的文字直到输入框为空(长文本分轮删除)。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/ime/clearText"
返回:
{
"success": true,
"via": "unix-socket",
"readbackLen": 0,
"deletedCount": 5,
"superset": true
}GET /api/ime/pressDel — 按删除键
需在 iOS 设置中添加 ketec 键盘(并开启完全访问),且屏幕上有键盘弹出。删除光标前的字符。
运行模式: agent, hid
参数:
count(query, integer; default 1): 删除字符数。
示例:
curl "http://phone-ip:9800/api/ime/pressDel"
返回:
{
"success": true,
"via": "unix-socket",
"readbackLen": 4,
"deletedCount": 1,
"superset": true
}GET /api/ime/pressEnter — 按回车键
需在 iOS 设置中添加 ketec 键盘(并开启完全访问),且屏幕上有键盘弹出。插入回车(换行或提交,取决于输入框)。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/ime/pressEnter"
返回:
{
"success": true,
"via": "unix-socket"
}GET /api/ime/dismiss — 隐藏键盘
需在 iOS 设置中添加 ketec 键盘(并开启完全访问),且屏幕上有键盘弹出。收起键盘。扩展无法收起且连着 HID 设备时,ketec 会点击键盘外区域;否则失败,reason 为 keyboard_still_visible。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/ime/dismiss"
返回:
{
"success": true,
"via": "unix-socket"
}GET /api/ime/getClipboard — 获取剪贴板(API 键盘)
需在 iOS 设置中添加 ketec 键盘(并开启完全访问),且屏幕上有键盘弹出。经键盘扩展读取剪贴板,可避开 iOS 的「允许粘贴」弹窗。键盘不可用时返回空字符串。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/ime/getClipboard"
返回:
{
"success": true,
"data": "copied text",
"length": 11,
"chars": 11,
"source": "http-fallback"
}GET /api/ime/setClipboard — 设置剪贴板
把文本写入系统剪贴板(不依赖键盘)。能读回一致时 verified 为 "true",被 iOS 拦截读不到时为 "unknown"。
运行模式: agent, hid
参数:
text(query, required, string): 要写入的文本,原样保留(URL 编码;加号写 %2B)。也可用 JSON 请求体 {"text": ...}。
示例:
curl "http://phone-ip:9800/api/ime/setClipboard?text=hello"
返回:
{
"success": true,
"data": {
"via": "uipasteboard",
"written": true,
"verified": "true",
"len": 5,
"encoding": 5,
"chars": 5
}
}剪贴板与配置
主 App 读写系统剪贴板,以及 App 键值配置。
GET /api/getClipboard — 获取剪贴板
由主 App 读取系统剪贴板。iOS 可能拦截该读取(粘贴权限),此时返回 needsUserPermission=true,建议改用 /api/ime/getClipboard。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/getClipboard"
返回:
{
"success": true,
"data": "copied text",
"meta": {
"data": "copied text",
"source": "system",
"changeCount": 42
}
}GET /api/setClipboard — 设置剪贴板
把文本写入系统剪贴板,原样保留(首尾空格不裁剪)。
运行模式: agent, hid
参数:
text(query, required, string): 要写入的文本(别名:value;URL 编码,加号写 %2B)。也可用 JSON 请求体 {"text": ...}。
示例:
curl "http://phone-ip:9800/api/setClipboard?text=hello"
返回:
{
"success": true
}GET /api/getAllConfig — 获取所有配置
返回 App 的键值配置:data 为对象,json 为同内容的 JSON 字符串。值均为字符串。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/getAllConfig"
返回:
{
"success": true,
"data": {
"runMode": "agent"
},
"json": "{\"runMode\":\"agent\"}"
}GET /api/setConfig — 设置配置项
设置一个配置项。key 与 value 只从查询串读取(不读 JSON 请求体),因此用 POST 也可以,但参数必须放在查询串里。key=runMode 时会同时切换运行模式。
运行模式: agent, hid
参数:
key(query, required, string): 配置键。value(query, string): 配置值(不传则为空字符串)。
示例:
curl "http://phone-ip:9800/api/setConfig?key=runMode"
返回:
{
"success": true
}POST /api/setAllConfig — 设置所有配置
把 JSON 请求体中的键值合并进配置。非字符串值按字符串形式保存;请求体未包含的已有键保持不变。
运行模式: agent, hid
请求体 (JSON):
{
"theme": "dark",
"retry": "3"
}示例:
curl -X POST "http://phone-ip:9800/api/setAllConfig" \
-H "Content-Type: application/json" \
-d '{"theme": "dark", "retry": "3"}'返回:
{
"success": true
}文件
管理 App 沙盒(Documents 或临时目录)中的文件。
GET /api/file/list — 获取文件列表
递归列出沙盒根目录(或 path 子目录)下的文件与文件夹,最多 5000 项,按路径排序;文件夹 size 为 0。路径相对所选沙盒根目录;包含 ".." 会被拒绝。
运行模式: agent, hid
参数:
dirType(query, string; default "documents"; one of documents, temp): 沙盒根目录:App 的 Documents 目录或临时目录。path(query, string): 可选,要列出的子目录。
示例:
curl "http://phone-ip:9800/api/file/list"
返回:
{
"success": true,
"data": [
{
"name": "records",
"path": "records",
"isDirectory": true,
"size": 0,
"modified": 1764460800
},
{
"name": "a.txt",
"path": "a.txt",
"isDirectory": false,
"size": 12,
"modified": 1764460800
}
]
}GET /api/file/exists — 判断文件是否存在
返回路径是否存在以及是否为文件夹。路径相对所选沙盒根目录;包含 ".." 会被拒绝。
运行模式: agent, hid
参数:
dirType(query, string; default "documents"; one of documents, temp): 沙盒根目录:App 的 Documents 目录或临时目录。path(query, required, string): 相对路径。
示例:
curl "http://phone-ip:9800/api/file/exists?path=a.txt"
返回:
{
"success": true,
"data": {
"exists": true,
"isDirectory": false
}
}POST /api/file/upload — 上传文件
把原始请求体写入 path(自动创建上级目录,已存在则覆盖),上限 200 MB。路径相对所选沙盒根目录;包含 ".." 会被拒绝。
运行模式: agent, hid
参数:
dirType(query, string; default "documents"; one of documents, temp): 沙盒根目录:App 的 Documents 目录或临时目录。path(query, required, string): 目标相对路径(含文件名)。
示例:
curl -X POST "http://phone-ip:9800/api/file/upload?path=scripts/main.js" \
-H "Content-Type: application/json" \
-d '{}'返回:
{
"success": true,
"data": {
"path": "/scripts/main.js",
"bytes": 1024
}
}GET /api/file/download — 下载文件
以 application/octet-stream 返回文件内容。录屏文件保存在 documents 的 records/ 下。路径相对所选沙盒根目录;包含 ".." 会被拒绝。
运行模式: agent, hid
参数:
dirType(query, string; default "documents"; one of documents, temp): 沙盒根目录:App 的 Documents 目录或临时目录。path(query, required, string): 文件相对路径。
示例:
curl "http://phone-ip:9800/api/file/download?path=a.txt"
返回: application/octet-stream
GET /api/file/delete — 删除文件
删除 path 处的文件(或文件夹)。路径相对所选沙盒根目录;包含 ".." 会被拒绝。
运行模式: agent, hid
参数:
dirType(query, string; default "documents"; one of documents, temp): 沙盒根目录:App 的 Documents 目录或临时目录。path(query, required, string): 相对路径。
示例:
curl "http://phone-ip:9800/api/file/delete?path=a.txt"
返回:
{
"success": true
}GET /api/file/deleteDir — 删除目录
删除 path 处的文件夹及其全部内容;目标不是文件夹时失败。路径相对所选沙盒根目录;包含 ".." 会被拒绝。
运行模式: agent, hid
参数:
dirType(query, string; default "documents"; one of documents, temp): 沙盒根目录:App 的 Documents 目录或临时目录。path(query, required, string): 文件夹相对路径。
示例:
curl "http://phone-ip:9800/api/file/deleteDir?path=tmp"
返回:
{
"success": true
}媒体
把图片/视频保存到系统相册,以及批量删除相册媒体。
POST /api/media/saveImageToAlbum — 保存图片到相册
把图片保存到系统相册。支持原始二进制、multipart/form-data(可多文件)、带 Base64 data 的 JSON,或用 url 下载。按文件头识别类型,上限 200 MB。首次调用会在手机上弹出相册授权。
运行模式: agent, hid
参数:
filename(query, string): 文件名;扩展名用于辅助识别格式。url(query, string): 改为下载该 http/https 链接并保存(无需请求体)。
请求体 (JSON):
{
"data": "iVBORw0KGgo...",
"filename": "a.png"
}示例:
curl -X POST "http://phone-ip:9800/api/media/saveImageToAlbum" \
-H "Content-Type: application/json" \
-d '{"data": "iVBORw0KGgo...", "filename": "a.png"}'返回:
{
"success": true,
"data": {
"filename": "photo.jpg",
"bytes": 5364,
"kind": "image",
"success": true,
"localIdentifier": "<asset-id>"
}
}POST /api/media/saveVideoToAlbumPath — 保存视频到相册
把视频保存到系统相册(建议 H.264 的 .mp4 / .mov)。支持原始二进制、multipart/form-data(可多文件)、带 Base64 data 的 JSON,或用 url 下载。按文件头识别类型,上限 200 MB。首次调用会在手机上弹出相册授权。
运行模式: agent, hid
参数:
filename(query, string): 文件名;扩展名用于辅助识别格式。url(query, string): 改为下载该 http/https 链接并保存(无需请求体)。
请求体 (JSON):
{
"data": "iVBORw0KGgo...",
"filename": "a.png"
}示例:
curl -X POST "http://phone-ip:9800/api/media/saveVideoToAlbumPath" \
-H "Content-Type: application/json" \
-d '{"data": "iVBORw0KGgo...", "filename": "a.png"}'返回:
{
"success": true,
"data": {
"filename": "photo.jpg",
"bytes": 5364,
"kind": "image",
"success": true,
"localIdentifier": "<asset-id>"
}
}POST /api/media/save — 保存图片/视频到相册(自动识别)
统一入口:每个文件按内容自动识别为图片或视频后保存。支持原始二进制、multipart/form-data(可多文件)、带 Base64 data 的 JSON,或用 url 下载。按文件头识别类型,上限 200 MB。首次调用会在手机上弹出相册授权。也可通过 /api/media/upload 访问。
运行模式: agent, hid
参数:
filename(query, string): 文件名;扩展名用于辅助识别格式。url(query, string): 改为下载该 http/https 链接并保存(无需请求体)。
请求体 (JSON):
{
"data": "iVBORw0KGgo...",
"filename": "a.png"
}示例:
curl -X POST "http://phone-ip:9800/api/media/save" \
-H "Content-Type: application/json" \
-d '{"data": "iVBORw0KGgo...", "filename": "a.png"}'返回:
{
"success": true,
"data": {
"filename": "photo.jpg",
"bytes": 5364,
"kind": "image",
"success": true,
"localIdentifier": "<asset-id>"
}
}GET /api/media/deleteAllPhotos — 删除相册所有图片
提交删除相册中全部图片(含截屏)的请求并立即返回。随后 iOS 会弹出确认框,用户确认后才真正删除(进入「最近删除」)。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/media/deleteAllPhotos"
返回:
{
"success": true,
"data": {
"submitted": 12,
"kind": "照片",
"note": "已提交,系统会弹「允许删除」确认框,用户确认后才真正删除"
}
}GET /api/media/deleteAllVideos — 删除相册所有视频
提交删除相册中全部视频的请求并立即返回。随后 iOS 会弹出确认框,用户确认后才真正删除(进入「最近删除」)。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/media/deleteAllVideos"
返回:
{
"success": true,
"data": {
"submitted": 12,
"kind": "视频",
"note": "已提交,系统会弹「允许删除」确认框,用户确认后才真正删除"
}
}GET /api/media/deleteAllScreenshots — 删除相册所有截屏
提交删除相册中全部截屏图片的请求并立即返回。随后 iOS 会弹出确认框,用户确认后才真正删除(进入「最近删除」)。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/media/deleteAllScreenshots"
返回:
{
"success": true,
"data": {
"submitted": 12,
"kind": "截图",
"note": "已提交,系统会弹「允许删除」确认框,用户确认后才真正删除"
}
}日志
读取与下载 App 日志。
GET /logger/files — 日志列表
返回 App 日志文件列表,按时间倒序。响应体是 JSON 数组(没有 success 外层)。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/logger/files"
返回:
[
{
"filePath": "<app-sandbox>/Documents/logs/ketec.log",
"fileName": "ketec.log",
"modificationDate": "2026-11-30T08:00:00Z",
"fileSize": "120 KB"
}
]GET /logger/download — 下载日志
以 application/octet-stream 返回日志文件内容。不传 fileName 时返回(按文件名排序的)最新一个。
运行模式: agent, hid
参数:
fileName(query, string): 来自 /logger/files 的文件名。
示例:
curl "http://phone-ip:9800/logger/download"
返回: application/octet-stream
GET /logger/current/lines — 获取当前实时日志
返回当前日志最后 count 行(去掉空行)。hasMore=true 表示前面还有更早的行。响应体没有 success 字段。
运行模式: agent, hid
参数:
count(query, integer; default 200): 返回行数。
示例:
curl "http://phone-ip:9800/logger/current/lines"
返回:
{
"lines": [
"[12:00:01] script started",
"[12:00:02] click 540,1200"
],
"hasMore": true
}屏幕镜像
实时屏幕流(MJPEG、H.264 FLV)与录屏。实时流需要 ketec 屏幕直播正在运行。
GET /mirror/image — 实时屏幕流 MJPEG
需要 ketec 屏幕直播正在运行(iOS 要求用户在系统直播选择器 / 控制中心里手动开始一次)。以 multipart/x-mixed-replace(boundary 为 kcframe)持续推送 JPEG 帧,直到客户端断开;可直接放进 <img> 标签。也可通过 /api/mirror/image、/api/mirror/mjpeg 访问。
运行模式: agent, hid
参数:
scalingFactor(query, number; default 1): 输出尺寸 = 设备像素 × 系数。用画面坐标点击前请先除以该系数。
示例:
curl "http://phone-ip:9800/mirror/image"
返回: multipart/x-mixed-replace; boundary=kcframe
GET /mirror/flv — 实时屏幕流 H264 HTTP-FLV
需要 ketec 屏幕直播正在运行(iOS 要求用户在系统直播选择器 / 控制中心里手动开始一次)。以 FLV 封装(video/x-flv)持续推送 H.264 视频,直到客户端断开;可用 flv.js、ffplay 等播放。也可通过 /api/mirror/flv 访问。
运行模式: agent, hid
参数:
fps(query, integer; default 10): 目标帧率。scalingFactor(query, number; default 1): 输出尺寸 = 设备像素 × 系数。bitrate(query, number; default 4): 目标码率(Mbit/s)。quality(query, number): 兼容参数,无实际效果(请用 scalingFactor)。
示例:
curl "http://phone-ip:9800/mirror/flv"
返回: video/x-flv
GET /api/hid/openRecordScreen — 开始录屏
开始录制 MP4。屏幕直播在运行时录整屏,否则只录 ketec 自己的窗口。文件保存在 documents 沙盒的 records/ 下(用 /api/file/download 下载)。两种模式均可用;也可通过 /api/control/startRecordScreen 访问。
运行模式: agent, hid
参数:
fps(query, integer; default 10): 录制帧率(1–30)。source(query, string; one of broadcast, internal): 帧来源。缺省:屏幕直播已连接时为 broadcast,否则为 internal(ketec 窗口)。
示例:
curl "http://phone-ip:9800/api/hid/openRecordScreen"
返回:
{
"success": true,
"data": {
"isRecording": true,
"fps": 10,
"frames": 0,
"duration": 0,
"path": "rec-20261130-120000.mp4",
"captureSource": "broadcast",
"frameSource": "broadcast",
"canCaptureFullScreen": true,
"broadcastSupported": true,
"lastBroadcastEvent": "started",
"lastBroadcastAt": 1764504000
}
}GET /api/hid/closeRecordScreen — 停止录屏
停止当前录制,文件在后台完成写入(saving=true)。未在录制时返回 success=false。也可通过 /api/control/stopRecordScreen 访问。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/hid/closeRecordScreen"
返回:
{
"success": true,
"data": {
"name": "rec-20261130-120000.mp4",
"saving": true
}
}GET /api/hid/isRecording — 获取录屏状态
ketec 正在录制或屏幕直播正在运行时返回 true(与 /api/status 的 isRecording 同口径)。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/hid/isRecording"
返回:
{
"success": true,
"data": false
}账号与授权
从电脑给手机登录 / 退出(TokenKey、账号主 key 或账号密码),以及查询授权状态。设备未授权时这些接口也会应答。许可由 App 向云端授权服务校验;云端没有远程给设备登录的接口,要在局域网里逐台调用手机上的这些接口。
GET /api/license — 查询设备授权状态
返回本机授权状态:是否已授权(valid / isLogin)、原因、用账号登录时的账号名、当前所用 key 的前 8 位、许可的设备上限、在线数和到期时间。未授权时也会正常应答。调用 /api/login 后许可在后台验证,轮询本接口直到 reason 不再是 checking。
运行模式: agent, hid
示例:
curl "http://phone-ip:9800/api/license"
返回:
{
"success": true,
"data": {
"enforced": true,
"valid": true,
"reason": "ok",
"message": "已授权",
"builtIn": false,
"hasKey": true,
"account": "",
"isLogin": true,
"key": "4F0DCB53…",
"deviceId": "<device-id>",
"expiresAt": 1827851075,
"maxDevices": 1500,
"online": 12,
"lastOK": 1796000100,
"lastCheck": 1796000100,
"server": "https://api.ketec.top"
}
}POST /api/login — 给设备登录(TokenKey 或账号密码)
给这台手机登录,让它使用某个账号的许可。二选一:传 key(账号主 key 或 TokenKey,别名 token / tokenKey),或传 username + password;带了 username 就按账号密码登录。传 key 时立即保存,并在后台验证(data.reason = checking)。账号密码登录会等授权服务回包(最多 20 秒),成功后保存该账号的 key。手机上原来的 key 或账号会被替换,并让出它占的在线席位。参数放 JSON 体或查询串都可以。设备未授权时也能调用。内置了授权码的安装包会返回失败。
运行模式: agent, hid
请求体 (JSON):
{
"tokenKey": "4F0DCB53-478C-456A-AFA9-E682F56FE73A"
}示例:
curl -X POST "http://phone-ip:9800/api/login" \
-H "Content-Type: application/json" \
-d '{"tokenKey": "4F0DCB53-478C-456A-AFA9-E682F56FE73A"}'返回:
{
"success": true,
"data": {
"enforced": true,
"valid": false,
"reason": "checking",
"message": "正在验证授权…",
"builtIn": false,
"hasKey": true,
"account": "",
"isLogin": false,
"key": "4F0DCB53…",
"deviceId": "<device-id>",
"expiresAt": 0,
"maxDevices": 0,
"online": 0,
"lastOK": 0,
"lastCheck": 1796000000,
"server": "https://api.ketec.top"
}
}POST /api/license/activate — 写入授权码(TokenKey 或账号主 key)
等同于用 key 调 /api/login:保存 key 并在后台验证。结果轮询 /api/license(reason 为 unknown_key = key 不存在,token_revoked = TokenKey 已作废)。
运行模式: agent, hid
请求体 (JSON):
{
"key": "4F0DCB53-478C-456A-AFA9-E682F56FE73A"
}示例:
curl -X POST "http://phone-ip:9800/api/license/activate" \
-H "Content-Type: application/json" \
-d '{"key": "4F0DCB53-478C-456A-AFA9-E682F56FE73A"}'返回:
{
"success": true,
"data": {
"enforced": true,
"valid": false,
"reason": "checking",
"message": "正在验证授权…",
"builtIn": false,
"hasKey": true,
"account": "",
"isLogin": false,
"key": "4F0DCB53…",
"deviceId": "<device-id>",
"expiresAt": 0,
"maxDevices": 0,
"online": 0,
"lastOK": 0,
"lastCheck": 1796000000,
"server": "https://api.ketec.top"
}
}POST /api/register — 注册账号并给设备登录
在授权服务上注册新账号,并用它给这台手机登录(最多等 20 秒)。新账号在购买前没有设备许可,所以验证后 data.reason 会是 expired。用户名 3–32 位,以字母或数字开头,可用字母、数字和 _ . @ -;密码 6–64 位。
运行模式: agent, hid
请求体 (JSON):
{
"username": "studio-a",
"password": "••••••••"
}示例:
curl -X POST "http://phone-ip:9800/api/register" \
-H "Content-Type: application/json" \
-d '{"username": "studio-a", "password": "••••••••"}'返回:
{
"success": true,
"data": {
"enforced": true,
"valid": false,
"reason": "checking",
"message": "正在验证授权…",
"builtIn": false,
"hasKey": true,
"account": "studio-a",
"isLogin": false,
"key": "4F0DCB53…",
"deviceId": "<device-id>",
"expiresAt": 0,
"maxDevices": 0,
"online": 0,
"lastOK": 0,
"lastCheck": 1796000000,
"server": "https://api.ketec.top"
}
}POST /api/logout — 给设备退出登录
清掉手机上的 key / 账号,并在授权服务上让出它的在线席位。之后大多数接口会返回授权错误,直到重新登录。别名:/api/license/logout。
运行模式: agent, hid
示例:
curl -X POST "http://phone-ip:9800/api/logout" \
-H "Content-Type: application/json" \
-d '{}'返回:
{
"success": true,
"data": {
"enforced": true,
"valid": false,
"reason": "no_key",
"message": "未登录:请登录账号或输入授权码",
"builtIn": false,
"hasKey": false,
"account": "",
"isLogin": false,
"key": "",
"deviceId": "<device-id>",
"expiresAt": 0,
"maxDevices": 0,
"online": 0,
"lastOK": 0,
"lastCheck": 1796000000,
"server": "https://api.ketec.top"
}
}授权服务
App 与云端授权服务(api.ketec.top)之间的心跳。App 每 60 秒自动发送,这里仅供参考,一般不需要自己调用。
POST /v1/heartbeat — 授权心跳(参考)
App 每 60 秒带着授权码(账号密钥或 TokenKey)和设备标识发一次。回包是签名信封:payload 是 JSON 字符串,sig 是对该字符串的 Ed25519 签名,App 用内置公钥验签,并核对 payload.key、deviceId、nonce 与发出的一致(用 TokenKey 时 key 回显 TokenKey)。ok: false 时 reason 为机器可读原因:bad_request、unknown_key、token_revoked、disabled、expired、kicked、device_limit。
运行模式: agent, hid
请求体 (JSON):
{
"key": "3F2A9C1E-7B4D-4E8A-9C21-5D6E7F809A1B",
"deviceId": "<device-id>",
"nonce": "6F1D2C3B-…",
"model": "iPhone13,2",
"ios": "26.5",
"appVersion": "330v240",
"name": "iPhone"
}示例:
curl -X POST "https://api.ketec.top/v1/heartbeat" \
-H "Content-Type: application/json" \
-d '{"key": "3F2A9C1E-7B4D-4E8A-9C21-5D6E7F809A1B", "deviceId": "<device-id>", "nonce": "6F1D2C3B-…", "model": "iPhone13,2", "ios": "26.5", "appVersion": "330v240", "name": "iPhone"}'返回:
{
"payload": "{\"key\":\"3F2A9C1E-7B4D-4E8A-9C21-5D6E7F809A1B\",\"deviceId\":\"<device-id>\",\"nonce\":\"6F1D2C3B-…\",\"serverTime\":1796300000,\"heartbeat\":60,\"ok\":true,\"reason\":\"ok\",\"message\":\"已授权\",\"maxDevices\":10,\"expiresAt\":1827843558,\"online\":3,\"customer\":\"studio-a\"}",
"sig": "<base64 Ed25519 签名>"
}