Heroku
This guide explains how to run KitDev on Heroku as a worker process. If you prefer your own server, see Docker or background.
It is written from Heroku's official documentation (consulted in November 2026) and has not been tested on a real deployment yet.
Before you start: costs and limits
Heroku no longer has a free plan. KitDev doesn't open ports, so it runs as a worker. These are the plans that work, with the prices from Heroku's documentation:
| Dyno | Price | For KitDev |
|---|---|---|
| Eco | 5 USD a month for 1000 hours, shared across all your Eco dynos | An Eco worker doesn't sleep and uses about 744 hours a month, so it fits in the hours pool. If you use it all up, all your Eco dynos sleep until the next month |
| Basic | 7 USD a month at most | It doesn't sleep and has no hours limit |
Both have 512 MB of RAM. You don't need a bigger plan.
Heroku's disk is ephemeral. Heroku restarts every dyno at least once a day (between 24 hours and 24 hours plus 216 minutes), and also every time you deploy code or change a variable, and on every restart it deletes everything that was written to disk.
KitDev keeps everything in the data/ folder, so on every restart it is wiped: the kitdev.sqlite3 database (gban, warnings, contacts, the sudo list, PM Permit accepted people and the bot's users for broadcast), state.json (all the settings: welcome, PM Permit, texts, the assistant's photo...), your snips and the downloaded addons.
So that you don't lose it, KitDev has automatic backups: it sends a copy of data/ to your logs group when the data changes and another when it shuts down, and on startup with an empty disk it restores the latest one. That is why LOG_CHAT_ID is required on Heroku. What is kept without backups is your environment variables (session, bot token, logs group, prefixes) and your Telegram account.
What is not recovered:
- What changed since the last backup, if Heroku kills the dyno without warning (for example, for lack of memory). At most, the minimum time you have chosen in the panel (1 hour by default).
- The backup sent on shutdown has about 20 seconds to upload, because Heroku warns with SIGTERM and shuts down after 30 seconds. If your data is heavy (for example, a lot of media), it may not arrive in time.
If you'd rather not depend on the backups, use a MongoDB or PostgreSQL database (for example, free Atlas, Supabase or Neon): with DATABASE_URL your data and settings live outside Heroku and are not lost on restart. See Database.
With that, Heroku also works for normal use, with those limitations. If you can't lose anything, a server where data/ is kept, like a VPS with Docker, is still the safest.
Requirements
- A Heroku account with a payment method
API_IDandAPI_HASHfrom my.telegram.org- Your own computer to generate the session (Python 3.10 or higher)
- A bot from @BotFather and a group for the logs
- For the terminal option: Git and the Heroku CLI
1. Prepare the data
Since the disk is wiped, KitDev can't remember this data between restarts: these five variables are required on Heroku.
| Variable | How to get it |
|---|---|
API_ID and API_HASH |
At my.telegram.org, in your app |
SESSION_STRING |
Run python3 gen_session.py on your own computer (see Generating your session). Copy it whole |
BOT_TOKEN |
Create a bot with @BotFather and copy its token (123456789:ABC...). Without it, the assistant would be created again on every restart |
LOG_CHAT_ID |
Create a group (or use the one KitDev created when it started on your computer), add the assistant bot as an administrator and write .id in it. It is the number that starts with -100. Without it, a new group would be created on every restart and KitDev wouldn't find your backups |
The SESSION_STRING gives full access to your account. Paste it only into your Heroku app's variables, never into a file in the repository.
DATABASE_URL (a MongoDB or PostgreSQL URI) is optional but highly recommended: with it nothing else is needed to keep your data. PREFIX, SUDO_PREFIX, ADDONS and AUTO_RESTORE are optional; their default values are in installation.
2. Deploy with the button
The repository includes an app.json with the variables, the worker and the buildpacks already defined.
- Press the button and sign in to Heroku.
- Give your app a name and fill in the variables from the previous step.
- Press Deploy app and wait for the build to finish.
- In the Resources tab, check that the
workeris on.
The button uses the repository's default branch. For another branch, add /tree/branch-name to the repository URL inside the link.
3. Deploy with the terminal
From the KitDev folder:
heroku login heroku create mi-kitdev heroku buildpacks:add https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git heroku buildpacks:add heroku/python heroku config:set API_ID=123456 API_HASH=tu_api_hash SESSION_STRING=la_cadena_completa BOT_TOKEN=123456789:ABC LOG_CHAT_ID=-1001234567890 git push heroku main heroku ps:scale worker=1 heroku logs --tail
- Heroku only deploys the remote's
mainormasterbranch. If you work on another one, usegit push heroku dev:main. - The
Procfiledeclares only aworkerprocess. Heroku starts thewebone by itself, but theworkerhas to be scaled to 1 (heroku ps:scale worker=1); the button already does it. - The
.python-versionasks for Python 3.12. Theruntime.txtfile is deprecated on Heroku. - The ffmpeg buildpack is from the community, not from Heroku. ffmpeg is only used for video stickers and the deployment message's animation; without it, that animation comes out as a GIF.
- To move to Basic:
heroku ps:resize worker=basic.
4. What changes on Heroku
- Updating: Heroku's code is not a Git clone, so there is no
git pulland no "Update Available" button. You update withgit push heroku main. Every deploy restarts the dyno: KitDev saves a backup when it shuts down and restores the latest one when it starts again. - Backups: they are automatic (see automatic backups). In the assistant's ⚙️ Settings → 💾 Backups you change how often they are sent or turn them off. After a restart, in Heroku's logs you will see "Datos restaurados desde la copia automática". The first time there are no backups: KitDev starts from scratch and sends the first one a few minutes after starting.
.restart: restarts only the KitDev process, without going through Heroku, anddata/is kept.- Startup messages: on every dyno restart (daily or more often) the assistant sends "KitDev detenido" to your logs group and, when it comes back, the deployment message.
- Shutdown: Heroku warns the dyno with SIGTERM and KitDev handles it as a normal shutdown.
5. Turning off or changing plan
heroku ps:scale worker=0turns KitDev off. With Basic you stop paying for that dyno; with Eco the 5 USD fee is charged anyway even if you don't use it.heroku ps:scale worker=1turns it on again: it starts with an empty disk and restores the latest backup.- Changing a variable (
heroku config:set) also restarts the dyno: a backup is saved on shutdown and restored on return.
If something fails
Always look at the logs with heroku logs --tail. KitDev explains in them which variable is wrong.
| What happens | What to do |
|---|---|
| No dyno is running | Run heroku ps:scale worker=1 |
SESSION_STRING: falta or parece incompleta |
Copy the whole session, without spaces or quotes |
BOT_TOKEN: formato inválido |
It must look like 123456789:ABC... |
| The dyno keeps restarting | Heroku waits longer and longer between attempts (up to about 5 hours). Fix the error in the logs and restart with heroku restart |
| A new bot or group is created on every restart | BOT_TOKEN or LOG_CHAT_ID are missing |
| After a restart the data doesn't come back | Check that LOG_CHAT_ID is set, that AUTO_RESTORE isn't false and that there are backups with #kitdev_backup in the logs group. If they were restored, the logs say so |