DocsReference
API reference
Every device HTTP endpoint: method, path, auth, parameters, request and reply fields, examples and error codes. Generated from openapi.json.
This reference is generated from the device API definition openapi.json (OpenAPI 3.1), the same file the API page of the device web app uses. For pairing, signing, actions and timelines, see HTTP API.
OpenAPI 3.1, with descriptions in Chinese and English (English in x-en). Import it into Postman and similar tools, or hand it to an agent.
Groups#
Device#
Device info, status, logs, screen language, time zone, BOOT button events, identify and restart. info and nonce are open; the rest need signing
| Endpoint | Description | Marks |
|---|---|---|
GET /v1/info | Device info: ID, firmware, memory, Wi-Fi, OTA slots, microSD card, web app version | |
GET /v1/nonce | Get a one-time nonce for signing (valid 60 s; authenticated replies also carry X-Stick-Nonce) | |
GET /v1/status | Status bus snapshot: current states and events | |
GET /v1/logs | Log ring | |
POST /v1/identify | Identify: screen and LED signal for 5 s | |
POST /v1/reboot | Restart 0.5 s after replying | |
GET /v1/lang | Screen (system UI) language: zh / en; chosen means someone picked it | |
POST /v1/lang | Set the screen language; saved and applied immediately | |
GET /v1/time | Time and time zone (POSIX TZ + IANA name) | |
POST /v1/time | Set the time zone; applied immediately | |
GET /v1/button | BOOT button event ring (click / double-click / long press / hold; stop marks emergency stop) |
Wi-Fi#
Saved networks (up to 3), switching and forgetting; during Wi-Fi setup, the open /prov/* endpoints used by the setup page on the hotspot. When a phone joins the setup hotspot, the captive portal redirects (302) GETs with no route to the setup page (not an endpoint). Only a person enters Wi-Fi passwords, on the setup page or in Settings of the device web app; host tools and agents never handle them
| Endpoint | Description | Marks |
|---|---|---|
GET /v1/wifi | Saved networks (up to 3, most recent first, no passwords) and the current one | |
POST /v1/wifi | Set as candidate and switch to it in about 1.5 s; saved only once joined, otherwise returns to a saved network | |
POST /v1/wifi/forget | Forget a network; without ssid, clear all and enter Wi-Fi setup (device goes offline until set up from a phone) | |
GET /prov/status | Setup page polling: candidate network result (Wi-Fi setup only) | |
GET /prov/scan | Nearby networks (Wi-Fi setup only) | |
POST /prov/wifi | Setup page submit (form ssid, pass; Wi-Fi setup only) | |
POST /prov/forget | Setup page forgets a network (form ssid; Wi-Fi setup only) | |
POST /prov/lang | Setup page sets the screen language (form lang=zh|en; Wi-Fi setup only) | |
POST /prov/leave | Leave setup: drop the candidate, close the hotspot, return to a saved network (Wi-Fi setup only) |
Pairing#
A browser, or an agent on a new computer, gets the pairing key over Wi-Fi: the device screen shows a 4-digit code; click BOOT to allow, double-click to deny. Kernel only; in the rescue firmware use the key command over USB serial
| Endpoint | Description | Marks |
|---|---|---|
POST /v1/pair | Request pairing: the screen shows a 4-digit code; click BOOT to allow (30 s) | |
GET /v1/pair | Pairing result; the first query after approval includes the key |
HID keyboard and mouse#
Send keyboard, mouse and media input to the connected computer over Wi-Fi: arm first (a lease), then send actions or a timeline; the BOOT button and disarm stop it at any time. Also timelines on the microSD card, the monitor screen and the USB mode
| Endpoint | Description | Marks |
|---|---|---|
GET /v1/hid | HID state: lease left, queue, held keys, LEDs (Num / Caps / Scroll) | |
POST /v1/hid | Send keyboard and mouse actions (keys go to the foreground window) | |
POST /v1/hid/arm | Arm HID output (lease; disarms and releases all keys on expiry). Call again to renew | |
POST /v1/hid/disarm | Emergency stop and disarm | |
POST /v1/hid/timeline | Timeline (6-byte records, executed at their scheduled times) | |
POST /v1/hid/play_file | Stream a timeline file from the microSD card | |
GET /v1/hid/play_file | Playback state of the card timeline | |
POST /v1/hid/play_file/stop | Stop playback | |
GET /v1/monitor | Monitor screen state (right side: name, mode, step, progress) | |
POST /v1/monitor | Set the monitor screen state (replaces it) | |
POST /v1/usb | USB mode hid / serial; restarts after replying (no keyboard or mouse in serial) |
Apps and macros#
Lua apps on the device, one running at a time: list, start, stop, start on boot, delete, message, read events and run code in the app. The macro player is the app macro, controlled through POST /v1/apps/msg
| Endpoint | Description | Marks |
|---|---|---|
GET /v1/apps | Apps, the running app, start on boot, memory | |
POST /v1/apps/start | Start an app (the macro player is macro) | |
POST /v1/apps/stop | Stop the current app and return home | |
POST /v1/apps/auto | Set or clear start on boot (id null clears) | |
POST /v1/apps/delete | Delete an app folder (keeps its data folder) | |
POST /v1/apps/msg | Message the running app; macro player: select / run / stop / reload / plan | |
GET /v1/apps/events | Events emitted by apps (app.emit) | |
POST /v1/eval | Run code in the app’s Lua state (can call hid; take care) |
Storage files#
Files in the device storage (littlefs): apps /apps/<id>/, app data /data/<id>/, fonts /fonts/, device web app /www/. Files are read and written whole, ≤ 2 MB
| Endpoint | Description | Marks |
|---|---|---|
GET /v1/fs/list | List a storage folder (up to 256 entries) | |
GET /v1/fs | Read a storage file (whole file) | |
PUT /v1/fs | Write a storage file (≤ 2 MB; replaces an existing one) | |
DELETE /v1/fs | Delete a storage file or folder (recursive=1 deletes its contents) |
microSD card#
Files on the microSD card (FAT). Read and written in chunks of ≤ 1 MB per request (256 KB on the host), resumable. Leave existing files on the card alone; put your own under /stick/
| Endpoint | Description | Marks |
|---|---|---|
GET /v1/sd/list | List a folder on the microSD card (up to 256 entries) | |
GET /v1/sd | Read a card file in chunks (≤ 1 MB per request) | |
PUT /v1/sd | Write a card file in chunks (≤ 1 MB each, resumable) | |
DELETE /v1/sd | Delete a card file or folder (recursive=1 deletes its contents) |
Screen#
Screenshots, the UI object tree and full-screen mockup previews
| Endpoint | Description | Marks |
|---|---|---|
GET /v1/snap | Screenshot: 320×172 raw RGB565 pixels | |
GET /v1/ui | UI object tree (coordinates, text) | |
GET /v1/ui/preview | Full-screen mockup preview state | |
PUT /v1/ui/preview | Show a 320×172 mockup full screen (RGB565) | |
DELETE /v1/ui/preview | Remove the mockup preview | |
GET /v1/display | Screen settings: brightness, dimming, backlight off, interface style | |
POST /v1/display | Change screen settings or the interface style; saved and applied at once |
Updates and boot#
Write signed firmware over Wi-Fi, confirm or roll back a new kernel, switch the boot partition, fetch the crash dump. Boot rules: docs/interfaces.md section 1
| Endpoint | Description | Marks |
|---|---|---|
POST /v1/ota | Write a signed firmware image (used by stick deploy) | |
POST /v1/ota/confirm | Confirm the pending kernel | |
POST /v1/ota/rollback | Switch to the other kernel slot and restart | |
POST /v1/boot | Switch the boot partition and restart | |
GET /v1/crash | Raw crash dump (decode with stick crash --decode) | |
DELETE /v1/crash | Clear the crash dump |
Debug and drills#
Fault drills and UI debugging: make the device drop the network or crash, or inject a status to check the UI. Use dropping and crashing only in drills (stick drill)
| Endpoint | Description | Marks |
|---|---|---|
POST /v1/debug/status | Inject a status to check the system screen, banner and icons | |
POST /v1/debug/net_drop | Fault injection: drop the network for N s, then reconnect (this page drops too) | |
POST /v1/debug/crash | Fault injection: crash and restart after about 0.5 s |
Conventions#
HTTP API of the Keyling device (hardware layer). The API page of the device web app, the API reference on the website and the endpoint tables in docs/interfaces.md are all generated from this definition: change an endpoint here first, then regenerate.
- Replies: success is
{"ok":true,...}; failure is an HTTP status plus{"ok":false,"error":"<code>","message":"<text>"}. Programs go byerror;messageis for people (Chinese, independent of the UI language). Endpoint-specific error codes are inx-errors; codes any endpoint can return are incomponents.x-errors. - Auth: HMAC signing by default (
stickHmac, see its rules); endpoints withsecurity: []are open. x-only:kernelmeans kernel only (the rescue firmware returns 404not_found);provmeans only during Wi-Fi setup.x-risk:keyspresses keys and moves the mouse on the computer;rebootrestarts;offlinemay take the device offline;datachanges or deletes data.x-resp: replies that are not JSON are markedtext,binaryorrgb565(screen pixels).- Name tables (key, modifier, mouse button and media names) are case-insensitive (
x-case-insensitive); enums list the canonical spelling. Key names come in two layers: the device accepts the full tableKeyName; host tools and the SDK accept only the standard 87-key setKeyName87by default; extended keysKeyNameExtended(F13–F24, NUMLOCK) are for self-tests and drills only. - Fields limited in UTF-8 bytes carry
x-max-bytes(a Chinese character is 3 bytes;maxLengthcounts characters and is only a necessary condition). - Examples of binary request bodies:
valueis hex (12 digits per timeline record, separated by spaces) andx-recordsspells out each record;x-repeat: Nmeans the whole value repeats N times (e.g. a solid-colour screen). - Query parameters of examples:
x-queryon a request-body example holds that example's full query; endpoints without a request body use each parameter'sexample. - Languages: Chinese goes in the standard keys
summary/description/title(namefor tags); English goes in the same-named keys ofx-enon the same object.
Address#
http://{device} · Device address
device: Device IP (shown on the device screen or by stick ls), for example 192.168.1.20.
Authentication#
stickHmac · header Authorization
Each device has one 32-byte key (obtained by pairing: POST /v1/pair and a click on BOOT to allow, or the key command over USB serial). For every request:
- Get a nonce:
GET /v1/nonce(valid 60 s, single use), or take the one in theX-Stick-Nonceheader of the previous authenticated reply. - Header
X-Stick-Sha256: <SHA-256 of the body, lowercase hex>, sent even for an empty body. - Header
Authorization: Stick <nonce>:<mac>, where mac = lowercase hex HMAC-SHA256(key, "stick-v1\n" + method + "\n" + URI + "\n" + nonce + "\n" + body hash). The method is uppercase; the URI is the path and query string exactly as in the request line.
In Python, stick.client.Client signs requests for you; curl cannot.
For how to sign requests, with a Python example, see HTTP API.
Common errors#
Errors any endpoint can return. Each endpoint lists its own error codes below it.
| Status | Code | Description |
|---|---|---|
401 | auth_required | Authorization or X-Stick-Sha256 is missing or malformed. Sign as described in stickHmac |
401 | bad_nonce | The nonce is invalid, used or expired (60 s). Resend at once with the X-Stick-Nonce of this reply |
401 | bad_mac | Signature mismatch: wrong key, or the signed method, URI (with query string) or body hash differs from the actual request |
403 | unpaired | The device is not paired and has no key: POST /v1/pair first, or use the key command over USB serial |
400 | body_mismatch | The body's SHA-256 does not match X-Stick-Sha256: the body changed after signing, or the hash is wrong |
400 | bad_body | The body arrived incomplete (connection dropped or wrong Content-Length). Resend |
413 | too_large | The body exceeds this endpoint's limit |
404 | not_found | No such path (message is the path); kernel-only endpoints return this in the rescue firmware |
500 | no_memory | The device is out of memory. Try again later |