
Build a Telegram AI Bot in Python for Under ₹1/Day
A complete Telegram bot with an LLM backend, using python-telegram-bot and a budget model — with the real per-day cost for a small community bot.
Author
AICredits Team
Published
4 Sept 2026
Reading time
6 min read
Telegram bots are the cheapest way to ship an AI project
Telegram's Bot API is free, requires no business verification, and the python-telegram-bot library handles the webhook/polling plumbing for you. Pair it with a budget LLM through AICredits and a hobby-scale bot — a study-group Q&A bot, a personal reminder assistant, a community FAQ bot — costs close to nothing to run.
Setup
pip install python-telegram-bot openaiGet a bot token from @BotFather on Telegram, then:
import logging
from telegram import Update
from telegram.ext import ApplicationBuilder, MessageHandler, ContextTypes, filters
from openai import OpenAI
client = OpenAI(base_url="https://api.aicredits.in/v1", api_key="sk-your-aicredits-key")
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_text = update.message.text
response = client.chat.completions.create(
model="google/gemini-2.0-flash",
messages=[
{"role": "system", "content": "You are a helpful, concise assistant in a Telegram group. Keep replies under 3 sentences."},
{"role": "user", "content": user_text},
],
)
await update.message.reply_text(response.choices[0].message.content)
app = ApplicationBuilder().token("YOUR_TELEGRAM_BOT_TOKEN").build()
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
app.run_polling()This runs as a long-running process — deploy it on any small VM, or a free-tier cloud service that supports persistent processes (Telegram's polling model needs the process to stay alive; webhooks are the alternative if you're on a serverless platform).
Adding memory across messages
Telegram bots are stateless by default — each message arrives with no context of prior turns. A simple in-memory conversation history per chat:
conversations: dict[int, list[dict]] = {}
async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
chat_id = update.message.chat_id
user_text = update.message.text
history = conversations.setdefault(chat_id, [
{"role": "system", "content": "You are a helpful, concise assistant."}
])
history.append({"role": "user", "content": user_text})
response = client.chat.completions.create(model="google/gemini-2.0-flash", messages=history)
reply = response.choices[0].message.content
history.append({"role": "assistant", "content": reply})
conversations[chat_id] = history[-10:] # cap history to last 10 messages to bound cost
await update.message.reply_text(reply)Capping history length matters here specifically — without it, a long-running conversation keeps growing the input token count on every single message, quietly increasing cost per reply over time.
What it actually costs
Assume a small community bot: 200 messages/day, each exchange averaging 400 input tokens (with capped history) and 80 output tokens.
| Model | Daily cost | Monthly cost | |-------|------------|----------------| | Gemini 2.0 Flash | ~₹0.19 | ~₹5.70 | | DeepSeek V3 | ~₹0.20 | ~₹6.00 | | GPT-4o-mini | ~₹0.24 | ~₹7.20 | | Claude 3.5 Haiku | ~₹1.60 | ~₹48 |
For a genuinely hobby-scale bot, this comfortably fits under ₹1/day on any of the budget models — a ₹50 topup lasts months.
Frequently Asked Questions
Should I use polling or webhooks for a Telegram bot?
Polling (run_polling()) is simpler and fine for personal or small-community bots. Webhooks scale better for high-traffic bots but need a public HTTPS endpoint — most hobby deployments don't need this complexity.
How do I keep the bot from responding to every message in a group chat?
Filter on mentions (@your_bot_name) or replies to the bot's own messages, rather than responding to every message in a shared group — check update.message.entities for mention detection.
Can I add voice message support?
Yes — download the voice note via Telegram's file API, then transcribe it with openai/whisper-1 or sarvam/saarika-v2 for Indian languages before passing the text to the chat model.
Get started
- Create a free account and get a key for your bot.
- Related: How to Build a Retry Strategy for LLM API Calls — useful once your bot has real traffic and occasional provider hiccups to handle gracefully.
Related Articles
Continue in Docs
Need implementation commands and endpoint details? Go to quickstart or API reference.