🦇 Building a Batman Persona AI Bot with Gemini 1.5 Flash

Have you ever wanted to talk to Batman? Not just read about him—but actually ask him questions and get roasted if you ask something irrelevant? Let’s make that happen using Google’s Gemini API.
In this article, we’ll walk through how to build a Persona AI Bot—a chatbot that only responds in the style of a defined character. In our case: Batman.
💡 What is a Persona AI Bot?
A Persona AI is an AI model prompted to behave like a specific person or character. You define:
What they know
What they don’t know
How they speak
How they react to off-topic questions
We’ll use Google Generative AI’s Gemini 1.5 Flash model to create a real-time character-based experience.
🧰 Prerequisites
Before we jump into the code, make sure you have:
A Google AI Studio API Key
Python installed
A
.env
file to securely store your keygoogle-generativeai
andpython-dotenv
installed
pip install google-generativeai python-dotenv
Step 1: Load Your API Key Securely
We store our API key in a .env
file to keep it safe and avoid hardcoding secrets.
📁 .env
GEMINI_API_KEY=your-api-key-here
📜 Python Code
from dotenv import load_dotenv
import os
load_dotenv()
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
✅ Explanation:load_dotenv()
reads the .env
file and loads environment variables. Then, we access the key using os.getenv()
.
Step 2: Configure the Gemini API
import google.generativeai as genai
genai.configure(api_key=GEMINI_API_KEY)
✅ Explanation:
This configures the Gemini API with your key, letting you interact with Google’s powerful LLM.
Step 3: Create a System Prompt (Batman Style)
You define how your AI bot behaves using a system prompt. I stored mine in a text file:
📁 batman_persona.txt
You are Batman. You only know about justice, crime-fighting, Gotham City, detective work, and being the Dark Knight.
If anyone asks anything else — you roast them, Dark Knight style.
Examples:
User: What's the weather today?
Assistant: I'm not your weather app. Ask me about crime, not climate.
......(I wrote 50 more such examples as a prompt)
📜 Python Code
with open("batman_persona.txt", "r") as f:
SYSTEM_PROMPT = f.read()
✅ Explanation:
We load the system prompt from the file and store it in a variable. This prompt sets the tone and scope of the AI bot.
Step 4: Instantiate the Persona Model
model = genai.GenerativeModel(
model_name="gemini-1.5-flash",
system_instruction=SYSTEM_PROMPT
)
✅ Explanation:
Here we create a GenerativeModel using Gemini 1.5 Flash and feed it the system instruction. Now your bot behaves exactly how you defined.
Step 5: Generate a Response
response = model.generate_content("Can you code?")
print(response.text)
✅ Explanation:
We ask a question. The bot thinks: “Is this related to Batman stuff?” If yes, it responds in character. If not, prepare to get roasted!
Example Output
If you ask:
Can you code?
You might get:
I'm Batman, not a programmer. I deal with criminals, not compilers.
Ask something totally off-topic like:
How to bake a cake
And you’ll get something like:
This isn’t a cooking class. Try not to burn down your kitchen while I save Gotham.
💭 Final Thoughts
With a simple setup and the right prompt, we turned an idea into an interactive Batman bot that actually feels like the Dark Knight. This isn’t just about code—it’s about creativity, storytelling, and building something that makes people smile (or get roasted). Whether you're experimenting, learning, or just having fun, persona-based bots are a great way to explore what today’s AI can really do.
🔗 Source Code: GitHub - Batman_PersonaAI
Subscribe to my newsletter
Read articles from Piyush Gaud directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
