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.

Download openapi.json

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

EndpointDescriptionMarks
GET /v1/infoDevice info: ID, firmware, memory, Wi-Fi, OTA slots, microSD card, web app versionOpen
GET /v1/nonceGet a one-time nonce for signing (valid 60 s; authenticated replies also carry X-Stick-Nonce)Open
GET /v1/statusStatus bus snapshot: current states and eventsSignature required
GET /v1/logsLog ringSignature required
POST /v1/identifyIdentify: screen and LED signal for 5 sSignature required
POST /v1/rebootRestart 0.5 s after replyingSignature required Restarts
GET /v1/langScreen (system UI) language: zh / en; chosen means someone picked itSignature required
POST /v1/langSet the screen language; saved and applied immediatelySignature required
GET /v1/timeTime and time zone (POSIX TZ + IANA name)Signature required Kernel only
POST /v1/timeSet the time zone; applied immediatelySignature required Kernel only
GET /v1/buttonBOOT button event ring (click / double-click / long press / hold; stop marks emergency stop)Signature required Kernel only

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

EndpointDescriptionMarks
GET /v1/wifiSaved networks (up to 3, most recent first, no passwords) and the current oneSignature required
POST /v1/wifiSet as candidate and switch to it in about 1.5 s; saved only once joined, otherwise returns to a saved networkSignature required May go offline
POST /v1/wifi/forgetForget a network; without ssid, clear all and enter Wi-Fi setup (device goes offline until set up from a phone)Signature required May go offline
GET /prov/statusSetup page polling: candidate network result (Wi-Fi setup only)Open Wi-Fi setup only
GET /prov/scanNearby networks (Wi-Fi setup only)Open Wi-Fi setup only
POST /prov/wifiSetup page submit (form ssid, pass; Wi-Fi setup only)Open Wi-Fi setup only
POST /prov/forgetSetup page forgets a network (form ssid; Wi-Fi setup only)Open Wi-Fi setup only
POST /prov/langSetup page sets the screen language (form lang=zh|en; Wi-Fi setup only)Open Wi-Fi setup only
POST /prov/leaveLeave setup: drop the candidate, close the hotspot, return to a saved network (Wi-Fi setup only)Open 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

EndpointDescriptionMarks
POST /v1/pairRequest pairing: the screen shows a 4-digit code; click BOOT to allow (30 s)Open Kernel only
GET /v1/pairPairing result; the first query after approval includes the keyOpen Kernel only

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

EndpointDescriptionMarks
GET /v1/hidHID state: lease left, queue, held keys, LEDs (Num / Caps / Scroll)Signature required Kernel only
POST /v1/hidSend keyboard and mouse actions (keys go to the foreground window)Signature required Kernel only Sends input
POST /v1/hid/armArm HID output (lease; disarms and releases all keys on expiry). Call again to renewSignature required Kernel only Sends input
POST /v1/hid/disarmEmergency stop and disarmSignature required Kernel only
POST /v1/hid/timelineTimeline (6-byte records, executed at their scheduled times)Signature required Kernel only Sends input
POST /v1/hid/play_fileStream a timeline file from the microSD cardSignature required Kernel only Sends input
GET /v1/hid/play_filePlayback state of the card timelineSignature required Kernel only
POST /v1/hid/play_file/stopStop playbackSignature required Kernel only
GET /v1/monitorMonitor screen state (right side: name, mode, step, progress)Signature required Kernel only
POST /v1/monitorSet the monitor screen state (replaces it)Signature required Kernel only
POST /v1/usbUSB mode hid / serial; restarts after replying (no keyboard or mouse in serial)Signature required Kernel only Restarts

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

EndpointDescriptionMarks
GET /v1/appsApps, the running app, start on boot, memorySignature required Kernel only
POST /v1/apps/startStart an app (the macro player is macro)Signature required Kernel only
POST /v1/apps/stopStop the current app and return homeSignature required Kernel only
POST /v1/apps/autoSet or clear start on boot (id null clears)Signature required Kernel only
POST /v1/apps/deleteDelete an app folder (keeps its data folder)Signature required Kernel only Changes data
POST /v1/apps/msgMessage the running app; macro player: select / run / stop / reload / planSignature required Kernel only Sends input
GET /v1/apps/eventsEvents emitted by apps (app.emit)Signature required Kernel only
POST /v1/evalRun code in the app’s Lua state (can call hid; take care)Signature required Kernel only Sends input

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

EndpointDescriptionMarks
GET /v1/fs/listList a storage folder (up to 256 entries)Signature required Kernel only
GET /v1/fsRead a storage file (whole file)Signature required Kernel only
PUT /v1/fsWrite a storage file (≤ 2 MB; replaces an existing one)Signature required Kernel only Changes data
DELETE /v1/fsDelete a storage file or folder (recursive=1 deletes its contents)Signature required Kernel only Changes data

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/

EndpointDescriptionMarks
GET /v1/sd/listList a folder on the microSD card (up to 256 entries)Signature required Kernel only
GET /v1/sdRead a card file in chunks (≤ 1 MB per request)Signature required Kernel only
PUT /v1/sdWrite a card file in chunks (≤ 1 MB each, resumable)Signature required Kernel only Changes data
DELETE /v1/sdDelete a card file or folder (recursive=1 deletes its contents)Signature required Kernel only Changes data

Screen#

Screenshots, the UI object tree and full-screen mockup previews

EndpointDescriptionMarks
GET /v1/snapScreenshot: 320×172 raw RGB565 pixelsSignature required
GET /v1/uiUI object tree (coordinates, text)Signature required Kernel only
GET /v1/ui/previewFull-screen mockup preview stateSignature required Kernel only
PUT /v1/ui/previewShow a 320×172 mockup full screen (RGB565)Signature required Kernel only
DELETE /v1/ui/previewRemove the mockup previewSignature required Kernel only
GET /v1/displayScreen settings: brightness, dimming, backlight off, interface styleSignature required Kernel only
POST /v1/displayChange screen settings or the interface style; saved and applied at onceSignature required Kernel only

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

EndpointDescriptionMarks
POST /v1/otaWrite a signed firmware image (used by stick deploy)Signature required Restarts
POST /v1/ota/confirmConfirm the pending kernelSignature required
POST /v1/ota/rollbackSwitch to the other kernel slot and restartSignature required Restarts
POST /v1/bootSwitch the boot partition and restartSignature required Restarts
GET /v1/crashRaw crash dump (decode with stick crash --decode)Signature required
DELETE /v1/crashClear the crash dumpSignature required Changes data

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)

EndpointDescriptionMarks
POST /v1/debug/statusInject a status to check the system screen, banner and iconsSignature required
POST /v1/debug/net_dropFault injection: drop the network for N s, then reconnect (this page drops too)Signature required May go offline
POST /v1/debug/crashFault injection: crash and restart after about 0.5 sSignature required Restarts

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 by error; message is for people (Chinese, independent of the UI language). Endpoint-specific error codes are in x-errors; codes any endpoint can return are in components.x-errors.
  • Auth: HMAC signing by default (stickHmac, see its rules); endpoints with security: [] are open.
  • x-only: kernel means kernel only (the rescue firmware returns 404 not_found); prov means only during Wi-Fi setup.
  • x-risk: keys presses keys and moves the mouse on the computer; reboot restarts; offline may take the device offline; data changes or deletes data.
  • x-resp: replies that are not JSON are marked text, binary or rgb565 (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 table KeyName; host tools and the SDK accept only the standard 87-key set KeyName87 by default; extended keys KeyNameExtended (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; maxLength counts characters and is only a necessary condition).
  • Examples of binary request bodies: value is hex (12 digits per timeline record, separated by spaces) and x-records spells out each record; x-repeat: N means the whole value repeats N times (e.g. a solid-colour screen).
  • Query parameters of examples: x-query on a request-body example holds that example's full query; endpoints without a request body use each parameter's example.
  • Languages: Chinese goes in the standard keys summary / description / title (name for tags); English goes in the same-named keys of x-en on 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:

  1. Get a nonce: GET /v1/nonce (valid 60 s, single use), or take the one in the X-Stick-Nonce header of the previous authenticated reply.
  2. Header X-Stick-Sha256: <SHA-256 of the body, lowercase hex>, sent even for an empty body.
  3. 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.

StatusCodeDescription
401auth_requiredAuthorization or X-Stick-Sha256 is missing or malformed. Sign as described in stickHmac
401bad_nonceThe nonce is invalid, used or expired (60 s). Resend at once with the X-Stick-Nonce of this reply
401bad_macSignature mismatch: wrong key, or the signed method, URI (with query string) or body hash differs from the actual request
403unpairedThe device is not paired and has no key: POST /v1/pair first, or use the key command over USB serial
400body_mismatchThe body's SHA-256 does not match X-Stick-Sha256: the body changed after signing, or the hash is wrong
400bad_bodyThe body arrived incomplete (connection dropped or wrong Content-Length). Resend
413too_largeThe body exceeds this endpoint's limit
404not_foundNo such path (message is the path); kernel-only endpoints return this in the rescue firmware
500no_memoryThe device is out of memory. Try again later

View the source of this page on GitHub