All guides
Technology

Pyrogram Hosting: VPS Setup, Limits, Costs, and Security

Pyrogram hosting on a VPS: choose resources, persist sessions, configure systemd, handle Telegram limits, and avoid common deployment failures.

SJslipjar.app 4 December 2026 11 min read 32 views
On this page

Pyrogram hosting usually means running a Python Telegram bot or user client on a Linux VPS with persistent storage, automatic restarts, and controlled rate limits. A small bot rarely needs a powerful server: the critical requirements are stable networking, protected API credentials, durable session files, and a process manager such as systemd or Docker.

  • Telegram limits free bot broadcasts to about 30 messages per second; group bots should stay below 20 messages per minute.
  • Pyrogram stores file-based sessions in SQLite, so an ephemeral VPS filesystem can force repeated logins after restarts.
  • Pyrogram’s default worker setting is min(32, os.cpu_count() + 4), while upload and download concurrency defaults to 1.
  • Paid Telegram broadcasts can reach up to 1,000 messages per second at 0.1 Telegram Stars per message above the free allowance, subject to eligibility requirements.

Choose a VPS by workload, region, storage, and real-world testing instead of buying excess CPU for a lightweight bot.

Подобрать VPS на Valebyte

What Pyrogram Hosting Actually Requires

Pyrogram is a Python framework for Telegram’s MTProto API and Bot API workflows. Hosting does not require a special “Pyrogram server.” A regular Linux VPS is enough if it provides Python, outbound network access, persistent disk, and a way to restart the process after failure.

CPU usage depends more on the bot’s workload than on Pyrogram itself. A command bot that receives text and sends short replies has a different profile from a media downloader that resizes images, transcodes audio, or runs OCR. The latter workloads can saturate CPU, RAM, disk I/O, or bandwidth long before Telegram becomes the bottleneck.

Resource planning by workload

WorkloadMain constraintPractical hosting concern
Command and moderation botReliability and latencyKeep the process online and protect the session
Channel monitor or parserAPI limits and concurrencyUse queues, backoff, and bounded workers
Media downloaderDisk, bandwidth, and CPUMonitor temporary files and cleanup jobs
User client with many dialogsSession integrity and flood limitsBack up the session carefully and avoid aggressive polling

RAM capacity is not a useful proxy for bot quality by itself. A VPS with spare memory but slow storage can still produce failed downloads, delayed session writes, or long restart times. Conversely, a small instance can run a simple event-driven bot reliably if its external work is delegated to a database, object storage, or a separate worker.

For a broader deployment walkthrough, the Pyrogram hosting tutorial for deploying bots on a VPS covers the surrounding server decisions and operational sequence.

Session Storage Is the First Deployment Decision

Pyrogram file storage writes session data to a SQLite file, normally with a .session suffix. That file contains authorization data associated with the Telegram identity. Deleting it can trigger a new login; exposing it can give another party access to the account or bot session.

Pyrogram’s documentation describes three relevant storage patterns: file storage, in-memory storage, and session strings. File storage is the simplest choice for a normal VPS because the disk survives process restarts. In-memory storage avoids writing the session to disk, but the session disappears when the client stops unless a session string is exported.

telegram-bot/
├── app.py
├── .env
├── requirements.txt
├── bot.session
└── logs/

Session permissions should be narrower than ordinary application files. A dedicated Linux user prevents the bot process from reading unrelated credentials, SSH keys, or other services’ data.

sudo useradd --system --home /opt/telegram-bot --shell /usr/sbin/nologin telegram
sudo chown -R telegram:telegram /opt/telegram-bot
sudo chmod 700 /opt/telegram-bot
sudo chmod 600 /opt/telegram-bot/.env /opt/telegram-bot/*.session

Pyrogram’s storage engine documentation explains why a persistent session matters. Its Client reference also documents session_string, in_memory, workers, workdir, and transmission settings.

Valebyte helps compare VPS and dedicated-server options for bots, VPNs, Forex workloads, and game servers using published plan details and testing data.

Compare Valebyte VPS options or Подобрать VPS на Valebyte

Linux Deployment: systemd, Environment Variables, and Logs

systemd is a practical default for one or several Pyrogram processes on a Linux VPS. It starts the application after boot, restarts it after an unexpected exit, and sends logs to the journal without requiring a second monitoring stack.

Minimal application configuration

import os
from pyrogram import Client, filters

app = Client(
    "bot",
    api_id=int(os.environ["API_ID"]),
    api_hash=os.environ["API_HASH"],
    bot_token=os.environ["BOT_TOKEN"],
    workdir="/opt/telegram-bot"
)

@app.on_message(filters.command("start"))
async def start_handler(client, message):
    await message.reply_text("Online")

app.run()

Environment variables keep credentials out of source control. The API ID and API hash come from Telegram’s application credentials, while the bot token comes from BotFather. A user client requires a different authorization flow and should be treated as a higher-risk identity than a bot account.

[Unit]
Description=Pyrogram bot
After=network-online.target
Wants=network-online.target

[Service]
User=telegram
WorkingDirectory=/opt/telegram-bot
EnvironmentFile=/opt/telegram-bot/.env
ExecStart=/usr/bin/python3 /opt/telegram-bot/app.py
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now pyrogram-bot
sudo journalctl -u pyrogram-bot -f

RestartSec=5 is not a Telegram setting; it is a local recovery delay. A short delay handles transient failures, but it does not solve a bad token, invalid session, or a loop that repeatedly crashes on startup. Add health checks and alerting once the bot handles payments, moderation, or business notifications.

Telegram Limits Matter More Than VPS CPU

Telegram Bot API limits usually determine throughput before CPU does. Telegram’s official FAQ says bots should avoid sending more than one message per second in a single chat, more than 20 messages per minute in a group, and more than approximately 30 messages per second for bulk notifications.

Paid broadcasts raise the broadcast ceiling to as much as 1,000 messages per second. Telegram states that messages above the free 30-per-second allowance cost 0.1 Stars each, and that the feature requires at least 100,000 Stars in the bot balance and at least 100,000 monthly active users. That makes paid broadcasting irrelevant for most small bots.

Telegram’s official Bot FAQ recommends spreading bulk notifications over longer intervals. The correct engineering response to a 429 error is a queue with retry-after handling, not a larger VPS.

Backoff and bounded concurrency

import asyncio
from pyrogram.errors import FloodWait

async def send_with_backoff(client, chat_id, text):
    try:
        return await client.send_message(chat_id, text)
    except FloodWait as error:
        await asyncio.sleep(error.value)
        return await client.send_message(chat_id, text)

Pyrogram’s default sleep threshold is 10 seconds for automatic handling of some flood waits. Longer waits can still be raised to the application. Treat the exception as a scheduling signal: slow down the queue, record the affected method, and avoid retrying every message simultaneously.

The non-obvious point is that adding workers can reduce reliability. Pyrogram’s default worker count is min(32, os.cpu_count() + 4), but more handlers do not create more Telegram capacity. If each worker generates outbound requests, the application can reach API limits faster and create a larger retry backlog.

For bots that serve trading alerts or time-sensitive notifications, compare the architecture with the recommendations in the low-latency Forex hosting setup guide. Network distance matters, but Telegram’s application-level limits still govern message delivery.

Security and Operations for Pyrogram VPS Hosting

API credentials should be treated like production secrets. Do not commit .env, session files, exported session strings, or bot tokens to Git. If a session is exposed, revoke it from Telegram’s active sessions or regenerate the bot token where appropriate.

Operational checklist

  • Run Pyrogram under a dedicated non-login user.
  • Allow SSH access with keys and disable password authentication where practical.
  • Keep the operating system and Python dependencies updated on a defined schedule.
  • Send systemd logs to a retained destination if incident history matters.
  • Monitor disk usage because media downloads and SQLite files can grow silently.
  • Back up configuration and database data, but handle session backups as sensitive credentials.
  • Use a queue for broadcasts, media processing, and scheduled jobs.

Docker is useful when the same bot must run consistently across development and production. It does not remove the need for persistent volumes. Mount the directory containing the session file, or use a carefully protected session string with a secret manager.

services:
  bot:
    build: .
    restart: unless-stopped
    env_file:
      - .env
    volumes:
      - ./data:/opt/telegram-bot/data

For a user client, privacy and account safety deserve more attention than container convenience. The anonymous VPS hosting guide discusses privacy-related trade-offs, but anonymity does not excuse weak credential handling or abusive Telegram behavior.

What We Got Wrong / What Surprised Us

The strongest non-commodity signal is session durability. Hosting comparisons often lead with vCPU, RAM, and storage size. For Pyrogram, a lost session file can interrupt service regardless of how powerful the server is. Persistent storage, permissions, and recovery procedures are first-order requirements.

The surprising constraint is not raw throughput. A bot may have unused CPU while still failing because it sends too many messages to one chat, exceeds group limits, or retries after a flood wait without coordination. Telegram’s 30-message-per-second bulk limit and 20-message-per-minute group limit make queue design more valuable than simply selecting a larger instance.

The common mistake is treating “always online” as the whole requirement. A process that stays alive but loses its session, fills its disk, or floods Telegram is not a reliable service. Availability includes authorization recovery, controlled retries, logs, and a known restart path.

Practical Takeaways

  1. Classify the bot workload. Separate text handling, scheduled broadcasts, media processing, and user-client automation. Expected outcome: a resource decision based on CPU, disk, bandwidth, or API limits. Time: 15–30 minutes. Difficulty: low.
  2. Deploy under a dedicated Linux user. Store the session and environment file outside the source repository with restrictive permissions. Expected outcome: reduced credential exposure. Time: 20–40 minutes. Difficulty: low.
  3. Choose persistent session storage. Use Pyrogram’s file storage on a VPS, or store a protected session string when the filesystem is ephemeral. Expected outcome: restarts without repeated authorization. Time: 15–30 minutes. Difficulty: medium.
  4. Add systemd restart behavior. Configure Restart=on-failure, inspect journalctl, and test a manual restart. Expected outcome: recovery from ordinary process exits. Time: 20 minutes. Difficulty: low.
  5. Implement FloodWait handling and a queue. Respect the 1-message-per-second single-chat guidance, 20 messages per minute in groups, and approximately 30 messages per second for free broadcasts. Expected outcome: fewer 429 errors and less retry amplification. Time: 1–3 hours. Difficulty: medium.
  6. Test failure recovery. Reboot the VPS, remove network access briefly, and verify that the process reconnects without exposing credentials. Expected outcome: a known recovery path before production use. Time: 30–60 minutes. Difficulty: medium.

For a bot, the right VPS is the one that matches its workload and survives restarts without losing authorization. Use Valebyte to compare available VPS and dedicated-server options before committing to excess resources.

Подобрать VPS на Valebyte

FAQ

What is the best VPS size for Pyrogram hosting?

A lightweight command bot usually needs only a small Linux VPS, but the exact size depends on media processing, databases, concurrent jobs, and logging. Telegram rate limits often matter more than CPU for notification bots.

Does Pyrogram need a dedicated server?

No. Pyrogram runs on a normal VPS with Python, outbound connectivity, persistent storage, and a process manager. A dedicated server becomes reasonable when the workload also includes CPU-heavy media processing, large databases, or several unrelated services.

Where does Pyrogram store the session?

Pyrogram’s file storage uses a SQLite-backed session file in the client working directory. The working directory can be set with workdir; session strings and in-memory storage are alternatives for environments where local files are unsuitable.

How many Telegram messages can a Pyrogram bot send per second?

Telegram’s official guidance allows approximately 30 bulk messages per second for free broadcasts, with tighter limits of one message per second in a single chat and 20 messages per minute in a group. Paid broadcasts can reach up to 1,000 messages per second under Telegram’s stated eligibility and billing conditions.

SJ

slipjar.app

Editorial team

The slipjar.app team writes about hosting, servers and infrastructure in plain language.

Was this article helpful?
Technology

Read next.

Whole category

New guides every week.

A digest of the best pieces on servers, VPN and self-hosted software. No ads, no spam.

1 email a weekOne-click unsubscribeRU · EN
Only slipjar.app articles, nothing else.