Home › Gemini API course: 3 beginner lessons

Gemini API course: 3 beginner lessons

Last checked

What it does

The Gemini API lets your code use Google's Gemini models for text, images, structured output, Google Search grounding and agents, starting free in Google AI Studio.

Who it's for: Developers who want Gemini models inside their own app or script.

Made by Google.

Sign up and log in
  1. Sign in to Google AI Studio; it creates a project and an API key for new users automatically.
  2. Copy the key from the API keys page (or select Create API key).
  3. Set it as an environment variable: export GEMINI_API_KEY="YOUR_API_KEY"
  4. Install the Python SDK: pip install -U google-genai (a JavaScript SDK and REST also work).
  5. Optional: select Set up billing to move to the paid tier for higher rate limits.

The Gemini API has a free tier with limited model access. The paid tier needs Cloud Billing and a minimum prepayment of US$5 in credits. The Batch API costs 50% of the standard price.

Lesson 1: Get a key in AI Studio and make your first call

Google's current getting-started guide uses the Interactions API: one call with a model name and your input, and the answer comes back as output_text..

  1. Get your key from the AI Studio API keys page and export GEMINI_API_KEY.
  2. pip install -U google-genai
  3. In Python: from google import genai, then client = genai.Client().
  4. Call client.interactions.create(model="gemini-3.8-flash", input="…").
  5. Print interaction.output_text.

Open lesson 1 →

Lesson 2: Ground answers in Google Search and get JSON

Grounding with Google Search lets Gemini answer about recent events and cite its sources, and structured outputs make it return JSON that matches your schema..

  1. Add tools=[{"type": "google_search"}] to your interactions.create call.
  2. Show users the sources returned with the grounded answer.
  3. For JSON, define a schema with Pydantic (Python) or Zod (JavaScript).
  4. Pass the schema in your request so the reply matches it.
  5. Use it for data extraction, classification or inputs for other tools.

Open lesson 2 →

Lesson 3: Process big jobs at half price with the Batch API

For large jobs that don't need an instant answer (tagging, summaries, evaluations), the Batch API runs your requests at 50% of the standard cost..

  1. Collect your requests: inline in the batch request for small jobs (under 20MB), or one per line in a JSONL file for big ones.
  2. Create the batch job with the SDK.
  3. Wait for it to finish; Google targets 24 hours, and most finish much sooner.
  4. Read the results: a list of responses, or a JSONL file with one response or status per line.
  5. Match each result to its request and handle any failed lines.

Open lesson 3 →

Sources

Start Lesson 1 →

Also: All Google products · Gemini course · Gemini features and prices · All tutorials

Report an error on this page