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

Start freefrom $11 a month per stream · 3 hours with every model, no card

Step by step

  1. Create the bot

    Message @BotFather in Telegram, create a bot and save the token.

  2. Get an API key

    Create a key in the Tenzo Cloud dashboard. For a server, restrict it by IP.

  3. Install the libraries

    You need openai and python-telegram-bot.

    terminal
    pip install openai python-telegram-bot
  4. Write the bot

    The code below answers every text message with the model.

    bot.py
    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()
  5. Run it

    Set the tokens in environment variables and run the script.

    terminal
    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

    Operational
    1 stream4+ 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 soon
    1 stream4+ 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.

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.