Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Multi-Model AI Bot (Python)

A small, dependency-free Telegram bot that sends chat requests to an OpenAI-compatible API. It supports configurable models, bounded conversation history, long polling, retries, and Telegram-safe message splitting.

APIMART · multi-model AI API gateway

A runnable Telegram bot using one OpenAI-compatible API endpoint. Run a Telegram AI bot with one multi-model API key

Transparent disclosure: this repository is maintained by APIMART.

中文说明:README.zh-CN.md

Features

  • Pure Python standard library; no framework dependency
  • OpenAI-compatible /chat/completions
  • /model shows the active model
  • /reset clears the current chat history
  • Per-chat history with a configurable message limit
  • Retry with exponential backoff for transient API errors
  • Splits replies to stay within Telegram's message limit

Run

Requirements: Python 3.10+

cp .env.example .env
# Set TELEGRAM_BOT_TOKEN and APIMART_API_KEY in your shell.
python bot.py

PowerShell example:

$env:TELEGRAM_BOT_TOKEN = "123456:telegram-token"
$env:APIMART_API_KEY = "your-api-key"
$env:AI_MODEL = "gpt-4o-mini"
python .\bot.py

The default API endpoint is https://api.apimart.ai/v1. Set AI_API_BASE_URL to use another OpenAI-compatible gateway.

Commands

  • /start — usage help
  • /model — show the configured model
  • /reset — clear this chat's history
  • Any other text — send it to the model

Test

python -m unittest discover -s tests -v

The tests do not call Telegram or an AI API.

Production checklist

  • Store tokens in a secret manager; never commit them.
  • Use a dedicated Telegram bot token.
  • Add allow-lists or authentication if the bot is private.
  • Add persistent storage if conversations must survive restarts.
  • Review rate limits and model pricing before opening the bot publicly.

License

MIT

About

Dependency-free Telegram bot for OpenAI-compatible multi-model AI APIs.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages