PasarGuard
Node

API Reference

Complete REST API and gRPC reference for PasarGuard Node

API Overview

PasarGuard Node provides both REST API and gRPC interfaces for managing the node, users, and retrieving statistics.

Authentication

All API requests require authentication using the API_KEY configured in your .env file.

REST API:

Authorization: Bearer <api_key>

gRPC:

authorization: Bearer <api_key>

Base URL

REST API requests should be sent to:

https://your-node-address:port/

Content Type

REST API uses Protocol Buffers for data serialization:

Content-Type: application/x-protobuf

Data Structures

Backend

message Backend {
  BackendType type;      // Backend type (XRAY = 0)
  string config;         // Backend configuration
  repeated User users;   // List of users
  uint64 keepAlive;      // Keep alive duration in seconds
}

User

message User {
  string email;           // User's unique email identifier
  Proxy proxies;          // Proxy configurations
  repeated string inbounds; // List of inbound tags
}

StatRequest

message StatRequest {
  string name;      // User email or inbound/outbound tag
  bool reset;       // Reset traffic stats after retrieval
  StatType type;    // Type of stats to retrieve
}

enum StatType {
  Outbounds = 0;   // All outbound stats
  Outbound = 1;    // Single outbound stats
  Inbounds = 2;    // All inbound stats
  Inbound = 3;     // Single inbound stats
  UsersStat = 4;   // All users stats
  UserStat = 5;    // Single user stats
}

API Methods

Node Management

Start Backend

Start the node backend with configuration.

POST /start
Authorization: Bearer <api_key>
Content-Type: application/x-protobuf

Body: Backend (protobuf)
rpc Start(Backend) returns (BaseInfoResponse)

This is the only method called before creating a connection with the node.


Stop Backend

Stop the backend and deactivate client connections.

PUT /stop
Authorization: Bearer <api_key>
rpc Stop(Empty) returns (Empty)

Get Base Info

Retrieve basic node information and check connection status.

GET /info
Authorization: Bearer <api_key>
rpc GetBaseInfo(Empty) returns (BaseInfoResponse)

Response:

message BaseInfoResponse {
  string version;
  string core_type;
  bool running;
}

Logging

Get Logs

Stream real-time logs from the backend.

GET /logs
Authorization: Bearer <api_key>

// Returns Server-Sent Events (SSE) stream
rpc GetLogs(Empty) returns (stream Log)

Log Structure:

message Log {
  string detail;  // Log message
}

Statistics

Get System Stats

Retrieve system-level statistics.

GET /stats/system
Authorization: Bearer <api_key>
rpc GetSystemStats(Empty) returns (SystemStatsResponse)

Response:

message SystemStatsResponse {
  uint64 mem_total;                  // Total memory
  uint64 mem_used;                   // Used memory
  uint64 cpu_cores;                  // CPU cores
  double cpu_usage;                  // CPU usage %
  uint64 incoming_bandwidth_speed;   // Download speed
  uint64 outgoing_bandwidth_speed;   // Upload speed
}

Get Backend Stats

Retrieve backend runtime statistics.

GET /stats/backend
Authorization: Bearer <api_key>
rpc GetBackendStats(Empty) returns (BackendStatsResponse)

Response:

message BackendStatsResponse {
  uint32 num_goroutine;    // Active goroutines
  uint32 num_gc;           // GC runs
  uint64 alloc;            // Allocated memory
  uint64 total_alloc;      // Total allocated
  uint64 sys;              // System memory
  uint64 mallocs;          // Malloc count
  uint64 frees;            // Free count
  uint64 live_objects;     // Live objects
  uint64 pause_total_ns;   // Total GC pause
  uint32 uptime;           // Uptime in seconds
}

Get Traffic Stats

Retrieve traffic statistics for users, inbounds, or outbounds.

GET /stats
Authorization: Bearer <api_key>
Content-Type: application/x-protobuf

Body: StatRequest (protobuf)
rpc GetStats(StatRequest) returns (StatResponse)

Examples:

Get all users' stats:

StatRequest {
  type: UsersStat,
  reset: false
}

Get specific user stats:

StatRequest {
  name: "user@example.com",
  type: UserStat,
  reset: true  // Reset after retrieval
}

Response:

message StatResponse {
  repeated Stat stats;
}

message Stat {
  string name;   // User email or tag
  string type;   // Stat type
  string link;   // Link identifier
  int64 value;   // Traffic value in bytes
}

Get User Online Stats

Get online connection count for a user.

GET /stats/user/online
Authorization: Bearer <api_key>
Content-Type: application/x-protobuf

Body: StatRequest (protobuf)
rpc GetUserOnlineStats(StatRequest) returns (OnlineStatResponse)

Response:

message OnlineStatResponse {
  string name;   // User email
  int64 value;   // Online connection count
}

Get User Online IP List

Get list of IPs for online user connections.

GET /stats/user/online_ip
Authorization: Bearer <api_key>
Content-Type: application/x-protobuf

Body: StatRequest (protobuf)
rpc GetUserOnlineIpListStats(StatRequest) returns (StatsOnlineIpListResponse)

User Management

Sync User

Add, update, or remove a single user.

PUT /user/sync
Authorization: Bearer <api_key>
Content-Type: application/x-protobuf

Body: User (protobuf)
rpc SyncUser(stream User) returns (Empty)

To remove a user, send empty inbounds array. gRPC provides a stream interface, but REST requires individual calls per user.


Sync Users

Replace all users with a new set.

PUT /users/sync
Authorization: Bearer <api_key>
Content-Type: application/x-protobuf

Body: Users (protobuf)
rpc SyncUsers(Users) returns (Empty)

This method removes all old users and replaces them with the provided list.


Error Responses

HTTP Status Codes

CodeMeaning
200Success
400Bad Request - Invalid data
401Unauthorized - Invalid API_KEY
404Not Found - Endpoint doesn't exist
500Internal Server Error

Error Format

{
  "error": "Error description",
  "code": "ERROR_CODE"
}

Rate Limiting

There are currently no built-in rate limits, but it's recommended to:

  • Batch user updates when possible
  • Cache statistics locally
  • Avoid excessive polling