Skip to content

API

The API lets your own scripts and tools, such as a billing bot or a dashboard, do what the panel’s pages do: the panel itself uses it for everything. This page is the short version, enough to make a first call. Paths under api/v1/ are stable: later 1.x versions only add to them. There is no public list of every call. For any other call, the panel uses the same API, so the Network tab of your browser, open on a page of the panel, shows an exact request. A longer safe path is Use the API from a script.

The API lives under the panel’s address and secret path:

https://panel.example.com:2053/SECRET-PATH/api/v1/

The API tokens card in Settings → Security makes tokens and shows the exact address as API address, and it is hidden until you turn on Selling and operator tools in Settings → Panel (the full_mode setting). Give the token a name and choose its access and when it expires: in 30, 90 or 365 days, or never. Copy the token at once: it is shown once, and the panel keeps only a hash of it. A token starts with aft_, and an account can have up to 50 tokens. Send it in the header Authorization: Bearer TOKEN of every request:

Terminal window
curl -H "Authorization: Bearer aft_YOUR_TOKEN" https://panel.example.com:2053/SECRET-PATH/api/v1/clients

Treat a token like a password. A token acts as the account that made it: an admin’s token reaches only that admin’s sections, and a reseller’s only their own clients. Only the owner sees the API tokens card in Settings → Security; other admins and resellers create and delete their own tokens through the API from a signed-in browser session. Every change made with a token is recorded in the activity log as token:NAME.

Access What it may do
Full (full) Everything the account can do in the panel, except the calls below that need a signed-in admin.
Clients (clients) Read everything. Create, change, renew, reset and delete clients, and nothing else.
Read only (read) GET calls only: lists, usage and configs.

A call outside the token’s access is refused with token_scope. Some calls refuse every token and answer session_only. They need a signed-in admin: changing the password and two-factor sign-in, making tokens, making and restoring backups, installing updates and AmneziaWG, replacing the secrets, a factory reset, and the install command of a bridge, an exit or a fleet server, which carries that node’s join secret.

A wrong token counts as a failed sign-in: an address that keeps guessing is blocked by the login guard (see Security), and the call answers too_many_attempts. An expired token answers token_expired, and one the panel does not know bad_token.

  • Request bodies are JSON (Content-Type: application/json).
  • A reply is {"ok": true, "data": …}. An error is {"ok": false, "code": "…", "msg": "…"} with an HTTP status of 400, 401, 403, 404, 429 or 500. The code is stable; the msg is for people.
  • A write from a browser page, with its sign-in cookie, needs the header X-Requested-With: aftab. A call with a token needs none, and a write without it is refused with csrf.
  • GET health needs no sign-in and says only whether the panel is up. While the panel starts it answers 503. GET status is what a monitor polls with a Read only token.
  • Times are Unix timestamps in seconds, and 0 means none. Traffic is in bytes, and 0 as a limit means unlimited.
  • A GET reply carries an ETag. Send it back as If-None-Match, and a reply that has not changed comes back as 304 Not Modified.
  • List replies that page say how to ask for the next page; use only the cursor or offset the panel returned.
  • On 429, wait before trying again.

Renewing clients (POST clients/renew) and other money-moving calls take an Idempotency-Key header of 8 to 128 letters, digits and the signs - _ . :, a new one for each thing you mean to do. Send the same key again after a lost reply and you get the first reply back, with the header Idempotent-Replayed: true, and nothing is charged or done twice. The same key with other content is refused with idempotency_key_reused (422). While the first request is still running the same key gets idempotency_in_progress (409), and if the first one went through but its reply was lost in a restart, idempotency_reply_lost (409). The panel keeps keys for 7 days.

These are the calls this page documents. Each must match the router. A token can never make backups, restore, password, two-factor or token-minting calls.

Call Token access
GET clients read or clients
POST clients clients
GET clients/ID read or clients
GET clients/ID/config read or clients
POST clients/renew clients
PUT clients/ID clients
DELETE clients/ID clients
GET status read
GET health none

Create a client, read its config link, renew it, then disable it:

Terminal window
BASE='https://panel.example.com:2053/SECRET-PATH/api/v1'
AUTH='Authorization: Bearer aft_YOUR_TOKEN'
curl -sS -H "$AUTH" -H 'Content-Type: application/json' \
-d '{"name":"script-demo","inbounds":[1]}' \
"$BASE/clients"
curl -sS -H "$AUTH" "$BASE/clients/ID/config?inbound=1"
curl -sS -H "$AUTH" -H 'Content-Type: application/json' \
-H 'Idempotency-Key: renew-script-demo-1' \
-d '{"items":[{"id":ID,"days":30}]}' \
"$BASE/clients/renew"
curl -sS -X PUT -H "$AUTH" -H 'Content-Type: application/json' \
-d '{"enabled":false}' \
"$BASE/clients/ID"

If a create body is refused, copy the JSON from the Network tab on Clients when you add one by hand.

Monitoring and alerts shows how Prometheus uses a Read only token, and Security what to do when a token leaks.