Authorization header of every API request.
Getting Your Token
There are two ways to obtain your authentication token:1. Using the CLI Command
The simplest way to get your token is using thesurge token command:
2. Setting a Custom Token
You can set a custom token when starting the server: Using a command-line flag:The
--token flag takes precedence over the SURGE_TOKEN environment variable.Using the Token
Include your token in theAuthorization header with the Bearer scheme:
Example with JavaScript
Example with Python
Token Storage
Tokens are stored securely in your Surge configuration directory:- Linux/macOS:
~/.config/surge/token - Windows:
%APPDATA%\surge\token
Unauthorized Requests
If you make a request without a valid token or with an incorrect token, the API will return a401 Unauthorized error:
Token Rotation
To rotate your token, simply generate a new one by restarting the server with a new--token value or by updating the SURGE_TOKEN environment variable. You can also manually edit the token file in your configuration directory.