base_url, and the same openai SDK works with Claude, GPT, Gemini, and DeepSeek.
Prerequisites
- A RuAPI key —
sk-.... Create it in the Console: Tokens → Create token. Top up your balance in USDT — see top up. - Python 3.10+ — check with
python --version. - A Telegram bot token — we’ll get this in the next step.
Create the bot in Telegram
Open a chat with @BotFather in Telegram and send
/newbot. BotFather will ask for the bot’s name and a username (it must end in bot). In return it sends an HTTP API token — a string like 123456789:AAH.... Copy it; you’ll need it shortly.Install the dependencies
python-telegram-bot version 21+ is an async framework for Telegram. openai is the client we’ll point at RuAPI.Write the bot
Create a file called
bot.py. This is a fully working minimal bot: on every text message it sends your text to the model and replies with the model’s answer.bot.py
The example uses the model
claude-opus-4-8. The same key also reaches other
models: gpt-5, gemini-3.5-flash, deepseek-v3, and more. Exact names are
on the Pricing page of the main site.Run it
Pass both tokens via environment variables and run the script:The bot starts quietly and begins listening for messages (
run_polling polls Telegram). Find your bot in Telegram by its username, send it anything, and it will answer through the LLM. Press Ctrl+C to stop.Make it better
The minimal bot has no memory and answers every message from a blank slate. A few directions to grow:
- Conversation history. Store the message history per
chat_id(for example, incontext.chat_data) and pass the whole list tomessages=[...]— then the bot remembers earlier turns. - A system prompt. Add
{"role": "system", "content": "You are a friendly assistant..."}as the first element to set tone and role. - A /start command. Add a
CommandHandler("start", ...)with a greeting — it makes the bot feel friendlier. - Switch models. Change the
modelfield to switch to GPT or Gemini. - Cheaper at scale. If you handle a lot of traffic, move the bot to a more affordable model —
gemini-3.5-flashordeepseek-v3. They’re great for chat and spend your balance much more slowly.
Troubleshooting
The bot is silent and doesn't answer
The bot is silent and doesn't answer
Check that the bot token was copied whole, with no stray spaces, and that the
script is actually running (
run_polling must be active, the terminal window
still open). Make sure you’re messaging the exact bot you created with
BotFather. Errors print to the terminal — look there.401 (Unauthorized) error
401 (Unauthorized) error
402 (Payment Required) error
402 (Payment Required) error
Your balance ran out. Top it up in USDT — see top up.
What’s next
- Quickstart — the basics of the API and
base_url. - Streaming responses — make the bot type its answer out instead of pausing on long replies.
- Errors — what the response codes mean.
- Questions? [email protected]