API and automation
REST API
Everything the panel does is available as JSON under /api/v1/, described by an OpenAPI 3.1 spec at /api/v1/openapi.json, with scoped bearer tokens or a session with CSRF protection.
On this page
Berth's web interface and its REST API are two views of the same thing: every page in the panel calls the same panel functions that the API exposes, with the same permission checks, validation and audit logging. If you can do it in the panel, you can script it. This article explains how to find your way in the API, how to authenticate, and the few rules that every client has to follow.
The API at a glance
- Base path:
https://<panel hostname>/api/v1/. - Format: JSON in, JSON out.
- Description: an OpenAPI 3.1 document at
GET /api/v1/openapi.json, also printed byberth openapion the server. - Size: about a thousand paths and over 1,200 operations, covering domains, mail, DNS, databases, backups, migration, security, server management, fleet and more.
- Scope: a login sees through the API exactly what it sees in the panel. A customer only sees their own subscriptions, a reseller their own customers.
The spec is generated from the route registrations in the code, and a test fails when a route has no description, so the spec and the server do not drift apart. Summaries in the spec are currently in Dutch. Berth does not ship a documentation viewer; load the spec into the tool you prefer, such as Swagger UI, Redoc, Postman, Insomnia or a client generator.
curl -s https://panel.example.nl/api/v1/openapi.json -o berth-openapi.json
berth openapi > berth-openapi.json # on the server, same documentAuthentication
The spec declares two security schemes. Use a token for scripts and integrations; the session is what the browser uses.
Bearer token
curl -s -H "Authorization: Bearer berth_<secret>" https://panel.example.nl/api/v1/meGET /api/v1/me returns who you are (login, role and, for customers and resellers, their id). It is a good first call to check a token.
Session with CSRF token
POST /api/v1/login with {"login": "...", "password": "..."} sets the session cookie and returns {"login": …, "csrf": …, "session_expires": …}. Send the csrf value as the X-CSRF-Token header on every request that changes something. If the account uses two-step verification, the answer says mfa_required; send the code to POST /api/v1/login/mfa with the same cookie and CSRF token.
curl -s -c jar -H "Content-Type: application/json" \
-d '{"login":"acme","password":"…"}' https://panel.example.nl/api/v1/login
curl -s -b jar -H "X-CSRF-Token: $CSRF" -H "Content-Type: application/json" \
-X PATCH -d '{"hsts":true}' https://panel.example.nl/api/v1/domains/acme.nlOver https the cookie is a __Host- cookie: bound to the panel's hostname, secure-only and path /.
API tokens and scopes
A token belongs to a login and acts with that login's rights, narrowed by its scope:
| Scope | Panel label | What the token can reach |
|---|---|---|
full | REST API | The whole REST API, as the login. |
provisioning | Billing (provisioning) | Only /api/v1/provisioning/, for WHMCS, HostBill or your own billing. Administrators only. |
metrics | Metrics (Prometheus) | Only /metrics in Prometheus format. See Statistics and metrics. |
monitor:read | Home Assistant (read only) | Only the read-only status used by Home Assistant. |
ai:read, ai:write, ai:full | Read only, Read and change, Full within the subscription | Only the MCP endpoint /mcp; the REST API refuses these tokens. See AI assistant and MCP. |
probe | Probe location for uptime | Lets another Berth server run uptime checks from this one. Administrators only. |
Extensions get their own, narrower keys from the panel; see Webhooks and extensions.
Rules that apply to every token:
- The secret (
berth_…) is shown once and stored only as a hash. Lost means revoke and create a new one. - A token can be limited to one subscription of the login.
- By default a token expires after a year; you can choose a shorter or no expiry.
- A token can never create or manage tokens, and never manage two-step verification.
- An auditor's tokens are read-only, whatever scope is chosen.
- Revoking works immediately.
Creating a token
Panel: Account → AI connection (the page AI connection and API keys) → Create key. Give it a name, choose the rights, optionally a subscription and a validity (30 days, 90 days, 1 year, unlimited). Creating a key asks you to confirm it is you first.
On the server:
berth token create --login admin --name ci --scope full --days 90
berth token create --login acme --name deploy --scope full --sysuser acme --days 30
berth token list --login admin
berth token revoke --login admin --id 7Sensitive actions
Some actions need more than an ordinary token or session, because they hand out secrets or destroy data: setting a mailbox or database password, exporting a database or a customer's data, downloading a backup or a file from history, deleting a customer, domain, database, mailbox or backup, lifting a write lock, widening a subscription's outbound traffic, and creating an API key.
| Situation | Response | What to do |
|---|---|---|
| Session without a recent confirmation | 403 with code: "reauth_required" | Confirm with POST /api/v1/me/reauth (a passkey, a second-factor code, or the password if the login has no second step), then repeat the request. |
| Token without the sensitive scope | 403 with code: "sensitive_scope_required" | Use a token created with Allow sensitive actions, --sensitive on the CLI. |
The error body names the action in action. Only create sensitive tokens for integrations that really need them: the panel normally asks a person to confirm these actions, and a token cannot.
Rules every client must follow
Send JSON as JSON. A request with a JSON body must carry Content-Type: application/json; otherwise the API answers 415. This is deliberate: browsers can send some content types across sites without a preflight check, and requiring the JSON type closes that path for cross-site requests.
Send exactly what the operation expects. Bodies are decoded strictly: unknown fields, more than one JSON value and oversized bodies are refused with a 4xx error. Check the schema of the operation in the spec.
Expect errors in one shape. Errors return a 4xx or 5xx status with a JSON body:
{"error": "…", "request_id": "…"}Messages are in Dutch. Some refusals carry a stable code for programs, such as the two above, or coverage_loss (409) when a backup change would leave subscriptions without an external copy; such a body tells you which field to resend (confirm: true) to go ahead deliberately.
Respect rate limits. Sign-in and other sensitive endpoints are rate-limited. Calls from customers, resellers and their tokens are also limited per account, both in how many requests may run at once and in requests per second, with room for a short burst. A client that gets 429 should honour Retry-After and back off.
Examples
Create a mailbox (the password is generated when you leave it empty and shown once in the answer):
curl -s -X POST https://panel.example.nl/api/v1/domains/acme.nl/mail/accounts \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"local":"info","quota_mb":2048}'Add a domain with a certificate for an existing customer:
curl -s -X POST https://panel.example.nl/api/v1/domains \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"domain":"shop.example.com","customer":"acme","plan":"basis","tls":true}'Usage of a subscription against its package, and what is currently running or waiting:
curl -s -H "Authorization: Bearer $TOKEN" https://panel.example.nl/api/v1/subscriptions/acme/usage
curl -s -H "Authorization: Bearer $TOKEN" https://panel.example.nl/api/v1/summaryLong operations (an update, a restore, a WordPress install) run as background tasks; GET /api/v1/tasks lists them with their progress.
Auditing
Every change through the API lands in the activity log under the login's name, with the token's name, exactly as if it had been done in the panel. Four-eyes approval, where enabled, applies to API calls too: the call becomes a request for a second administrator.
Related
- The berth CLI: the same functions on the server, without a token.
- Webhooks and extensions: get notified of changes instead of polling.
- Sign-in security: passkeys, two-step verification and re-authentication.