Bots
How to host an AI Telegram bot
In short
An AI Telegram bot is hosted like any other bot: you upload the code to Netrun, the platform builds the project and keeps the bot running. The model API key does not belong in the code: you enter it during setup, and the platform keeps it encrypted and passes it to the bot at start. The platform does not give you access to the model itself, so you get the key from the model provider and pay them for tokens. A bot never sleeps, because nothing would wake it up, so the free plan gives it three days and continuous work needs the Pro plan.
An AI bot looks like magic from the outside, but inside it is an ordinary Telegram bot: it takes a message, sends it to a model API, waits for the answer and forwards it back. The hard part is the same as for any bot: something has to keep it running around the clock. Normally that means renting a server, installing Python on it, setting up autostart, watching that the process does not die, and separately worrying that your paid model key does not leak along with the code.
With Netrun you upload a folder of code, the platform works out the language, installs the dependencies, starts the bot and restarts it after a crash. The key is asked for separately and stored encrypted. One thing is worth stating plainly: we do not provide access to the model. Netrun is not a proxy and not a VPN, it does not hand out model keys and does not open routes to providers. We make sure your bot runs; the key and the token bill stay between you and the model provider.
Take the model key out of your code#
This is the most important step and also the one people get wrong most often. A model API key is access to money: once it lands in a public repository or an archive, strangers find it within hours and spend your tokens. Read the key from an environment variable and enter the actual value during project setup in Netrun. The platform stores it encrypted and passes it to the bot at start, so it never sits in the code.
Set the API address the same way#
Most model client libraries let you set the base API address through an environment variable or a client parameter. If you talk to a compatible gateway or a different provider instead of the default service, that is a setting in your own code: read the address from the environment just like the key and enter it in secrets. Switching providers then takes a value change instead of a code change.
Raise the timeouts and send a typing status#
A model answer takes seconds, sometimes tens of seconds, and default timeouts often are not enough. The request is cut off, the bot says nothing, and the user assumes it is broken. Raise the timeout on the model request and on the HTTP client inside your Telegram library, and send the typing status as soon as a message arrives. It speeds up nothing, but the person can see the bot is alive and stops tapping send five times.
Store chat history in the persistent folder#
For the bot to remember earlier messages, the history has to live somewhere. A plain dictionary in process memory works right up to the first restart, after which the bot forgets everyone. Write the history to the project persistent folder /data, which survives a code update and a restart. The platform does not offer a ready-made database: if you have many conversations and need to search them, run your own database next to the app in a docker-compose file, or use an external one.
Upload the code and get a working bot#
Bring the project in as a ZIP archive or import a GitHub repository, private ones included. Netrun detects the language, installs the dependencies, asks for the BotFather token and the model key, starts the bot and keeps an eye on it after a crash. Logs stream in your dashboard in real time, so a problem like a wrong key shows up immediately instead of as silence.
Watch token spending and the free plan window#
Every user message is a paid request to the model, and you pay the provider for it directly, so tokens are not part of what the platform charges. Set a spending limit in the provider dashboard and cap how much history you send with each request. Also keep the run mode in mind: bots do not sleep, so the free plan gives a bot three days, a warning arrives a day before it stops, and continuous operation needs the Pro plan.
An AI bot is an ordinary bot with two twists: a paid third-party key that must never live in the code, and slow answers that both your timeouts and your users have to be prepared for. Everything else is on the platform: the build, the start, the restart after a crash and a persistent folder for chat history. Current plans and limits are shown in your dashboard. Try Netrun.
Common questions
Does Netrun give access to ChatGPT or another model?
No. Netrun runs your code, but it is not a proxy or a VPN and it does not hand out model keys. You get the key yourself from the model provider and pass it to the platform as a secret so your bot can use it.
What happens if my model key ends up in a repository?
It will almost certainly be found: public repositories are scanned constantly and leaked keys start getting spent the same day. If it already happened, revoke the key at the provider and issue a new one, then put the new value into project secrets rather than into the code.
Why does the bot stay silent for so long after a question?
It is most likely waiting for the model. Generation takes seconds, and longer with a long context. Send a typing status as soon as the message arrives and raise your request timeouts, otherwise the request is cut off before the answer arrives and the user gets nothing at all.
How do I make the bot remember previous messages?
Keep the conversation history in the persistent /data folder instead of process memory: in memory it lasts until the first restart, and restarts happen on code updates and after crashes. If there are many conversations, use a database instead, either your own running next to the app in a docker-compose file or an external one. It also helps to cap how many recent messages you send to the model, since a long history costs more on every request.
How much does the model itself cost to run in a bot?
That is a separate bill: you pay the model provider for tokens at their rates, and it is not included in what the platform charges. The real amount depends on how many users you have, how long the messages are and how much history you send with each request, so it is worth setting a spending cap up front.
Can I use a provider other than OpenAI?
Yes, as long as your library can talk to it. Many clients let you set the base API address through an environment variable, so you just point it at the right address and add the key to project secrets. From the platform side it is an ordinary bot calling an external service.
Can I host a Telegram bot?
Yes. Upload the bot code and provide the token from BotFather (Telegram itself gives it to you when you create the bot) — Netrun starts the bot, and no VPS or manual setup is needed. On the free plan the bot runs for 3 days so you can check everything; to keep it running around the clock, switch to the Pro plan.
Where do I set tokens and other secret values?
Every project has a Secrets tab where you set the values from your code — for example the token from BotFather. We store them encrypted: you can see the variable names, but the values are shown to no one, including you.
What happens to my bot after 3 days on the free plan?
The bot switches off, but your code, settings and secrets stay where they are — we delete nothing. A day before it switches off we send you a warning. Switch to the Pro plan, and the bot starts again from the same place and runs around the clock. A new bot uploaded after that is built too, but it will not start: free time is counted per account, not per project.
Is my data kept when I update the code?
Yes, as long as your data lives in persistent storage. For a regular project that is the /data folder: anything your app saves there stays in place when you update the code or restart, and you can browse and download the files on the "Data" tab. If you described the services yourself in docker-compose, persistent storage means the named volumes from your file, and such a project has no /data folder. Files written outside persistent storage are created from scratch on the next deploy. Your project link stays the same either way.