Study tips10 min read

Build your own study quiz app with the free Gemini API: a short Python script that turns lecture notes into flashcards

Understand the free tier, build a notes-to-flashcards script in Python, export to Anki and quiz yourself on a spaced schedule

Medly TeamNovember 19, 2026
On this page

The Gemini API free tier lets you call several of Google's Flash and Flash-Lite models from your own code without paying, so you can build a small study tool in an afternoon. This guide shows you how: one Python script turns your lecture notes into question-and-answer flashcards, and a second quizzes you on them at spaced intervals. You'll also see which models were free when we checked on November 18, 2026, how Google uses what you send, and how to stay inside the limits.

What does the Gemini API free tier include?

Google's pricing page lists a free tier for most of its Flash and Flash-Lite text models. You don't pay for input or output on those models. You do get rate limits, which are set per Google Cloud project, not per API key.

ModelFree tierNote
Gemini 4 HydrogenYesNewest fast model
Gemini 3.8 FlashYesMost capable Flash
Gemini 3.6 FlashYes
Gemini 3.5 Flash-LiteYesUsed in this guide
Gemini 3.1 Flash-LiteYes
Gemini 3 Flash PreviewYesPreview model
Gemini 2.5 FlashYesDeprecated; moves to 3.5 Flash-Lite on December 1, 2026
Gemini 3.1 Pro PreviewNoPaid only

Source: Gemini API pricing. Last checked: November 18, 2026.

For flashcards, a Flash-Lite model is plenty. Writing a short question from a paragraph of notes is a light task, and the lighter models respond quickly. The script below uses gemini-3.5-flash-lite. To try another free model, change one line.

Two more conditions are worth knowing before you start. Google's API terms say you must be 18 or older to use the API. Google's rate limits page also says the limits are not guaranteed and actual capacity may vary.

How Google uses your notes on the free tier

This is the part most guides skip. On the free tier, Google uses what you send "to provide, improve, and develop Google products and services and machine learning technologies." Human reviewers may also read your input and output, after Google disconnects it from your account and API key.

QuestionFree tierPaid tier
Used to improve Google products?YesNo
Human reviewers may read it?YesNot stated
Kept for abuse checks?YesYes, for a limited time

Source: Gemini API Additional Terms of Service, effective March 23, 2026. Last checked: November 18, 2026.

In practice, your own lecture notes on the Krebs cycle are fine to send. Leave out anything personal or confidential: classmates' names, grades, health details, or unpublished research. Google's terms make the same point. Check your course syllabus too, since some instructors set rules on putting course materials into AI tools.

How to get a Gemini API key in Google AI Studio

You need a Google account and Python 3 (3.10 or later is a safe choice) from python.org.

  1. Sign in to Google AI Studio and open the API keys page.
  2. Click "Create API key". AI Studio sets up a project for you if you don't have one.
  3. Copy the key and keep it private. Never paste it into a script you share or push to GitHub.
  4. Save it as an environment variable. On macOS or Linux, run export GEMINI_API_KEY="your-key-here". On Windows PowerShell, run $env:GEMINI_API_KEY="your-key-here".
  5. Install Google's Python library with pip install -U google-genai.

The library reads GEMINI_API_KEY by itself, so your key never appears in your code. This setup follows Google's quickstart. If a later library update renames anything, the quickstart shows the current form.

A Python script that turns lecture notes into flashcards

Save your notes as plain text files, one per lecture or week. Then save this as notes_to_cards.py in the same folder.

import csv
import sys

from google import genai
from pydantic import BaseModel

MODEL = "gemini-3.5-flash-lite"  # any free model on the pricing page
CARDS_PER_FILE = 10


class Card(BaseModel):
    question: str
    answer: str


class Deck(BaseModel):
    cards: list[Card]


PROMPT = """You are helping a college student study.
Turn the lecture notes below into {n} flashcards.
Each question tests one idea and can be answered in one or two sentences.
Use only facts that appear in the notes.

{notes}"""


def main():
    files = sys.argv[1:]
    notes = ""
    for name in files:
        with open(name, encoding="utf-8") as f:
            notes += f"\n\nNOTES FROM {name}:\n" + f.read()

    client = genai.Client()  # reads GEMINI_API_KEY
    interaction = client.interactions.create(
        model=MODEL,
        input=PROMPT.format(n=CARDS_PER_FILE * len(files), notes=notes),
        response_format={
            "type": "text",
            "mime_type": "application/json",
            "schema": Deck.model_json_schema(),
        },
    )
    cards = Deck.model_validate_json(interaction.output_text).cards

    with open("cards.csv", "a", newline="", encoding="utf-8") as f:
        writer = csv.writer(f)
        for card in cards:
            writer.writerow([card.question, card.answer])

    print(f"Added {len(cards)} cards to cards.csv")


if __name__ == "__main__":
    main()

Run it with python notes_to_cards.py week1.txt. Here's what happens. The script reads every file you name and joins them into one prompt. It sends that prompt to Gemini once, with a schema that tells the model to reply with a list of question and answer pairs. It then adds those pairs to cards.csv, one card per row.

The schema matters. Without it, the model might wrap its reply in extra text, and your script would have to guess where the cards start. With it, the reply is JSON your code can read straight away.

Suppose week1.txt contains this: "Glycolysis happens in the cytoplasm and splits one glucose molecule into two pyruvate, with a net gain of 2 ATP. The Krebs cycle runs in the mitochondrial matrix. The electron transport chain sits in the inner mitochondrial membrane, and oxygen is the final electron acceptor, forming water." The first rows of cards.csv could look like this:

Where in the cell does glycolysis take place?,In the cytoplasm.
What is the net ATP gain from glycolysis?,2 ATP per glucose molecule.
What is the final electron acceptor in the electron transport chain?,"Oxygen, which forms water."

Read every card before you study it. The model works only from your notes, so a gap or a typo in the notes can turn into a wrong card. Fixing one takes ten seconds in a spreadsheet.

How to import your flashcards into Anki

If you already use Anki, the CSV is ready to import. The Anki manual covers the details, but the short version is:

  1. In Anki on your computer, choose File, then Import, and pick cards.csv.
  2. Check that the field separator is set to Comma.
  3. Choose the Basic note type and the deck you want.
  4. Map field 1 to Front and field 2 to Back, then import.

Anki then schedules the reviews for you. If you'd rather keep everything in one place you built yourself, use the quiz script below.

How to quiz yourself in the terminal on a 1, 3, 7 day schedule

Testing yourself beats rereading. In a 2006 study, Roediger and Karpicke found that students who practiced recalling a passage remembered more of it a week later than students who spent the same time restudying it. Spacing those tests out helps too, which is what this script does.

Save this as quiz.py:

import csv
import json
import random
from datetime import date, timedelta
from pathlib import Path

INTERVALS = [1, 3, 7]  # days until the next review
PROGRESS = Path("progress.json")
today = date.today()

with open("cards.csv", newline="", encoding="utf-8") as f:
    cards = [tuple(row) for row in csv.reader(f) if len(row) == 2]

progress = json.loads(PROGRESS.read_text()) if PROGRESS.exists() else {}

due = [c for c in cards
       if progress.get(c[0], {}).get("due", today.isoformat()) <= today.isoformat()]
random.shuffle(due)
print(f"{len(due)} cards due today.\n")

for question, answer in due:
    input(f"Q: {question}\n(press Enter to see the answer) ")
    print(f"A: {answer}")
    got_it = input("Did you get it? (y/n) ").strip().lower() == "y"

    step = progress.get(question, {}).get("step", 0)
    if got_it:
        days = INTERVALS[min(step, len(INTERVALS) - 1)]
        step += 1
    else:
        days, step = 1, 0
    progress[question] = {"step": step,
                          "due": (today + timedelta(days=days)).isoformat()}
    print(f"Next review in {days} day(s).\n")

PROGRESS.write_text(json.dumps(progress, indent=2))

Run python quiz.py once a day. A new card is due straight away. Each time you get it right, it moves to the next gap: 1 day, then 3, then 7, and it stays at 7 after that. Get it wrong and it goes back to the start, due again tomorrow. Your progress lives in progress.json, so you can close the terminal and pick up the next day.

Say the answer out loud or write it down before you press Enter. Recalling it is the part that does the work. For more on building questions that test understanding, see this active recall method.

How to stay under the Gemini API free limits

Free-tier limits come in three kinds: requests per minute, tokens per minute and requests per day. Google's rate limits page says the daily quota resets at midnight Pacific time and that all keys in one project share the same limits.

  1. Batch your notes. python notes_to_cards.py week1.txt week2.txt week3.txt makes one request, while running the script three times makes three.
  2. Keep each batch to a week or two of notes. A whole semester in one prompt can hit the tokens-per-minute limit.
  3. Check your quota before a big run. The rate limit page in AI Studio shows your project's current limits and how much you've used.
  4. Generate cards once, then quiz from the CSV. quiz.py never calls the API, so reviewing costs you nothing.

If you see a 429 error, you've hit a limit. Wait a minute for the per-minute limits, or until midnight Pacific for the daily one. On a project without billing, a request over the limit is refused, and nothing is charged.

Gemini API Python practice questions

These questions ask you to change and reason about the two scripts above. Try each one before you open the answer.

Question 1: (3 marks)

Change quiz.py so that any card you miss is shown again at the end of the same session, until you get every card right. The card's schedule should still say it's due tomorrow.

Answer
  1. Before the main loop, create an empty list: missed = [].
  2. Inside the loop, after setting got_it, add the card to the list if you missed it: if not got_it: missed.append((question, answer)).
  3. After the loop, keep retesting until the list is empty. Don't touch progress here, so the card keeps its 1-day due date.
while missed:
    print(f"Retesting {len(missed)} missed card(s).\n")
    still_missed = []
    for question, answer in missed:
        input(f"Q: {question}\n(press Enter to see the answer) ")
        print(f"A: {answer}")
        if input("Did you get it? (y/n) ").strip().lower() != "y":
            still_missed.append((question, answer))
    missed = still_missed

A common slip is updating progress inside the retest loop, which would push the card to a 3-day gap after one same-day retry.

Question 2: (1 mark)

You send your lecture notes to a free-tier Gemini model from the US. Which statement matches Google's API terms?

A. Your notes are deleted as soon as the reply is sent.

B. Your notes may be used to improve Google's products and may be read by human reviewers.

C. Your notes are used only if you opt in to data sharing.

D. Your notes are treated the same way as on the paid tier.

Answer

B. On unpaid services, the terms say Google uses submitted content to improve its products and machine learning technologies, and that human reviewers may read it after it is disconnected from your account. On the paid tier, prompts and responses are not used to improve Google's products.

Question 3: (2 marks)

A new card is shown by quiz.py for the first time on Tuesday, December 1, 2026. You get it right that day and at every review after. Give the dates of its next three reviews.

Answer
  1. December 1: the card is at step 0, so a correct answer sets a 1-day gap. Next review: Wednesday, December 2.
  2. December 2: step 1, so the gap is 3 days. Next review: Saturday, December 5.
  3. December 5: step 2, so the gap is 7 days. Next review: Saturday, December 12.

After that the gap stays at 7 days, because min(step, len(INTERVALS) - 1) keeps the index at the last item in the list.

Question 4: (3 marks)

Change quiz.py so that running python quiz.py missed quizzes you only on the cards you got wrong at their last review, whether or not they are due.

Answer
  1. Add import sys at the top.
  2. When you save progress, record the last result as well: progress[question] = {"step": step, "due": ..., "missed": not got_it}.
  3. Straight after the line that builds due, swap in the missed cards when the word missed is given:
if len(sys.argv) > 1 and sys.argv[1] == "missed":
    due = [c for c in cards if progress.get(c[0], {}).get("missed")]

Cards saved before this change have no missed key, so .get("missed") returns None and they are left out, which is what you want.

Once your scripts work, you've built the same loop good study tools use: questions from your material, answered from memory, at growing gaps. If you'd rather skip the code, Medly turns your uploaded lecture notes and slides into personalized flashcard decks and summaries you can edit, sets you questions from a large question bank and marks your answers with personalized feedback, so you can spend the time on the studying itself.

Frequently asked questions

Is the Gemini API free to use?

Yes. Google's pricing page lists a free tier for its fast text models, including Gemini 4 Hydrogen, Gemini 3.8 Flash, 3.6 Flash and 3.5 Flash-Lite, with rate limits set per project. Gemini 3.1 Pro Preview has no free tier.

Does Google train on data sent through the free Gemini API?

Yes. Google's terms say free-tier content is used to improve its products and machine learning technologies, and human reviewers may read it. Content sent on the paid tier is not used that way.

Do I need to be 18 to use the Gemini API?

Yes. The Gemini API terms say you must be 18 or older to use the APIs.

What are the Gemini API free tier limits?

They vary by model and project, and Google says they are not guaranteed. Your current requests per minute, tokens per minute and requests per day appear on the rate limit page in AI Studio, and daily quotas reset at midnight Pacific time.

What happens if I go over the free limit?

The API returns a 429 error and refuses the request until the limit resets. On a free project with no billing set up, you aren't charged.

Can I use the flashcards in Quizlet instead of Anki?

Yes. Quizlet's import accepts pasted text with a separator between term and definition, and a comma-separated cards.csv opened in a spreadsheet can be copied straight in.

Try Medly for free