MarzbanSDK
Modules

System

Server stats, inbound listing, and proxy host management via sdk.system.

sdk.system provides access to server-level information: resource usage, protocol inbounds, and proxy host configuration.

Types

SystemStats

Returned by getSystemStats.

import type { SystemStats } from 'marzban-sdk'
FieldTypeDescription
versionstringMarzban version string
mem_totalnumberTotal RAM in bytes
mem_usednumberUsed RAM in bytes
cpu_coresnumberNumber of CPU cores
cpu_usagenumberCPU usage percentage (0–100)
total_usernumberTotal number of users
users_activenumberUsers with active status
users_disablednumberUsers with disabled status
users_limitednumberUsers who hit their data limit
users_expirednumberUsers whose subscription expired
users_on_holdnumberUsers with on_hold status
online_usersnumberCurrently connected users
incoming_bandwidthnumberTotal inbound traffic in bytes
outgoing_bandwidthnumberTotal outbound traffic in bytes
incoming_bandwidth_speednumberCurrent inbound speed in bytes/s
outgoing_bandwidth_speednumberCurrent outbound speed in bytes/s

ProxyInbound

A single inbound configured in the Xray core. getInbounds returns these grouped by protocol.

import type { ProxyInbound } from 'marzban-sdk'
FieldTypeDescription
tagstringInbound tag — the identifier you pass in a user's inbounds.
protocol'vmess' | 'vless' | 'trojan' | 'shadowsocks'Proxy protocol.
networkstringTransport network, e.g. tcp, ws, grpc.
tlsstringTLS mode, e.g. none, tls, reality.
portnumber | stringListening port.

ProxyHost

A proxy host entry attached to an inbound tag. getHosts returns these grouped by inbound tag.

import type { ProxyHost } from 'marzban-sdk'
FieldTypeDescription
remarkstringDisplay label for the host. Supports template variables like {SERVER_IP}.
addressstringHost address (domain or IP). Also supports template variables.
portnumber | nullOverride port; null uses the inbound's own port.
snistring | nullServer Name Indication.
hoststring | nullHTTP Host header.
pathstring | nullRequest path for ws / grpc / http transports.
security'inbound_default' | 'none' | 'tls'TLS security mode. Default: inbound_default.
alpn'' | 'h2' | 'h3' | 'http/1.1' | …ALPN value. Default: ''.
fingerprint'' | 'chrome' | 'firefox' | 'safari' | …TLS fingerprint to mimic. Default: ''.
allowinsecureboolean | nullAllow insecure (unverified) TLS certificates.
is_disabledboolean | nullDisable this host entry.
mux_enableboolean | nullEnable connection multiplexing.
fragment_settingstring | nullTLS fragmentation settings.
noise_settingstring | nullNoise (obfuscation) settings.
random_user_agentboolean | nullSend a randomised User-Agent per request.
use_sni_as_hostboolean | nullUse the SNI value as the Host header.

Methods

getSystemStats()

Get overall system resource and traffic statistics.

Returns

const stats = await sdk.system.getSystemStats()

console.log(stats.version)
console.log(stats.users_active, '/', stats.total_user)
console.log(`CPU: ${stats.cpu_usage.toFixed(1)}%`)
console.log(`RAM: ${stats.mem_used} / ${stats.mem_total} bytes`)

getInbounds()

List all available inbounds configured in Xray core — inbound tags grouped by protocol.

Returns Record<string, []>

const inbounds = await sdk.system.getInbounds()

// Returns Record<protocol, ProxyInbound[]>
// e.g. { vless: [...], vmess: [...], trojan: [...] }
for (const [protocol, tags] of Object.entries(inbounds)) {
  console.log(protocol, tags)
}

Use this to discover which inbound tags to pass when creating users.


getHosts()

Get the current proxy host configuration for all inbound tags — proxy hosts grouped by inbound tag.

Returns Record<string, []>

const hosts = await sdk.system.getHosts()

// Returns Record<inboundTag, ProxyHost[]>
for (const [tag, hostList] of Object.entries(hosts)) {
  for (const host of hostList) {
    console.log(tag, host.remark, host.address, host.port)
  }
}

modifyHosts(data)

Replace the proxy host configuration. The full host map must be provided (replaces existing config).

Returns Record<string, []> — the updated host map

await sdk.system.modifyHosts({
  'VLESS TCP REALITY': [
    {
      remark: 'Main Server',
      address: '203.0.113.10',
      port: 443,
      sni: 'example.com',
      host: 'example.com',
      security: 'reality',
      fingerprint: 'chrome',
    },
  ],
})

Common patterns

Dashboard stats widget

import { formatBytes } from 'marzban-sdk'

const stats = await sdk.system.getSystemStats()

console.log(`
  Marzban ${stats.version}
  CPU:     ${stats.cpu_usage.toFixed(1)}% (${stats.cpu_cores} cores)
  Memory:  ${formatBytes(stats.mem_used)} / ${formatBytes(stats.mem_total)}
  Users:   ${stats.users_active} active / ${stats.total_user} total
  Online:  ${stats.online_users}
`)

On this page