Repository navigation
API
This page is for developers who script NodePilot or build clients for it. It covers the REST API base URL and authentication, errors, the OpenAPI spec and client generation, the in-panel reference, CORS for web apps, API tokens and their permissions, and curl examples for common tasks. AI agents use the same tokens over MCP: see MCP-and-AI-Agents.
-
Base URL:
https://<your panel>/api, for examplehttps://panel.example.com/api. All paths on this page start with/api. - Format: JSON request and response bodies, unless noted (file upload/download, backup download).
- IDs are UUID strings. Timestamps are RFC 3339 strings in UTC. Sizes are in bytes.
- PATCH endpoints take partial objects: fields you leave out stay unchanged.
The panel listens on 127.0.0.1:7780 by default; reach it through your HTTPS reverse proxy. See Installation and Configuration.
There are two kinds of credentials. Both are sent the same way.
| API token | Browser session | |
|---|---|---|
| How you get it |
API → Tokens → Create token, POST /api/tokens, or nodepilot token create
|
POST /api/auth/login (the sign-in form) |
| How it's sent | Authorization: Bearer np_… |
np_session cookie (HttpOnly), or the same token as Authorization: Bearer
|
| Rights | Only what the token was granted | Full access |
| Lifetime | Until it expires or is revoked | 30 days, or until sign-out |
curl -H "Authorization: Bearer np_0123…" https://panel.example.com/api/auth/meGET /api/auth/me returns the user, the token ({id, name}, or null for a session) and its effective permissions. Clients can use it to hide actions the token can't perform.
Public endpoints that need no credentials: GET /api/health, GET /api/openapi.json, GET /api/auth/status, POST /api/auth/setup (only while no user exists) and POST /api/auth/login.
curl -X POST https://panel.example.com/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "…"}'The response is {"token": "np_…", "user": {…}} plus a Set-Cookie header. If the user has 2FA, the first call returns 401 with two_factor_required and you repeat it with "code". See Security. For scripts and integrations, prefer an API token with limited rights over a session.
Browsers cannot set headers on WebSocket requests. For WebSocket upgrades only, the token may also be passed as a token query parameter:
wss://panel.example.com/api/servers/SERVER_ID/terminal?cols=120&rows=32&token=np_…
The parameter is ignored on ordinary HTTP requests. In a browser, the session cookie also works. The terminal WebSocket needs exec:write. Binary frames carry terminal bytes both ways; text frames carry JSON control messages ({"type":"resize","cols":120,"rows":40} from the client; ready, exit and error from the server). Clients that can't hold a WebSocket open can use the HTTP terminal sessions under /api/terminal-sessions instead.
Errors use a non-2xx status and a JSON body:
{ "error": "server not found" }| Status | Meaning |
|---|---|
| 400 | Bad input (validation error; the message says what) |
| 401 | Not authenticated: missing, unknown or expired token. On login: wrong credentials, or two_factor_required (below) |
| 403 | Authenticated, but not allowed, e.g. this API token has no 'write' access to 'exec'
|
| 404 | Object not found, or unknown /api/... path |
| 409 | Conflict, e.g. deleting a storage or identity that is in use, a backup job that is already running, a stale graph version
|
| 429 | Too many failed sign-ins; see Retry-After
|
| 500 | Internal error (details in the panel log) |
| 502 | SSH or remote failure: the server is unreachable, authentication failed, etc. |
Two cases carry extra information:
HTTP/1.1 401 Unauthorized
Content-Type: application/json
{"error": "two-factor code required", "two_factor_required": true}HTTP/1.1 429 Too Many Requests
Retry-After: 297
Content-Type: application/json
{"error": "too many failed attempts, try again in 297 s"}Retry-After is in seconds. Lockout rules are on the Security page.
The panel serves an OpenAPI 3.1 spec at:
GET /api/openapi.json
It needs no authentication and is generated from the same Rust types and endpoint catalog the server uses, so it matches the running version.
-
serversis[{"url": "/api"}]and paths are relative to it (/servers,/backup-jobs/{id}). Set your client's base URL tohttps://panel.example.com/api. - Every operation has
x-permissionwith the permission it needs (servers:read,exec:write,authenticated). The list of areas is underx-permission-areas. - Security schemes:
bearer(HTTP bearer, annp_…token) andcookie(np_session). - Operation IDs are derived from method and path, e.g.
GET /api/servers/{id}/stats→getServersIdStats.
Generate a client with any OpenAPI 3.1 tool, for example:
curl -o nodepilot.json https://panel.example.com/api/openapi.json
# TypeScript types
npx openapi-typescript nodepilot.json -o nodepilot.d.ts
# A Python client
openapi-generator-cli generate -i nodepilot.json -g python -o nodepilot-clientswift-openapi-generator and orval work too.
API → Reference in the panel is an interactive view of the same spec:
- the base URL, how to authorize, and the total number of endpoints;
- a Permission areas table;
- a searchable list of endpoints grouped by section, each with its parameters, request body, responses and required permission;
-
Try it sends a real request with your session's rights (full access).
DELETErequests, power actions and sign-out ask for confirmation first; other requests are sent right away; - a curl command for each endpoint (replace
np_…with your token).
WebSocket and binary upload endpoints can't be called from the page; it shows how to call them instead.
By default the API sends no CORS headers, so browser apps on other origins can't call it. To allow them, list their exact origins:
# /etc/nodepilot/nodepilot.env
NODEPILOT_CORS_ORIGINS=https://app.example.com,https://admin.example.comor nodepilot serve --cors-origins https://app.example.com,https://admin.example.com.
| Setting | Value |
|---|---|
| Allowed origins | Exactly those listed (a trailing / is ignored) |
| Methods |
GET, POST, PUT, PATCH, DELETE
|
| Request headers |
Authorization, Content-Type
|
| Exposed headers |
Content-Disposition, Content-Length
|
| Preflight cache | 1 hour |
| Credentials (cookies) | Not allowed |
Cross-origin web clients must authenticate with Authorization: Bearer np_…, not the session cookie.
Manage tokens in API → Tokens. Issue a separate token for each client (a mobile app, a CI job, an AI agent) so you can revoke one without affecting the others. The token is shown once, right after creation; the panel stores only its SHA-256 hash.
{ "full": false, "areas": { "servers": "read", "notes": "write" } }-
full: truegrants read and write on every area, including areas added in future versions. - Otherwise each area is
read,writeor absent (no access).writeincludesread. - Presets in the token dialog:
| Preset | Permissions |
|---|---|
| Full access |
{"full": true} (the default when permissions is omitted) |
| Read-only |
read on every area except exec and admin (nothing can be changed, no commands) |
| Custom | Pick None, Read or Write per area. All read, All write and Reset fill the table |
These are the 10 areas defined in the code (nodepilot-core/src/access.rs). The table lists what each level unlocks, from the endpoint catalog.
| Area | UI label | read |
write adds |
|---|---|---|---|
servers |
Servers and stats | List and get servers, current stats, stats history, SSH connection test | Add (also in bulk), edit and delete servers, forget a pinned host key |
projects |
Projects | List and get projects | Create, edit, delete projects; add and remove servers |
identities |
Keychain | List and get keychain entries (never secrets) | Create, edit, delete entries |
exec |
Commands and terminal | (write only) | Run a command on a server, bulk exec, the WebSocket terminal, HTTP terminal sessions |
system |
Processes and services | Processes, systemd services, service logs | Kill processes, start/stop/restart/reload/enable/disable services, reboot and shut down |
files |
Files | List directories, download files | Upload/overwrite, create directories, rename/move, delete |
notes |
Notes | List and get notes | Create, edit, delete notes |
graphs |
Graphs | List and get graphs | Create, edit, delete graphs, nodes and edges |
backups |
Backups | Storages, jobs, run history, archive download | Create/edit/delete storages and jobs, test storages, run now, delete archives, generate age key pairs |
admin |
API tokens | List tokens; security status; panel key info; audit log and its settings; update status | Issue, edit and revoke tokens; create, deploy, rotate and revoke the panel key; change audit forwarding and send a test event; change update settings and install updates |
Notes:
-
exechas a single level. Anexecentry is always stored aswrite, even if you send"exec": "read". A token withexeccan run any command on servers as their SSH user. -
admincovers more than tokens: the Security page, the audit log and updates are behind it too, even though the UI labels the area "API tokens". Don't give it to agents or third-party apps. - A few endpoints need only a valid credential, whatever its areas:
GET /api/auth/me,POST /api/auth/logout,POST /api/mcp,GET /api/system/versionand the/api/auth/2faendpoints (changing 2FA additionally requires a browser session). A token with no areas can check itself and connect to MCP, where it sees no tools. - Endpoints missing from the catalog are denied to API tokens.
POST /api/tokens (needs admin:write):
curl -X POST https://panel.example.com/api/tokens \
-H "Authorization: Bearer $NP_TOKEN" -H "Content-Type: application/json" \
-d '{
"name": "grafana",
"permissions": { "full": false, "areas": { "servers": "read", "backups": "read" } },
"expires_in_days": 90
}'{
"token": "np_5f0c…",
"info": {
"id": "…", "name": "grafana", "created_at": "…", "last_used_at": null,
"expires_at": "…", "permissions": { "full": false, "areas": { "backups": "read", "servers": "read" } }
}
}| Field | Notes |
|---|---|
name |
Required when creating. |
permissions |
Defaults to full access when creating. When editing, omit to keep. |
expires_in_days |
1–3650, or 0 for no expiry. When editing, it counts from now; omit to keep the current expiry. The UI offers Never, 7, 30, 90 and 365 days. |
Other calls: GET /api/tokens lists your tokens (admin:read), PATCH /api/tokens/{id} changes name, permissions or expiry, and DELETE /api/tokens/{id} revokes a token immediately. Each user sees and manages only their own tokens.
No escalation: a token can never issue or edit a token with more access than it has itself. A token with admin:write and servers:read can create a servers:read token, but not one with servers:write or full. The request fails with 403 cannot issue a token with more access than your own. Browser sessions have full access and can issue anything.
From the panel host you can also issue a token with the CLI (full or --read-only, optional --expires-in-days). See CLI-Reference.
The examples assume:
export NP=https://panel.example.com/api
export NP_TOKEN=np_…Needs servers:read. Optional filters: project_id, q (substring of name or host), tag.
curl -H "Authorization: Bearer $NP_TOKEN" "$NP/servers?q=web"Needs exec:write. timeout_secs defaults to 60 and is capped at 3600. stdout and stderr are capped at 1 MiB each (truncated: true when cut).
curl -X POST "$NP/servers/SERVER_ID/exec" \
-H "Authorization: Bearer $NP_TOKEN" -H "Content-Type: application/json" \
-d '{"command": "systemctl is-active nginx && df -h /", "timeout_secs": 30}'{ "exit_code": 0, "stdout": "active\nFilesystem …", "stderr": "", "duration_ms": 412, "truncated": false }A non-zero exit_code is still a 200 response. Connection problems return 502.
Needs exec:write. Target a project, a list of servers, or both (duplicates are removed). Up to 32 servers run in parallel; results come back in target order.
curl -X POST "$NP/exec" \
-H "Authorization: Bearer $NP_TOKEN" -H "Content-Type: application/json" \
-d '{"command": "uptime", "project_id": "PROJECT_ID", "timeout_secs": 20}'{
"results": [
{ "server_id": "…", "server_name": "web-1", "ok": true, "error": null,
"result": { "exit_code": 0, "stdout": " 10:00:01 up 12 days, …", "stderr": "", "duration_ms": 180, "truncated": false } },
{ "server_id": "…", "server_name": "web-2", "ok": false, "error": "…", "result": null }
]
}ok: false means the panel could not run the command on that server; check result.exit_code for the command's own status.
Needs notes:write. title is required. Attach the note to a project, a server, or neither.
curl -X POST "$NP/notes" \
-H "Authorization: Bearer $NP_TOKEN" -H "Content-Type: application/json" \
-d '{
"title": "nginx upgrade",
"body": "Upgraded nginx to 1.26 on **web-1**. Config unchanged.",
"server_id": "SERVER_ID",
"pinned": false
}'In PATCH /api/notes/{id}, "server_id": null or "project_id": null detaches the note. See Notes.
Needs graphs:write. type is node (default) or note (a text note on the canvas). role is one of server, api, web, db, cache, queue, storage, lb, vpn, internet, other. Leave out x/y and the node is placed in free space.
curl -X POST "$NP/graphs/GRAPH_ID/nodes" \
-H "Authorization: Bearer $NP_TOKEN" -H "Content-Type: application/json" \
-d '{"type": "node", "label": "db-1", "role": "db", "server_id": "SERVER_ID", "note": "Primary PostgreSQL"}'Connect two nodes with POST /api/graphs/{id}/edges and {"source": "NODE_A", "target": "NODE_B", "kind": "replication"}. Edge kinds: link, depends, cascade, vpn, replication, other. See Graphs.
Needs backups:read. Filter by job_id and/or server_id. Newest first, up to 500.
curl -H "Authorization: Bearer $NP_TOKEN" "$NP/backups?job_id=JOB_ID"[
{ "id": "…", "job_id": "…", "server_id": "…", "status": "success",
"started_at": "2025-01-01T03:00:00Z", "finished_at": "2025-01-01T03:01:12Z",
"size_bytes": 48213344, "file_name": "web-1-app-db-20250101-030000.pgdump.age",
"encrypted": true, "error": null }
]Download an archive with curl -OJ -H "Authorization: Bearer $NP_TOKEN" "$NP/backups/RUN_ID/download". See Backups.
docs/API.md in the repository has a human-oriented overview of every endpoint with TypeScript-style types. For exact, current schemas, use /api/openapi.json or API → Reference.
NodePilot · Releases · Report a vulnerability · Apache-2.0
Set up
Use
Secure
Integrate
Reference