DEV Community

modelkiwi
modelkiwi

Posted on

17 lines of Python and your AI bot is live

Brazilian devs spent 205% more time studying AI in 2025. If you haven't built your first bot yet, here's the shortcut: under 30 lines, zero frameworks, works with GPT, Claude and Gemini.

Let's build a question-answering bot on an LLM API — zero heavy frameworks. The same code works with OpenAI, Claude or Gemini; just change base_url and the key.

Step 1 — Install

pip install openai
Enter fullscreen mode Exit fullscreen mode

Step 2 — The bot

from openai import OpenAI

client = OpenAI(base_url="https://api.example.com/v1", api_key="your-key")

print("AI bot (type 'exit' to quit)")
while True:
    question = input("You: ")
    if question.lower() == "exit":
        break
    resp = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": question},
        ],
    )
    print("Bot:", resp.choices[0].message.content)
Enter fullscreen mode Exit fullscreen mode

Step 3 — Run it

python bot.py
Enter fullscreen mode Exit fullscreen mode

Next upgrades: conversation history, max_tokens cost control, stream=True for real-time answers, and exposing it as an API with FastAPI.


Want to try these models in your project? **ModelKiwi* gives you access to GPT, Claude and Gemini with PIX payment (no international credit card needed) and free credits to start: https://www.modelkiwi.com. WhatsApp: +5521999500402 — and join our channel: https://t.me/ModelkiwiOfficial.*

Top comments (0)