# Authentication · XProxy Box API

> How the XProxy Box API decides who may call it: HTTP Basic login (base64), Full access and Rotate only API keys, the callers that need no password (LAN, whitelist, Tailscale), the Force API Auth switches and every 401 answer.

Page: https://xproxy.io/docs/api/authentication

The box checks every call in this order: an API key if one is sent, then the address the call comes from, then the dashboard username and password. This page explains each step, the switches that change it, and what the box answers when it refuses a call.

To turn the switches on and off in the panel, follow [Secure the XProxy dashboard](https://xproxy.io/document/secure-your-dashboard).

## Three ways to sign in

| Method | How you send it | Where it works | Use it for |
| --- | --- | --- | --- |
| Admin login (HTTP Basic) | `Authorization: Basic <base64 of user:password>`, or `curl -u user:password` | Every route, including API key management | Your own scripts and the panel |
| Full access key (`xpf_…`) | `Authorization: Bearer xpf_YOUR_KEY` only, never in a URL | Every route that accepts the admin login, except API key management | Bots, servers and tools that should not know your password |
| Rotate only key (`xpr_…`) | `?token=xpr_YOUR_KEY` on the link, or `Authorization: Bearer xpr_YOUR_KEY` | Only the rotation links `/reset`, `/api/v1/rotate_ip/proxy/{proxy}` and `/api/v1/rotate_ip/position/{position}` | The Change IP URL of AdsPower, Dolphin and other antidetect browsers |

API keys exist from XProxy v21.3.61. Older boxes accept only the admin login.

Some links carry their own token and ignore everything on this page: the per-port [token links](https://xproxy.io/docs/api/box/get-status-with-port-token), the selling platform links ([`?token=` of a sold proxy](https://xproxy.io/docs/api/box/rotate-selling-proxy-ip)) and the [VPN rotation link](https://xproxy.io/docs/api/box/rotate-vpn-ip). Treat each of those tokens like a password.

## HTTP Basic auth: the admin login in a header

Basic auth sends the dashboard username and password in the `Authorization` header. Join them with a colon, encode the result as base64, and put `Basic ` in front. For the username `admin` and the password `secret`:

```
admin:secret  →  base64  →  YWRtaW46c2VjcmV0

Authorization: Basic YWRtaW46c2VjcmV0
```

Check your own value in a terminal (`-n` keeps the line break out of it):

```bash
echo -n 'admin:secret' | base64
# YWRtaW46c2VjcmV0
```

Most tools build the header for you:

cURL:

```bash
# curl encodes the login itself
curl -u "admin:secret" "http://192.0.2.10/api/v1/info_list"

# the same request with the header written out
curl -H "Authorization: Basic YWRtaW46c2VjcmV0" "http://192.0.2.10/api/v1/info_list"
```

Python:

```python
import requests

r = requests.get("http://192.0.2.10/api/v1/info_list", auth=("admin", "secret"), timeout=30)
print(r.status_code, r.json())
```

Node.js:

```javascript
const login = Buffer.from("admin:secret").toString("base64");
const r = await fetch("http://192.0.2.10/api/v1/info_list", {
  headers: { Authorization: `Basic ${login}` },
});
console.log(r.status, await r.json());
```

PHP:

```php
$ch = curl_init("http://192.0.2.10/api/v1/info_list");
curl_setopt($ch, CURLOPT_USERPWD, "admin:secret");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo curl_exec($ch);
```

Things to know:

- base64 is an encoding, not encryption. Anyone who sees the request can read the password. Over the internet, call the box through HTTPS (a domain with a certificate) or through Tailscale, or use an API key you can delete at any time.
- The box checks the password only while **Dashboard Auth** is on. While it is off, no password is ever accepted, so a caller that is not trusted (see [Who can call without a password](https://xproxy.io/docs/api/authentication#trusted)) is refused even with the right login.
- The box splits at the first colon. A colon inside the password is fine; a colon inside the username is not.
- The login is the one you set under **General Settings → System Setting → Security → Dashboard Auth**.

## API keys: Bearer header or token on the link

The panel admin creates keys under **Settings → System Setting → Security → API keys** ([step by step](https://xproxy.io/document/secure-your-dashboard#api-keys)), or through [Create an API key](https://xproxy.io/docs/api/box/create-api-key). A key is shown once, when it is created or regenerated; afterwards the panel shows only a masked form such as `xpf_…abcd`.

Full access key:

```bash
curl -H "Authorization: Bearer xpf_YOUR_KEY" "http://192.0.2.10/api/v1/info_list"
```

Rotate only key in a Change IP URL:

```
http://192.0.2.10/api/v1/rotate_ip/position/3?token=xpr_YOUR_KEY
```

- A key is checked before anything else. A valid key passes from any address, also when Force API Auth is on. A key that is not valid is refused with `invalid_token` from every address, the LAN and the box itself included: the box never falls back to the LAN or whitelist exemption.
- Keep a Full access key out of URLs: links end up in browser history, proxy logs and `Referer` headers. A Full access key sent as `?token=` is refused.
- A Rotate only key can rotate IPs and nothing else, so it is the safe choice for a link you paste into another program.
- A key can expire. Regenerating a key stops the old secret at once; deleting it stops it for good. A box holds at most 50 keys.
- Keys cannot manage keys: [`/v2/api_keys`](https://xproxy.io/docs/api/box/list-api-keys) and its sub-routes need the admin login and refuse every key.

## Who can call without a password

Some callers are trusted by their address and need no login:

- The box itself (`127.0.0.1`): always.
- The LAN: any private IPv4 address (`10.x`, `172.16-31.x`, `192.168.x`), unless **Force LAN Auth** is on.
- Whitelisted IPs: the ranges in **Whitelist IPs**, while **IP Auth** is on.
- Tailscale: devices on the box's Tailscale network, while the **Tailscale** switch allows it.

Calls that reach the box through VPS forwarding are never trusted by address: through the VPS they arrive from a local address, so the box treats them like internet traffic and asks for a login or a key.

The box has two kinds of routes:

- **Public routes**: rotate, status, reboot and proxy list (`/api/v1/…` and the legacy `/reset`, `/status`, `/reboot_usb`). While **Force API Auth** is off, anyone who can reach the box can call them. Turn it on to require a trusted address, the login or a key.
- **Panel routes**: everything else (settings, modems, logs, …). They always need a trusted address, the admin login or a Full access key. Force API Auth does not change them.

Public routes, by caller and settings:

| Caller | Force API Auth off (default) | Force API Auth on, Dashboard Auth off | Force API Auth on, Dashboard Auth on |
| --- | --- | --- | --- |
| The box itself (127.0.0.1) | Open | Open | Open. Loopback is always trusted. |
| LAN | Open | Open. Refused when Force LAN auth is on. | Open. Needs credentials when Force LAN auth is on. |
| Whitelisted IP | Open | Refused. Open when IP whitelist auth is enabled (Disable IP whitelist auth off). | Login. Open when IP whitelist auth is enabled (Disable IP whitelist auth off). |
| Tailscale | Open | Refused. Open when Allow Tailscale without login is on. | Login. Open when Allow Tailscale without login is on. |
| Internet (WAN, domain or VPS forwarding) | Open. Anyone who can reach the box can call these routes. | Refused | Login. Traffic relayed through your VPS never gets the LAN, Tailscale or whitelist exemptions. |

- Open: Answers without credentials
- Login: Needs HTTP Basic credentials
- Refused: Refused (401), even with credentials

## The switches

All of them are in the panel under **General Settings → System Setting → Security**. [Secure the XProxy dashboard](https://xproxy.io/document/secure-your-dashboard) shows where each one is.

| Panel switch | Default | What it does |
| --- | --- | --- |
| **Dashboard Auth** (`dashboard_disable_auth` off) | Off | Checks the username and password. While it is off, no login is ever accepted. |
| **Force API Auth** (`api_auth_check`) | Off | Public routes then need a trusted address, the login or a key, like panel routes. |
| **Force LAN Auth** (`dashboard_force_auth_local`) | Off | LAN callers lose their exemption and must log in or send a key. |
| **IP Auth** (`dashboard_disable_ip_auth` off) | Off | Lets the addresses in **Whitelist IPs** in without a login. |
| **Tailscale** (`dashboard_auth_allow_tailscale`) | Off | Lets devices on the box's Tailscale network in without a login. |

> Turning on Force API Auth breaks rotation links that your bots or antidetect browsers call without a login. Give them a Rotate only key first, then turn the switch on.

## When the box says no

| HTTP and body | Why | What to do |
| --- | --- | --- |
| 401 `{"message": "Unauthorized. Your IP: 203.0.113.25"}` | The caller is not trusted and sent no valid login or key, while Force API Auth is off (a panel route, or a LAN caller with Force LAN Auth on). The IP is the address the box saw. | Send the login or a Full access key, or trust that address (whitelist, Tailscale). |
| 401 `{"message": "Unauthorized", "status": false}` | Force API Auth is on and the caller is not trusted and sent no valid login or key. | Send the login or a key. For rotation links, a Rotate only key. |
| 401 `{"status": false, "msg": "invalid_token"}` | An API key was sent and refused: unknown, expired, deleted, regenerated, malformed, a Full access key in `?token=`, a Rotate only key on a non-rotation route, or any key on `/v2/api_keys`. The body is the same in every case. | Check the key in the panel and create a new one if needed. Remove a `token` parameter you did not mean to send. |
| 401 plain text `Unauthorized Access` | A panel route refused the login. | Check the username and password, and that Dashboard Auth is on. |
| 403 `{"status": false, "code": "cross_origin"}` | A web page on another address called `/v2/api_keys` from a browser. | Manage keys in the panel itself, or call these routes from a script. |

A rotation link that carries a `token` value that is not a valid Rotate only key gets `invalid_token` instead of rotating, even from the LAN. Some tools append their own `token` parameter; remove it or replace it with your key.

## Which one should I use?

| You want to | Use |
| --- | --- |
| Change the IP from AdsPower, Dolphin or another antidetect browser | A Rotate only key in the Change IP URL |
| Run a bot or script on a server outside your LAN | A Full access key in the Bearer header, over HTTPS or Tailscale |
| Call the box from a computer on the same LAN | Nothing, unless Force LAN Auth is on |
| Manage API keys from a script | The admin login (keys cannot manage keys) |
| Open the box to the internet safely | Dashboard Auth with a strong password, then Force API Auth; see [Secure the XProxy dashboard](https://xproxy.io/document/secure-your-dashboard) |
