Home › Gemini API course: 3 beginner lessons
Gemini API course: 3 beginner lessons
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
- Sign in to Google AI Studio; it creates a project and an API key for new users automatically.
- Copy the key from the API keys page (or select Create API key).
- Set it as an environment variable: export GEMINI_API_KEY="YOUR_API_KEY"
- Install the Python SDK: pip install -U google-genai (a JavaScript SDK and REST also work).
- 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..
- Get your key from the AI Studio API keys page and export GEMINI_API_KEY.
- pip install -U google-genai
- In Python: from google import genai, then client = genai.Client().
- Call client.interactions.create(model="gemini-3.8-flash", input="…").
- Print interaction.output_text.
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..
- Add tools=[{"type": "google_search"}] to your interactions.create call.
- Show users the sources returned with the grounded answer.
- For JSON, define a schema with Pydantic (Python) or Zod (JavaScript).
- Pass the schema in your request so the reply matches it.
- Use it for data extraction, classification or inputs for other tools.
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..
- Collect your requests: inline in the batch request for small jobs (under 20MB), or one per line in a JSONL file for big ones.
- Create the batch job with the SDK.
- Wait for it to finish; Google targets 24 hours, and most finish much sooner.
- Read the results: a list of responses, or a JSONL file with one response or status per line.
- Match each result to its request and handle any failed lines.
Sources
Also: All Google products · Gemini course · Gemini features and prices · All tutorials