# Diagnostics What the server itself is doing: the process, each account's connection, frames the client could not decode, recent warnings, crash reports and the log. Undecodable frames are the first sign of a broker build the client does not understand. Each (account, command, kind) keeps at most 5 bodies an hour; the rest are only counted. Kept ones are also appended to `/captures/undecoded.jsonl`, and the newest of them are read back at start, so a restart does not empty the list (the counters start again). Admin only. ### Get diagnostics `GET /api/v1/diagnostics` Scope: admin. One snapshot of the server: version and build target, process stats (null off Linux), data folder, log file, database size, dashboard sessions, open streams, every account's status with tick and decode counters, frames the client could not decode, the last 100 warnings and errors, crash reports, and the report from an unclean exit, if any. **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: Diagnostics. A Diagnostics object. | Field | Type | Description | |---|---|---| | `version` | string | Server version. (required) | | `target` | string | The platform the binary was built for, for example x86_64-unknown-linux-gnu. (required) | | `pid` | integer | Process id. (required) | | `started_at` | integer | When the server started, unix seconds (UTC). (required) | | `uptime_s` | integer | Seconds since the server started. (required) | | `process` | object | Read from /proc; every field is null off Linux. (required; object: rss_kb, rss_peak_kb, threads, open_files) | | `data_dir` | string | The data folder. (required) | | `log_file` | string or null | The current log file, null before the first one is written. (required) | | `db_bytes` | integer | Size of the database (with its write-ahead log) in bytes. (required) | | `dashboard_sessions` | integer | Dashboard sign-ins that have not expired. (required) | | `streams` | object | Open price streams and their caps. (required; object: sse, ws, max, max_per_key) | | `accounts` | array of DiagnosticsAccount | Every account, with its connection status. (required; see DiagnosticsAccount) | | `undecoded` | object | Frames the client could not decode. (required; object: total, file, by_command, recent) | | `problems` | array of LogLine | The last 100 warnings and errors from the log, newest first. (required; see LogLine) | | `crashes` | array of CrashReport | Crash reports in /crashes, newest first. (required; see CrashReport) | | `unclean_exit_report` | string or null | null, or the file name (such as unclean-exit-2026-10-03T00-12-07Z.txt) of the report written at this start because the previous run did not shut down cleanly (its pid file was still there). Read it with GET /api/v1/diagnostics/crashes/{name}. It stays set for the whole run. (required) | Example: ```json { "version": "0.1.0", "target": "x86_64-unknown-linux-gnu", "pid": 41822, "started_at": 1790894779, "uptime_s": 75600, "process": { "rss_kb": 23140, "rss_peak_kb": 31200, "threads": 9, "open_files": 21 }, "data_dir": "/var/lib/termless", "log_file": "/var/lib/termless/logs/termlessd.2026-10-03.log", "db_bytes": 135168, "dashboard_sessions": 1, "streams": { "sse": 1, "ws": 0, "max": 1024, "max_per_key": 256 }, "accounts": [ { "connected": true, "since": 1790968298, "reconnects": 0, "ping_ms": 14.2, "server_build": 6090, "last_error": null, "subscribed": 2, "login_rejected": false, "retry_at": null, "id": "pepperstone-12345678", "enabled": true, "session_running": true, "ticks_seen": 1840211, "last_tick_at_ms": 1790970379473, "last_frame_at_ms": 1790970381002, "streams": 1, "ticks_coalesced": 0, "undecoded": 3 } ], "undecoded": { "total": 3, "file": "/var/lib/termless/captures/undecoded.jsonl", "by_command": [ { "account": "pepperstone-12345678", "command": 8, "kind": "body", "context": "tick push", "count": 3, "first_at": 1790964410, "last_at": 1790965012, "last_error": "short read at offset 40" } ], "recent": [ { "id": 3, "time": 1790965012, "account": "pepperstone-12345678", "kind": "body", "command": 8, "code": 0, "context": "tick push", "error": "short read at offset 40", "server_build": 6090, "len": 52 } ] }, "problems": [ { "time": 1790968290, "level": "warn", "target": "termless::session", "message": "[pepperstone-12345678] connection lost, reconnecting" } ], "crashes": [ { "name": "20261002T231405Z-panic.txt", "time": 1790896445, "size": 6120, "summary": "index out of bounds: the len is 3 but the index is 3" } ], "unclean_exit_report": null } ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/diagnostics" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/diagnostics", headers=auth) r.raise_for_status() print(r.json()) ``` ### List undecoded frames `GET /api/v1/diagnostics/undecoded` Scope: admin. Frames the client could not decode, newest first, with their bytes as hex. The server keeps the last 200 in memory, and at start reads the newest kept ones back from `captures/undecoded.jsonl` (its last 4 MB), so a restart does not empty this list. Without `bodies=1`, `body_hex` is cut to its first 128 bytes and `body_preview: true` says so (a page of 200 frames is then under 100 KB); with it, up to 64 KB a frame. **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `account` | string | no | Only this account's frames. | | `limit` | integer | no | Most frames to return, at most 200. (default 50; 1 to 200) | | `bodies` | boolean | no | 1 (or true) returns each frame's whole body_hex, up to 64 KB a frame. (default false) | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: Frames. A JSON array of UndecodedFrame. | Field | Type | Description | |---|---|---| | `id` | integer | Frame number since the server started. (required) | | `time` | integer | When it arrived, unix seconds (UTC). (required) | | `account` | string | Account id. (required) | | `login` | integer | MT5 login of the account. (required) | | `kind` | string | frame: the outer frame or its encryption did not check out. body: a known command whose body did not parse. unknown_push: a push with a command id the client does not handle. extra (0.6.0): a reply read in full with bytes after the records the layout knows; kept for diagnosis, never counted as undecoded. (required; one of frame, body, unknown_push, extra) | | `command` | integer | Protocol command id. (required) | | `code` | integer | The frame's result code. (required) | | `context` | string | Where it happened, for example tick push or account reply. (required) | | `error` | string | What the decoder said. (required) | | `server_build` | integer | The broker's MT5 build at the time. (required) | | `len` | integer | Body length in bytes. (required) | | `body_hex` | string | The body as hex. Without `bodies=1` it is cut to the first 128 bytes and `body_preview` is true; with it, up to 64 KB a frame. (required) | | `truncated` | boolean | True when the kept body itself holds only the first 64 KB. (required) | | `body_preview` | boolean | Present and true when body_hex was cut to its first 128 bytes; ask with `bodies=1` for the whole body. | Example: ```json [ { "id": 3, "time": 1790965012, "account": "pepperstone-12345678", "login": 12345678, "kind": "body", "command": 8, "code": 0, "context": "tick push", "error": "short read at offset 40", "server_build": 6090, "len": 52, "body_hex": "0a000000b80b0000a4703d0ad7af924000000000000000000000000000000000c8b1e2a4b5010000", "truncated": false, "body_preview": true } ] ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/diagnostics/undecoded?account=pepperstone-12345678&limit=50" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/diagnostics/undecoded", headers=auth, params={"account": "pepperstone-12345678", "limit": 50}) r.raise_for_status() print(r.json()) ``` ### Run the doctor `GET /api/v1/diagnostics/doctor` Scope: admin. The same checks as `termlessd doctor` on the command line, against the running server: the data folder (exists, writable, owner-only), `master.key`, the database (integrity check and row counts), the listen address, each account's gateway (DNS, TLS, the web terminal's build, and the session's live state), the clock against the first connected broker (warns past 5 s) and free disk. Each warn or fail says what to do. **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: The report. A DoctorReport object. | Field | Type | Description | |---|---|---| | `verdict` | string | ok when every check passed, warnings when something should be looked at, problems when something is broken. (required; one of ok, warnings, problems) | | `version` | string | Server version. (required) | | `data_dir` | string | The data folder that was checked. (required) | | `checks` | array of DoctorCheck | One row per check, in the order they ran. (required; see DoctorCheck) | Example: ```json { "verdict": "warnings", "version": "0.1.0", "data_dir": "/var/lib/termless", "checks": [ { "name": "data folder", "level": "ok", "detail": "/var/lib/termless exists and is writable" }, { "name": "master.key", "level": "ok", "detail": "/var/lib/termless/master.key present (owner-only)" }, { "name": "database", "level": "ok", "detail": "/var/lib/termless/termless.db (132 KB) integrity ok; rows: accounts 1, keys 2, audit 4821, account_events 310, equity_samples 1440" }, { "name": "listen", "level": "ok", "detail": "serving on http://127.0.0.1:8780" }, { "name": "gateway", "level": "ok", "detail": "pepperstone-12345678: mt5-demo01.pepperstone.com:443 is Pepperstone Group Limited build 6090 (2 servers); connected, build 6090" }, { "name": "clock", "level": "warn", "detail": "7 s off the broker's clock", "fix": "enable NTP (timedatectl set-ntp true); candle times and expirations depend on it" }, { "name": "disk", "level": "ok", "detail": "18240 MB free; termless uses 3 MB" } ] } ``` **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/diagnostics/doctor" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/diagnostics/doctor", headers=auth) r.raise_for_status() print(r.json()) ``` ### Get a crash report `GET /api/v1/diagnostics/crashes/{name}` Scope: admin. The text of one crash report: a panic, or an exit without a clean shutdown, with the last log lines before it. **Path parameters** | Name | Type | Required | Description | |---|---|---|---| | `name` | string | yes | Crash report file name, from the crashes list in GET /api/v1/diagnostics. | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: The report, as text/plain. **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. **curl** ```sh curl -s "$TERMLESS_URL/api/v1/diagnostics/crashes/20261002T231405Z-panic.txt" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/diagnostics/crashes/20261002T231405Z-panic.txt", headers=auth) r.raise_for_status() print(r.text) ``` ### Get the log `GET /api/v1/diagnostics/logs` Scope: admin. The end of the current log file (`/logs/termlessd..log`, one per day). 404 before the first one is written. **Query parameters** | Name | Type | Required | Description | |---|---|---|---| | `lines` | integer | no | How many lines from the end, at most 5000. (default 200; 1 to 5000) | **Headers** | Name | Type | Required | Description | |---|---|---|---| | `X-Request-Id` | string | no | Your own id for the request, kept and echoed in the response header of the same name (and written on every log line and audit row of the request). Anything else is replaced by one the server makes. | **Response 200**: The last lines, as text/plain. **Errors** - `400 bad_request`: A field is missing or not valid, or the query string has a parameter the route does not take (the message names the ones it takes; `key=` is accepted anywhere). - `401 unauthorized`: No valid API key or session. - `403 forbidden`: The key lacks the scope, or may not use this account, or a cookie request came from another site. - `404 not_found`: No such account, symbol, ticket, key or route. - `429 too_many_requests`: This IP is locked out for 15 minutes (5 wrong passwords or setup tokens lock it out of sign-in, 30 unknown API keys in 15 minutes lock it out of key auth), or a stream cap was hit (1,024 open streams per server, 256 per key or dashboard session), or a password check could not start (one at a time per IP, two at a time per server). Retry-After has the seconds to wait. - `500 internal`: The server hit an internal error. Any route can answer it; a panic also saves a crash report (see Diagnostics). **curl** ```sh curl -s "$TERMLESS_URL/api/v1/diagnostics/logs?lines=200" \ -H "Authorization: Bearer $TERMLESS_KEY" ``` **Python (requests)** ```python import os import requests base = os.environ["TERMLESS_URL"] + "/api/v1" auth = {"Authorization": "Bearer " + os.environ["TERMLESS_KEY"]} r = requests.get(f"{base}/diagnostics/logs", headers=auth, params={"lines": 200}) r.raise_for_status() print(r.text) ```