MarzbanSDK
Modules

Nodes

Add, query, update, and monitor Marzban worker nodes — addresses, ports, status, and reconnection — with full type safety via `sdk.node`.

sdk.node provides endpoints for adding, querying, and managing Marzban worker nodes.

Types

NodeResponse

Returned by getNode, addNode, modifyNode, and getNodes.

import type { NodeResponse } from 'marzban-sdk'
FieldTypeDescription
idnumberUnique node ID
namestringDisplay name
addressstringIP address or hostname
portnumberXray API port (default: 62050)
api_portnumberNode gRPC API port (default: 62051)
usage_coefficientnumberTraffic multiplier (default: 1)
status'connected' | 'connecting' | 'error' | 'disabled'Current connection state
xray_versionstring | nullXray version running on the node
messagestring | nullError message when status is 'error'

NodeCreate

Payload for addNode.

import type { NodeCreate } from 'marzban-sdk'
FieldTypeRequiredDescription
namestringYesDisplay name
addressstringYesIP address or hostname
portnumberNoDefault: 62050
api_portnumberNoDefault: 62051
usage_coefficientnumberNoTraffic multiplier, default: 1
add_as_new_hostbooleanNoAuto-create a host entry for this node, default: true

NodeModify

Payload for modifyNode — all fields optional. Omitted fields are left unchanged. Unlike , there is no add_as_new_host, and status can be set directly.

import type { NodeModify } from 'marzban-sdk'
FieldTypeRequiredDescription
namestring | nullNoDisplay name
addressstring | nullNoIP address or hostname
portnumber | nullNoXray API port
api_portnumber | nullNoNode gRPC API port
usage_coefficientnumber | nullNoTraffic multiplier
status'connected' | 'connecting' | 'error' | 'disabled' | nullNoForce a connection state, e.g. 'disabled'

NodeSettings

Returned by getNodeSettings — the global TLS settings used for node-to-core communication.

import type { NodeSettings } from 'marzban-sdk'
FieldTypeDescription
certificatestringTLS certificate that nodes use to authenticate with the core
min_node_versionstringMinimum supported node version. Default: "v0.2.0"

NodesUsageResponse

Returned by getUsage — traffic totals per node over the requested range.

import type { NodesUsageResponse } from 'marzban-sdk'
FieldTypeDescription
usages[]Per-node traffic entries

Each entry:

FieldTypeDescription
node_idnumber | nullNode ID; null for aggregated or unassigned traffic
node_namestringNode display name
uplinknumberBytes sent (upload)
downlinknumberBytes received (download)

Methods

getNodes()

List all configured nodes.

Returns []

const nodes = await sdk.node.getNodes()

for (const node of nodes) {
  console.log(node.id, node.name, node.status)
}

getNode(node_id)

Get a single node by ID.

Returns

const node = await sdk.node.getNode(1)
console.log(node.name)
console.log(node.status)   // 'connected' | 'connecting' | 'error' | 'disabled'
console.log(node.message)  // error details when status === 'error'

addNode(data)

Register a new node from a payload.

Returns

const node = await sdk.node.addNode({
  name: 'Frankfurt-01',
  address: '203.0.113.10',
  port: 62050,
  api_port: 62051,
  add_as_new_host: true,
})

console.log(node.id)
console.log(node.status) // 'connecting' initially

modifyNode(node_id, data)

Update a node's configuration from a payload.

Returns

await sdk.node.modifyNode(1, {
  name: 'Frankfurt-01 (updated)',
  address: '203.0.113.11',
  status: 'disabled',
})

removeNode(node_id)

Remove a node from Marzban.

Returns

await sdk.node.removeNode(1)

reconnectNode(node_id)

Force a node to reconnect.

Returns

await sdk.node.reconnectNode(1)

getUsage(params?)

Get traffic usage per node, optionally filtered by time range.

Returns

const usage = await sdk.node.getUsage({
  start: '2024-01-01T00:00:00',
  end:   '2024-01-31T23:59:59',
})

for (const entry of usage.usages) {
  console.log(entry.node_name, entry.uplink, entry.downlink)
}

getNodeSettings()

Retrieve the global node TLS certificate used for node-to-core communication.

Returns

const settings = await sdk.node.getNodeSettings()
console.log(settings.certificate)

Common patterns

Monitor node health

const nodes = await sdk.node.getNodes()

const unhealthy = nodes.filter(n => n.status === 'error')
for (const node of unhealthy) {
  console.warn(`Node ${node.name} error: ${node.message}`)
  await sdk.node.reconnectNode(node.id)
}

Add a node and wait for it to connect

const node = await sdk.node.addNode({
  name: 'Singapore-01',
  address: '10.0.0.5',
  add_as_new_host: true,
})

let current = node
while (current.status === 'connecting') {
  await new Promise(r => setTimeout(r, 2000))
  current = await sdk.node.getNode(node.id)
}

console.log('Node status:', current.status)

On this page