npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

marzban-sdk

v1.4.3

Published

Fully typed client SDK for the Marzban API, supporting both browser and Node.js environments.

Readme

🚀 MarzbanSDK

npm version npm downloads total downloads license GitHub stars


🚧 We're working on Marzban SDK 2.0.0 — the biggest update yet!

We're working on the biggest update yet — version 2.0.0! This release brings fundamental improvements:

  • 🛡️ Strict validation with Zod schemas
  • 🔌 Plugin system for HTTP & WebSocket requests
  • ⚠️ Unified error system with dedicated classes
  • 📝 Configurable logger
  • 💻 CLI tool (planned)

👉 Share your feedback! What features would you like to see? 👉 Join the discussion on GitHub


MarzbanSDK is a fully typed TypeScript client for interacting with the Marzban API.
It provides a clean, consistent, and developer-friendly interface — with built-in authentication, retries, and WebSocket support.

Unlike some SDK generators, MarzbanSDK does not dynamically generate or rebuild code from OpenAPI.
Instead, all methods and types are implemented directly as strongly-typed TypeScript definitions, originally based on Marzban’s OpenAPI schema — but maintained and refined manually for better developer experience.

The SDK works seamlessly in both Node.js and browser environments.

👉 View on GitHub


📖 Table of Contents


✨ Features

  • First-class TypeScript Support — All methods, parameters, and responses are strongly typed.
  • 🌐 Works in Node.js and Browser — Fully compatible with both environments.
  • 🔐 Manual or Automatic Authorization — Choose explicit or automatic login with full error handling.
  • 🔄 Auto Token Refresh — Automatic session renewal on expiration.
  • 🔁 Retry Logic — Resilient against temporary network errors.
  • 📡 Real-time WebSocket Logging — Stream logs from core or nodes.
  • 📘 OpenAPI-based Implementation — Methods and types are derived from Marzban’s OpenAPI specification, but implemented as native TS code for stability and flexibility.

📦 Installation

Install MarzbanSDK via npm:

npm install marzban-sdk

Or using yarn:

yarn add marzban-sdk

📑 Configuration Options

The Config object is used to initialize the MarzbanSDK instance. Below are all available options:

| Name | Type | Required | Default | Description | | -------------------- | ------- | -------- | ------- | -------------------------------------------------------------------------------------------------- | | baseUrl | string | Yes | — | The base URL of the Marzban API instance. Example: https://api.example.com | | username | string | Yes | — | The username for authentication. | | password | string | Yes | — | The password for authentication. | | token | string | No | — | Optional JWT token for direct authorization. If provided, SDK uses this token for requests. | | retries | number | No | 3 | Number of automatic retries for failed HTTP requests. | | authenticateOnInit | boolean | No | true | If true (default), SDK authenticates automatically on init. If false, call authorize() manually. |


🔐 Authorization Control

MarzbanSDK gives you full control over authentication:

  • Automatic authentication (default): The SDK logs in as soon as you create an instance.
  • Manual authentication: Set authenticateOnInit: false to delay login and handle errors yourself.
import { MarzbanSDK, AuthenticationError } from 'marzban-sdk'

const sdk = new MarzbanSDK({
  baseUrl: 'https://api.example.com',
  username: 'admin',
  password: 'secret',
  authenticateOnInit: false, // Manual mode
})

try {
  await sdk.authorize() // Explicit login
  // Now you can make authenticated requests
} catch (e) {
  if (e instanceof AuthenticationError) {
    // Handle authentication failure
  }
}

// Fetch user details
sdk.user.getUserById('user-id').then(user => {
  console.log(user)
})

// Get an authorization token
sdk.getAuthToken().then(token => {
  console.log(token)
})

You can also force re-authentication at any time:

await sdk.authorize(true) // Force a new login, even if already authenticated

See Config interface documentation for all available options.


🚀 Quick Start

import { MarzbanSDK, Config } from 'marzban-sdk'

const sdk = new MarzbanSDK({
  baseUrl: 'https://api.example.com',
  username: 'your-username',
  password: 'your-password',
})

// Fetch user details
sdk.user.getUserById('user-id').then(user => {
  console.log(user)
})

// Get an authorization token
sdk.getAuthToken().then(token => {
  console.log(token)
})

🔍 How It Works

MarzbanSDK is built around a clean TypeScript architecture:

1️⃣ Strong Typing and Validation

Every method, parameter, and response is defined using TypeScript types derived from Marzban’s OpenAPI schema.

2️⃣ Static Implementation

The SDK itself is not generated at runtime — all types and methods are implemented within the library for consistency and performance.

3️⃣ Unified API Interface

Access all Marzban endpoints through a single, well-structured class: MarzbanSDK.

4️⃣ Cross-Platform Support

The SDK uses platform-agnostic HTTP clients, making it work seamlessly in:

  • Node.js environments
  • Modern browsers
  • React/Next.js applications
  • Other JavaScript runtimes

📚 API Documentation

Full API reference and usage examples are available here:

API Documentation.


📡 WebSocket Support

MarzbanSDK supports WebSocket for real-time log streaming.
You can receive logs from both the core server and individual nodes.

For more details, check the WebSocket Guide.


🤝 Contributing

We welcome contributions! Whether you're fixing bugs, adding features, or improving documentation:

  1. 🚀 Fork the repository
  2. 🔧 Create a feature branch
  3. 📝 Make your changes
  4. 🎉 Submit a pull request

Check our Contribution Guidelines for details.


📜 License

This project is licensed under the MIT License. See LICENSE for details.


⭐ Support the Project

If MarzbanSDK helps your project, please:

  • ⭐ Star the repository on GitHub
  • 🐛 Report issues you encounter
  • 💡 Suggest improvements and new features
  • 📢 Share with other developers

Your support helps us improve the library for everyone! ❤️


MarzbanSDK - TypeScript client for Marzban API • GitHub Repository