For our purposes, we don't need to be super specific about which LLM we use. Any decent, modern model should work. What we want is:
Fortunately, there are options for us on Google's Gemini API. Google has drastically reduced the Gemini free-tier quotas in recent months, but they also have a series of open models called Gemma, which can be used on the free tier with less restrictive limits.
So let's get set up with a Gemini API key and verify that it works by writing a small test script. High-level steps:
.env file to store the API key, which should be kept secret.dotenv library library in your Python code to load the environment variable.google-genai library to make API requests.If you already have a GCP account and a project, you can create the API key in that project. If you don't, AI studio will automatically create one for you.
GEMINI_API_KEY="your_api_key_here"
We never want to commit API keys, passwords, or other sensitive information to Git.
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.environ.get("GEMINI_API_KEY")
if not api_key:
raise RuntimeError("GEMINI_API_KEY environment variable not set")
from google import genai
client = genai.Client(api_key=api_key)
model: The model name, gemma-3-27b-it (this one has a free-tier allowance that should be far more than enough).
contents: The prompt to send to the model (a string). For now, hardcode this prompt:
"Why is Boot.dev such a great place to learn about RAG? Use one paragraph maximum."
The .generate_content() method returns a GenerateContentResponse object. Print the .text property of the response to see the model's answer.
If everything is working as intended, you should be able to run your script and see the model's response in your terminal!
Prompt tokens: X
Response tokens: Y
The response has a .usage_metadata property that has both:
prompt_token_count property (tokens in the prompt)candidates_token_count property (tokens in the response)The Gemini API is an external web service, and it may rate limit your project. On lessons like this one, failed submissions won't penalize you, so it's safe to retry if something goes wrong on Google's end.
Not every lesson in this course is no-penalty, so read the instructions carefully and follow the submit flow each lesson asks for.
Submit the CLI tests.