Build an AI Study Buddy with Gemini
Call the Gemini API from Python to build a terminal AI tutor with chat memory.
Introduction
30 Second Summary
Ever wished you had a personal tutor available at any hour, ready to explain anything you're studying? That's exactly what you'll build today, using AI.
In this project, you will build a terminal-based AI Study Buddy powered by Google's Gemini API. You'll type questions, get intelligent tutoring responses, and have real-time conversations with an AI that remembers what you've discussed.
What You'll Build
A Python script that connects to the Gemini API, sends structured prompts to a large language model, and handles multi-turn conversations with streaming responses in your terminal.
By the end of this project, you'll have:
- A working AI Study Buddy running in your terminal that can explain concepts, answer questions, and tutor you on any subject.
- Hands-on experience calling an LLM API programmatically with Python, including system instructions, multi-turn chat, and streaming.
- A reusable project template you can extend for future AI Engineering projects.
- Secret Mission: Add a quiz mode that generates and evaluates practice questions on your chosen subject.
Are there any prerequisites?
None. This guide walks you through installing Python, setting up your project, and getting your API key from scratch. All you need is a Google account and VS Code.
Set Up Your Development Environment
Before you can build your AI Study Buddy, you need the right tools installed on your machine.
In this step, you'll install Python 3.13, create an isolated project environment, and grab an API key from Google AI Studio so your code can talk to the Gemini model.
In this step, get ready to:
- Install Python 3.13 and verify it works.
- Create a project folder with a virtual environment and install the SDK.
- Get a Gemini API key and configure it as an environment variable.
Install Python 3.13
The google-genai SDK requires Python 3.10 or higher. This project uses Python 3.13 for the latest features and performance improvements.
- Press Cmd+Space (macOS) or the Windows key (Windows) to open your search bar.
- Type Terminal and press Enter to open it.
- Check your current Python version by running this command:
python3 --version
✔️ I see version 3.13 or higher
You already have Python 3.13 installed. You can move on to the next substep.
ⓧ I see an older version
macOS ships with an older Python that does not meet the SDK requirements. You need to install Python 3.13 alongside it.
- Open https://www.python.org/downloads/release/python-31314/ in your browser.
- Scroll down to the files table and click Download macOS installer (for macOS) or Download Windows installer (64-bit) (for Windows).
- Run the downloaded installer and follow the prompts, accepting all defaults.
Why install alongside instead of replacing?
The installer adds Python 3.13 as a separate binary (python3.13) without overwriting your system Python. Your existing python3 command may still point to the older version, so throughout this project you will use python3.13 explicitly.
- After the installer finishes, verify the new version by running:
python3.13 --version
You should see Python 3.13.14 (or a similar 3.13.x number) printed in the terminal.
ⓧ Command not found
Python 3 is not installed on your system. You need to install Python 3.13 from the official website.
- Open https://www.python.org/downloads/release/python-31314/ in your browser.
- Scroll down to the files table and click Download macOS installer (for macOS) or Download Windows installer (64-bit) (for Windows).
- Run the downloaded installer and follow the prompts, accepting all defaults.
- After the installer finishes, close and reopen your Terminal.
- Verify the installation by running:
python3.13 --version
You should see Python 3.13.14 (or a similar 3.13.x number) printed in the terminal.
Still not seeing a version number?
Make sure you closed and reopened your Terminal after installing. The installer adds Python to your system PATH, but existing terminal sessions will not pick up the change.
help me troubleshoot Python 3.13 installation on my machine
Create your project folder and virtual environment
A virtual environment is an isolated copy of Python and its packages that belongs only to this project. It keeps your Study Buddy's dependencies separate from everything else on your machine.
- Move to your Desktop by running this command:
cd ~/Desktop
- Create your project folder and move into it by running these commands:
mkdir study-buddy
cd study-buddy
- Create a virtual environment using Python 3.13 by running:
python3.13 -m venv .venv
What does this command do?
python3.13 -m venv .venv tells Python 3.13 to create a virtual environment in a hidden folder called .venv inside your project directory. Everything you install with pip from now on goes into this folder instead of your global Python.
- Activate the virtual environment by running:
macOS
source .venv/bin/activate
Windows
.venv\Scripts\activate
You should see (.venv) appear at the beginning of your terminal prompt. This confirms the virtual environment is active.
- Install the Google GenAI SDK by running:
pip install google-genai
What is google-genai?
The google-genai package is Google's official Python SDK for the Gemini API. It handles authentication, request formatting, and response parsing so you can focus on building your app instead of managing HTTP calls.
Wait for the installation to finish. You should see a success message ending with something like "Successfully installed google-genai" and its dependencies.
Seeing a permissions error?
Make sure you activated the virtual environment first. The (.venv) prefix must be visible in your prompt before running pip install. If it is missing, re-run the activation command from the platform tabs above.
help me fix a pip install error inside my virtual environment
Get your Gemini API key
Your Python code needs an API key to authenticate with the Gemini service. Google AI Studio provides free API keys that work with the Gemini free tier.
- Open https://aistudio.google.com/apikey in your browser.
- Sign in with your Google account.
- Click Create API key.
- If prompted to select a project, accept the default project that Google AI Studio creates for you.
- Copy the API key that appears. You will only see it once, so keep this tab open until you paste it in the next step.
Is this free?
Yes. The Gemini 2.5 Flash model is free of charge on the Free Tier. No billing account is required.
- Back in your terminal (with (.venv) still active), set the API key as an environment variable by running:
macOS
export GEMINI_API_KEY="your-api-key-here"
Windows
$env:GEMINI_API_KEY="your-api-key-here"
- Replace your-api-key-here with the key you copied from Google AI Studio.
Why an environment variable?
The google-genai SDK automatically reads the GEMINI_API_KEY environment variable when you create a client. This keeps your secret out of your source code, which is a critical security practice.
- Verify that everything is connected by running this test command:
python -c "from google import genai; print('SDK ready')"
You should see SDK ready printed in the terminal.
Seeing ModuleNotFoundError?
This means pip install google-genai did not install into the environment your python command is using. Check that (.venv) appears in your prompt. If it does not, re-activate the virtual environment and run the install again.
help me fix ModuleNotFoundError for google-genai
Your development environment is ready. Next up, you'll write your first API call to Gemini and see a response appear in your terminal.
Make Your First API Call
Your environment is ready and your API key is connected. Now it's time to write Python code that actually talks to Google's Gemini model.
In this step, you'll create a script that sends a prompt to the Gemini API and prints the response. You'll start with a simple one-shot call, then upgrade to streaming for real-time output, and finally shape the AI's personality with a system instruction.
In this step, get ready to:
- Create study_buddy.py and make your first Gemini API call.
- Switch to streaming so responses appear word-by-word.
- Add a system instruction to shape the AI's personality.
Create your script and make a test call
The Gemini API works like a request-response cycle. You send a prompt, and the model sends back generated text. The genai.Client() handles authentication automatically using your GEMINI_API_KEY environment variable.
- In VS Code, create a new file called study_buddy.py in your project folder.
- Add the following code to make your first API call:
from google import genai
# Create a client that connects to the Gemini API
client = genai.Client()
# Send a test prompt to Gemini
response = client.models.generate_content(
model="gemini-2.5-flash",
contents="Hello! What can you help me with?",
)
print(response.text)
What does this code do?
- genai.Client() creates a connection to the Gemini API. It automatically reads your GEMINI_API_KEY environment variable for authentication.
- generate_content() sends your prompt to the gemini-2.5-flash model and waits for the full response before returning.
- response.text contains the generated text that Gemini produced.
- Save study_buddy.py.
- Run the script in your terminal by running this command:
python study_buddy.py
You should see a text response from Gemini printed in your terminal. The exact wording varies each time, but it will be a friendly greeting offering to help.
Not seeing a response?
- Make sure your virtual environment is still activated. You should see (.venv) at the start of your terminal prompt.
- Confirm your GEMINI_API_KEY is set by running echo $GEMINI_API_KEY in the terminal. If it prints nothing, re-export the key.
- If you see a permission error, double-check that you copied the full API key from Google AI Studio without any extra spaces.
Help me debug my Gemini API call that isn't returning a response
Switch to streaming responses
Right now, the script waits for the entire response to finish generating before printing anything. Streaming sends the response piece by piece as it's generated, making your app feel faster and more responsive.
- Replace the contents of study_buddy.py with this updated streaming version:
from google import genai
# Create a client that connects to the Gemini API
client = genai.Client()
# Send a test prompt with streaming
response_stream = client.models.generate_content_stream(
model="gemini-2.5-flash",
contents="Hello! What can you help me with?",
)
# Print each chunk as it arrives
for chunk in response_stream:
if chunk.text:
print(chunk.text, end="", flush=True)
print()
What changed?
- generate_content_stream() returns chunks as they're generated instead of waiting for the full response.
- The for chunk in response_stream: loop processes each piece of text as it arrives from the API.
- end="" keeps text flowing on one line, and flush=True forces Python to print immediately without buffering.
- Save study_buddy.py and run it again:
python study_buddy.py
This time you should see the response appearing word-by-word in your terminal instead of all at once.
Response still appearing all at once?
- Make sure you saved the file after editing. Check for generate_content_stream (not generate_content) in your code.
- Confirm the for chunk in response_stream: loop is present and printing with end="".
- Short responses may stream too fast to notice. Try changing the prompt to something longer like "Explain quantum physics in detail" to see the streaming effect more clearly.
Help me figure out why my streaming response isn't appearing incrementally
Add a system instruction
A system instruction tells the AI how to behave. It's like giving a character brief to an actor before a scene. The AI follows these instructions for the entire conversation.
- Replace the contents of study_buddy.py with this version that adds a system instruction:
import sys
from google import genai
from google.genai import types
SYSTEM_INSTRUCTION = """You are an enthusiastic and patient study buddy.
Your role is to help the user learn about their chosen subject.
- Explain concepts clearly using simple language and analogies
- Break down complex topics into digestible parts
- Encourage the user and celebrate their progress
- If the user seems confused, try explaining from a different angle
- Keep responses concise (2-3 paragraphs max) unless asked for detail
You are currently helping the user study: {subject}"""
client = genai.Client()
config = types.GenerateContentConfig(
system_instruction=SYSTEM_INSTRUCTION.format(subject="general topics"),
)
response_stream = client.models.generate_content_stream(
model="gemini-2.5-flash",
contents="Hello! What can you help me with?",
config=config,
)
for chunk in response_stream:
if chunk.text:
print(chunk.text, end="", flush=True)
print()
What does the system instruction do?
- SYSTEM_INSTRUCTION defines the AI's persona as a patient, encouraging tutor with specific behavioral rules.
- types.GenerateContentConfig(system_instruction=...) wraps the persona into a configuration object the API understands.
- config=config attaches the system instruction to the streaming call, so Gemini follows the persona when generating.
- {subject} is a Python format placeholder. You call .format(subject="general topics") to insert the subject into the instruction text.
- Save study_buddy.py and run it again:
python study_buddy.py
The response should now sound like an enthusiastic study tutor offering to help you learn. Compare this to the generic response you got earlier.
Response doesn't match the tutor persona?
- Check that you imported types with from google.genai import types at the top of the file.
- Make sure config=config is passed to generate_content_stream(). Without it, the system instruction is ignored.
- Verify your SYSTEM_INSTRUCTION string uses triple quotes """ and is not accidentally cut off.
Help me debug why my system instruction isn't changing the AI's behavior
✔️ Awesome, I've got everything!
Great. Double check you've saved study_buddy.py and your output matches the tutor persona.
ⓧ I'd like to double check the full code
Here is the complete study_buddy.py at this point:
import sys
from google import genai
from google.genai import types
SYSTEM_INSTRUCTION = """You are an enthusiastic and patient study buddy.
Your role is to help the user learn about their chosen subject.
- Explain concepts clearly using simple language and analogies
- Break down complex topics into digestible parts
- Encourage the user and celebrate their progress
- If the user seems confused, try explaining from a different angle
- Keep responses concise (2-3 paragraphs max) unless asked for detail
You are currently helping the user study: {subject}"""
client = genai.Client()
config = types.GenerateContentConfig(
system_instruction=SYSTEM_INSTRUCTION.format(subject="general topics"),
)
response_stream = client.models.generate_content_stream(
model="gemini-2.5-flash",
contents="Hello! What can you help me with?",
config=config,
)
for chunk in response_stream:
if chunk.text:
print(chunk.text, end="", flush=True)
print()
You've just made your first LLM API call, upgraded it to stream in real-time, and shaped the AI's personality with a system instruction. Next up, you'll turn this into a proper interactive chat that remembers what you discussed.
Build the Multi-Turn Chat Loop
Your study buddy currently speaks once and exits. A real tutor keeps the conversation going, remembering what you asked two questions ago.
In this step, you will replace the single-call pattern with a proper chat session. The SDK's chats helper automatically tracks conversation history so the AI remembers everything you discuss.
In this step, get ready to:
- Set up a chat helper function for multi-turn conversations.
- Build an interactive input loop with graceful exit.
- Test multi-turn memory with a chosen study subject.
Replace the single-call code with the chat helper
Right now your script fires one request and prints the response. The Gemini API offers a stateful chats helper that automatically manages conversation history behind the scenes. Every message you send and every reply you receive gets stored in the chat session, so follow-up questions have full context.
- In study_buddy.py, find all the code below the SYSTEM_INSTRUCTION string (starting from client = genai.Client() down to print()).
- Select and delete all of that code.
- Add the following create_chat function in place of the deleted code:
def create_chat(client, subject):
config = types.GenerateContentConfig(
system_instruction=SYSTEM_INSTRUCTION.format(subject=subject),
)
chat = client.chats.create(model="gemini-2.5-flash", config=config)
return chat
What does this code do?
- The function accepts a client and a subject string. It formats the system instruction with the chosen subject so the AI knows what topic to focus on.
- client.chats.create() starts a chat session that tracks every message automatically. You no longer need to manage history yourself.
- Passing config attaches the system instruction to the chat, so every response follows your tutor persona.
Build the main chat loop
With the chat helper ready, you need an interactive loop that collects user input, sends it to the chat, and prints the response. The loop also needs to exit cleanly when the user types "quit" or presses Ctrl+C.
- Below the create_chat function, add the following main function and entry point:
def main():
client = genai.Client()
print("=" * 50)
print(" Welcome to AI Study Buddy!")
print("=" * 50)
subject = input("\nWhat subject would you like to study? ")
print(f"\nGreat! I'm ready to help you learn about {subject}.")
print("Type your questions or 'quit' to exit.\n")
chat = create_chat(client, subject)
while True:
try:
user_input = input("You: ").strip()
except (KeyboardInterrupt, EOFError):
print("\n\nGoodbye! Happy studying!")
sys.exit(0)
if not user_input:
continue
if user_input.lower() == "quit":
print("\nGoodbye! Happy studying!")
break
response = chat.send_message(user_input)
print(f"\nStudy Buddy: {response.text}\n")
if __name__ == "__main__":
main()
What does this code do?
- The welcome banner and input() call ask the user to pick a study subject before the conversation begins. That subject is passed to create_chat so the system instruction tells the AI what topic to tutor on.
- The while True loop keeps the conversation going indefinitely. Each iteration collects a line of input, sends it to the chat, and prints the response with a "Study Buddy:" label.
- The try/except block catches KeyboardInterrupt (Ctrl+C) and EOFError (Ctrl+D) so the script prints a friendly goodbye instead of crashing with a traceback.
- Typing "quit" breaks out of the loop normally. Empty inputs are skipped with continue.
- if __name__ == "__main__" ensures main() only runs when you execute the file directly, not when importing it.
- Save study_buddy.py.
Seeing a syntax error when you save?
- Make sure you deleted all of the old module-level code. Leftover lines like response_stream = ... sitting outside a function will cause an indentation or name error.
- Check that def create_chat and def main are both at the top level (no extra indentation).
Ask for help: Why am I getting a syntax error in study_buddy.py after replacing the single-call code with functions?
Test a multi-turn conversation
Time to verify that the AI remembers your conversation across multiple messages.
- Run your script by entering this command in the terminal:
python study_buddy.py
- When prompted, type a subject like Python or machine learning.
- Ask a question, then ask a follow-up that references your first question. For example: "What is a variable?" followed by "Can you give me an example of one?"
- Verify that the AI's second answer references your first question without you needing to repeat it.
- Type quit to exit the loop cleanly.
What should I see?
The script prints a welcome banner, asks for your subject, then shows a "You:" prompt. Each response appears with a "Study Buddy:" label. Follow-up answers reference your earlier questions, proving the chat session retains context.
AI doesn't remember your earlier messages?
- Make sure you are using chat.send_message() and not client.models.generate_content(). The single-call method has no memory between calls.
- Check that you create the chat object once (before the loop) and reuse it for every message. Creating a new chat inside the loop resets the history each time.
Ask for help: Why doesn't my study buddy remember what I said earlier in the conversation?
✔️ Awesome, I've got everything!
Great. Double check you have saved study_buddy.py before moving on.
ⓧ I'd like to double check the full code
Here is the complete study_buddy.py at this point:
import sys
from google import genai
from google.genai import types
SYSTEM_INSTRUCTION = """You are an enthusiastic and patient study buddy.
Your role is to help the user learn about their chosen subject.
- Explain concepts clearly using simple language and analogies
- Break down complex topics into digestible parts
- Encourage the user and celebrate their progress
- If the user seems confused, try explaining from a different angle
- Keep responses concise (2-3 paragraphs max) unless asked for detail
You are currently helping the user study: {subject}"""
def create_chat(client, subject):
config = types.GenerateContentConfig(
system_instruction=SYSTEM_INSTRUCTION.format(subject=subject),
)
chat = client.chats.create(model="gemini-2.5-flash", config=config)
return chat
def main():
client = genai.Client()
print("=" * 50)
print(" Welcome to AI Study Buddy!")
print("=" * 50)
subject = input("\nWhat subject would you like to study? ")
print(f"\nGreat! I'm ready to help you learn about {subject}.")
print("Type your questions or 'quit' to exit.\n")
chat = create_chat(client, subject)
while True:
try:
user_input = input("You: ").strip()
except (KeyboardInterrupt, EOFError):
print("\n\nGoodbye! Happy studying!")
sys.exit(0)
if not user_input:
continue
if user_input.lower() == "quit":
print("\nGoodbye! Happy studying!")
break
response = chat.send_message(user_input)
print(f"\nStudy Buddy: {response.text}\n")
if __name__ == "__main__":
main()
Your study buddy now holds a real conversation. It remembers context, stays in character, and exits gracefully. Next up, you will add streaming so responses appear word-by-word instead of waiting for the full reply.
Add Streaming to the Chat
Your Study Buddy can hold a full conversation and remembers what you discussed. One thing still feels off though. When you ask a question, the entire response appears all at once after a pause.
Real AI assistants like ChatGPT stream their responses word-by-word. In this step, you will switch to streaming so text flows in real-time, and add error handling so network issues don't crash your app.
In this step, get ready to:
- Create a helper function that prints streamed chunks as they arrive.
- Switch the chat loop from a single response to a streaming response.
- Add error handling so API failures produce a friendly message instead of a crash.
Create a streaming response function
Streaming means the API sends response text in small pieces (called chunks) as they are generated, instead of waiting until the entire response is ready. You need a helper function that receives these chunks and prints each one immediately.
- In study_buddy.py, find the main() function.
- Add the following stream_response() function directly above the def main(): line:
def stream_response(response_stream):
full_text = ""
for chunk in response_stream:
if chunk.text:
print(chunk.text, end="", flush=True)
full_text += chunk.text
print()
return full_text
What does this code do?
- for chunk in response_stream iterates over each piece of text as the API sends it back.
- print(chunk.text, end="", flush=True) prints each chunk immediately without adding a newline, so text flows smoothly on one line.
- The function collects all chunks into full_text and returns it. This is useful if you want the complete response later.
- Save study_buddy.py.
- You won't see a change yet. The next substep connects this function to your chat loop.
Switch the chat loop to streaming
Now you will replace the old response handling with chat.send_message_stream(), which returns a stream of chunks instead of a single completed response. You will also wrap it in a try/except block so network errors or rate limits don't crash the program.
- Inside the while True loop in main(), find these two lines at the bottom:
response = chat.send_message(user_input)
print(f"\nStudy Buddy: {response.text}\n")
- Delete those two lines and replace them with this code:
try:
print("\nStudy Buddy: ", end="")
response_stream = chat.send_message_stream(user_input)
stream_response(response_stream)
print()
except Exception as e:
print(f"\nSorry, something went wrong: {e}")
print("Please try again.\n")
What changed here?
Two big upgrades in one block:
- Streaming: chat.send_message_stream() returns chunks one at a time. Your stream_response() function prints each chunk the instant it arrives, so the learner sees text flowing in real-time.
- Error handling: The try/except catches any exception (network timeouts, rate limits, auth errors) and prints a friendly message instead of crashing with a traceback.
- Save study_buddy.py.
- Run the script by running this command in your terminal:
python study_buddy.py
- Choose a subject and ask a question.
- You should see the response appear word-by-word instead of all at once after a long pause.
Response still appears all at once?
- Make sure you deleted the old response = chat.send_message(user_input) line. If both the old and new code exist, the old one runs first.
- Check that stream_response() is defined above main() in the file. Python must see a function definition before it is called.
- Confirm you are running the script inside your activated virtual environment (you should see (.venv) in your terminal prompt).
Help me debug why my streaming response is not working.
Test your error handling
The try/except block you added catches problems like network outages and API rate limits. Let's confirm it works.
- With your Study Buddy still running, disconnect from the internet (turn off Wi-Fi or unplug your ethernet cable).
- Type a question and press Enter.
- You should see a message like Sorry, something went wrong: followed by the error details, instead of a full Python traceback.
- Reconnect to the internet and type another question to confirm the chat still works.
Why does this matter?
Without the try/except, a single network blip would crash the entire program and lose your conversation history. With it, the user sees a helpful message and can retry immediately. This is a production-ready pattern you will reuse in every API-calling project.
✔️ Awesome, I've got everything!
Great. Double check you have saved study_buddy.py with both the streaming function and the error handling.
ⓧ I'd like to double check the full code
import sys
from google import genai
from google.genai import types
SYSTEM_INSTRUCTION = """You are an enthusiastic and patient study buddy.
Your role is to help the user learn about their chosen subject.
- Explain concepts clearly using simple language and analogies
- Break down complex topics into digestible parts
- Encourage the user and celebrate their progress
- If the user seems confused, try explaining from a different angle
- Keep responses concise (2-3 paragraphs max) unless asked for detail
You are currently helping the user study: {subject}"""
def create_chat(client, subject):
config = types.GenerateContentConfig(
system_instruction=SYSTEM_INSTRUCTION.format(subject=subject),
)
chat = client.chats.create(model="gemini-2.5-flash", config=config)
return chat
def stream_response(response_stream):
full_text = ""
for chunk in response_stream:
if chunk.text:
print(chunk.text, end="", flush=True)
full_text += chunk.text
print()
return full_text
def main():
client = genai.Client()
print("=" * 50)
print(" Welcome to AI Study Buddy!")
print("=" * 50)
subject = input("\nWhat subject would you like to study? ")
print(f"\nGreat! I'm ready to help you learn about {subject}.")
print("Type your questions or 'quit' to exit.\n")
chat = create_chat(client, subject)
while True:
try:
user_input = input("You: ").strip()
except (KeyboardInterrupt, EOFError):
print("\n\nGoodbye! Happy studying!")
sys.exit(0)
if not user_input:
continue
if user_input.lower() == "quit":
print("\nGoodbye! Happy studying!")
break
try:
print("\nStudy Buddy: ", end="")
response_stream = chat.send_message_stream(user_input)
stream_response(response_stream)
print()
except Exception as e:
print(f"\nSorry, something went wrong: {e}")
print("Please try again.\n")
if __name__ == "__main__":
main()
Your Study Buddy now feels like a real AI assistant with smooth, streaming responses and graceful error recovery. Next up, you will tackle the Secret Mission and give your Study Buddy a quiz mode.
Secret mission
Add Quiz Mode
Your study buddy can explain concepts and answer questions. But the best way to learn is active recall. Can you add a /quiz command that generates practice questions and evaluates your answers?
Clean Up Your Resources
Clean Up Your Resources
This project runs entirely locally and uses the Gemini free tier, so there are no ongoing costs. Decide whether to keep your resources for future use or delete them entirely.
Resources you used:
- Google AI Studio API key (free tier, no ongoing cost).
- Project folder on your Desktop (contains .venv virtual environment and study_buddy.py).
Keep everything running
No action needed. Choose this if you plan to keep building on this project or start a new AI Engineering project.
- Your API key is ready to use in future projects. The Gemini free tier has no charges while idle.
- Your project folder and virtual environment are ready for the next time you want to experiment.
- The GEMINI_API_KEY environment variable only lasts for your current terminal session. You will need to export it again next time you open a new terminal.
Pause - I'll come back to this later
Free up system resources while keeping your files intact. You can pick up where you left off anytime.
- If your virtual environment is still active, deactivate it by running:
deactivate
- Close your terminal window. Your project folder and API key remain untouched.
- When you come back, reactivate the virtual environment with source .venv/bin/activate (macOS/Linux) or .venv\Scripts\activate (Windows), then re-export your API key.
Delete - I don't want to use this again
Remove all project files and revoke your API key. This cannot be undone.
- Delete your project folder by running this command in the terminal:
macOS
cd ~/Desktop
rm -rf [[PROJECT_FOLDER="your project folder name"]]
Windows
cd ~\Desktop
rmdir /s /q [[PROJECT_FOLDER="your project folder name"]]
- Unset the environment variable in your current terminal session:
macOS
unset GEMINI_API_KEY
Windows
Remove-Item Env:GEMINI_API_KEY
- Delete your API key from Google AI Studio:
- Open the API Keys page in Google AI Studio.
- Find the API key you created for this project.
- Click the Actions icon next to the key, then select Delete API key.
- Confirm deletion in the modal. It takes a few minutes to propagate.
Nice Work!
Nice Work!
Nice work! You just built a fully functional AI Study Buddy powered by Google's Gemini API, running right in your terminal.
You've learned how to:
- Called the Gemini API programmatically from Python using system instructions to control the AI's persona and behavior.
- Built a multi-turn chat loop with conversation memory using the SDK's chat helper.
- Added real-time streaming and error handling for a production-ready terminal experience.
- Secret Mission: Added a quiz mode using structured prompt engineering to generate and evaluate practice questions.
Ready to quiz yourself?