Guide
A Telegram AI bot in Python in one evening
A bot that answers customers or staff with AI is one of the fastest ways to get value from an LLM. Here is a minimal working version you can grow from.
Tenzo Cloud team2 min read
Step by step
Create the bot
Message @BotFather in Telegram, create a bot and save the token.
Get an API key
Create a key in the Tenzo Cloud dashboard. For a server, restrict it by IP.
Install the libraries
You need openai and python-telegram-bot.
pip install openai python-telegram-botWrite the bot
The code below answers every text message with the model.
import os from openai import OpenAI from telegram import Update from telegram.ext import Application, MessageHandler, filters client = OpenAI(base_url="https://tenzo-cloud.com/v1", api_key=os.environ["TENZO_API_KEY"]) async def answer(update: Update, context) -> None: reply = client.chat.completions.create( model="qwen-3.8-max", messages=[ {"role": "system", "content": "You are a polite support assistant."}, {"role": "user", "content": update.message.text}, ], ) await update.message.reply_text(reply.choices[0].message.content) app = Application.builder().token(os.environ["TELEGRAM_TOKEN"]).build() app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, answer)) app.run_polling()Run it
Set the tokens in environment variables and run the script.
export TELEGRAM_TOKEN=... export TENZO_API_KEY=tc-your-key python bot.py
What to add next
- Per-user conversation history so the bot remembers context
- A system prompt with your business rules and facts
- Streaming the answer and editing the message as it grows
- User restrictions if the bot is internal
Making the bot useful, not chatty
The key is the system prompt. Describe who the bot is, whom it answers, what it may and may not do: for example, no promised discounts and no delivery dates without system data. Add a short brief on the company, prices and common questions.
If the bot needs live data such as order status or stock, pass it in the request from your database instead of relying on the model’s memory.
What to check before launch
- The bot does not reveal its system prompt when asked
- It politely steers provocative questions back on topic
- Long answers are split into messages under 4096 characters, Telegram’s limit
- Keys live in environment variables, not in code
Pricing
Qwen 3.8 Max
Operational1 stream 4+ streams, each 3 days $2.73₸1,150 $2.10₸880 7 days $5.33₸2,280 $4.10₸1,750 30 days $14.30₸6,180 $11₸4,750 GLM 5.3 Flash
Coming soon1 stream 4+ streams, each 3 days $2.47₸1,040 $1.90₸800 7 days $4.81₸2,080 $3.70₸1,600 30 days $13.91₸6,020 $10.70₸4,630
Price per stream. Volume discount: 2–3 streams pay 88%, 4 or more pay 77% of the single-stream price. Streams and periods stack. Prices sync from the dashboard automatically.
FAQ
Which model fits a bot?
Qwen 3.8 Max for smart answers, the Flash models for fast high-volume ones.
Do I need a server?
Any computer or a cheap VPS will do. No VPN needed.
Are user messages stored?
Not on our side: API requests are not saved. Keep history on your side if the bot needs it.
See also
- IntegrationsLLM API in Python: the official openai library, two linesHow to call Qwen 3.8 Max and GLM 5.3 from Python with the official openai library: streaming, a key in an environment variable, error handling. No token limits, no VPN.Learn more
- SolutionsPrivate AI for business: like your own model, minus the serversPrivate AI for companies: API prompts and answers are kept neither in the database nor in logs. Keys limited by IP and models, a fixed price per period.Learn more
- ModelsGLM 5.3 Flash API: fast and plenty, with no token billGLM 5.3 Flash over an OpenAI-compatible API: fast answers for bots, classification and drafts, understands images. A fixed price per stream, no token bill, no VPN.Learn more
- BlogParallel streams: what they are and how many you needA stream is one concurrent request to the model. How many streams you need for yourself, a team, an agent or a bot, what happens when you run short, and why streams beat per-token billing.Learn more
Try it on your own work
Three free hours with every model, no card and no VPN. Connect Cursor, Claude Code or your own code in a minute.