6 min read · updated 2026-11-01 · reviewed

A Telegram AI bot in 5 minutes: Model.sale for the model, Deployka for hosting

A Telegram bot that answers with a real AI model needs three things: a bot token, an API key for the model and a place where the code runs all the time. This guide does all three in about five minutes. Disclosure: Deployka, the hosting used here, is a sister service of Model.sale; any host that runs Python works the same way.

Editorial note

Written by Model.sale Engineering and reviewed against first-party documentation on 2026-11-01. Comparisons use the billing rules visible on the linked sources and do not claim universal model equivalence.

1. Get a bot token and an API key

In Telegram, open @BotFather, send /newbot, pick a name and a username, and copy the token it returns. Then create a Model.sale account, open API keys and create a key; new accounts that sign in with Google or Telegram get $0.50 of test credit, enough for hundreds of short replies on a cheap model.

2. The bot: about 20 lines of Python

The bot uses aiogram for Telegram and the official OpenAI SDK pointed at Model.sale, so switching the model is a one-word change: gpt-6.1-terra is the cheapest strong option ($0.15 per 1M charged tokens), claude-sonnet-5-5 and claude-opus-5-5 answer better on hard questions.

# bot.py — a Telegram bot that answers with an AI model via Model.sale
import asyncio, os

from aiogram import Bot, Dispatcher
from aiogram.types import Message
from openai import AsyncOpenAI

bot = Bot(os.environ["BOT_TOKEN"])
dp = Dispatcher()
ai = AsyncOpenAI(base_url="https://api.model.sale/v1", api_key=os.environ["MODEL_SALE_API_KEY"])


@dp.message()
async def answer(message: Message) -> None:
    reply = await ai.chat.completions.create(
        model=os.environ.get("MODEL", "gpt-6.1-terra"),
        messages=[{"role": "user", "content": message.text or ""}],
    )
    await message.answer(reply.choices[0].message.content or "…")


asyncio.run(dp.start_polling(bot))

3. Dependencies and settings

Put the dependencies next to bot.py. Keep the token and the key in environment variables, never in the code or the repository.

# requirements.txt
aiogram>=3
openai>=1

# environment variables
BOT_TOKEN=123456:ABC...          # from @BotFather
MODEL_SALE_API_KEY=ms_live_...   # from model.sale/dashboard/keys
MODEL=gpt-6.1-terra              # optional: claude-sonnet-5-5, claude-opus-5-5, gpt-6.1-sol

4. Host it free on Deployka

On Deployka, upload the folder as a ZIP or connect the GitHub repository. It detects Python, installs the requirements and starts bot.py; add BOT_TOKEN and MODEL_SALE_API_KEY in the project's environment variables. The Free Nano plan costs nothing and needs no card; it runs a small bot like this one for up to 30 days and reclaims the slot after 7 idle days. A paid Nano slot ($1.09 per 30 days) keeps it running without that limit.

Deploy Doctor checks the environment variables and the start command before the build, so a missing key shows up before the first crash. Logs and a restart button are in the dashboard. Deployka also has ready Telegram Bot and AI Chatbot templates if you prefer to start from one.

5. What it costs to run

A short exchange is roughly 300 input and 300 output tokens. On gpt-6.1-terra that is about $0.0001 per reply, so $5 covers tens of thousands of replies; on claude-opus-5-5 ($1.40 per 1M charged tokens) about $0.001 per reply. Put a daily spend limit on the key in the dashboard, and connect @modelsale_bot to get a message when the balance runs low or spending jumps.

6. Next steps

Keep the conversation history per chat to give the model context, add a system prompt for your bot's role, and use streaming for long answers. The model pages on Model.sale have ready code in Python, Node.js and cURL for every model.

Sources and further reading

Checked on 2026-11-01. These links support the factual comparisons in this article; pricing and terms may change.

Use the numbers on your own workload

Open the cost calculator, choose a live model and enter a representative input/output mix before deciding.

Open cost calculator
← All guides