Agentic AI Notebook
Step zero for every AI builder

Get your API keys before you build anything

Every lesson with runnable code — LLM calls, RAG, agents — needs an API key. Free tiers are enough to complete Phase 1 and most early projects.

Why API keys come first

  • You cannot call Gemini, GPT, or Grok without an API key — there is no workaround.
  • Free tiers let you experiment without a credit card (Gemini & Grok) or with trial credits (OpenAI).
  • Store keys in a `.env` file — never commit them to GitHub.
  • Pick one provider to start; you can add others later for comparison or failover.

Choose your provider

Start with Gemini — it's free, fast, and what we use most in this notebook. Add OpenAI or Grok when you want to compare models.

01Recommended

Google Gemini

Recommended — we use this most in the notebook

Step-by-step

  1. 1

    Open Google AI Studio

    Go to aistudio.google.com/apikey and sign in with your Google account.

  2. 2

    Create API key

    Click "Create API key" → choose a Google Cloud project (or create one) → copy the key.

  3. 3

    Save in .env

    In your project folder: `GOOGLE_API_KEY=your_key_here` inside a `.env` file.

  4. 4

    Install SDK & test

    `pip install google-generativeai python-dotenv` then run a one-line generate call to confirm it works.

Free tier (Google AI Studio)

  • Create a key at no cost — no credit card required for the free tier
  • Gemini 2.0 Flash: fast, cheap, great for learning and prototyping
  • Generous rate limits for personal study and small demos
  • Multimodal: text, images, and more in one API

Paid (when you outgrow free)

  • Enable billing in Google Cloud / AI Studio for higher limits
  • Pay per token — Flash models stay very affordable at scale
  • Vertex AI for enterprise: VPC, compliance, SLAs

Environment variable

GOOGLE_API_KEY

Quick test (Python)

test_gemini.py
1import os2from dotenv import load_dotenv3import google.generativeai as genai4
5load_dotenv()6genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))7model = genai.GenerativeModel("gemini-2.0-flash")8print(model.generate_content("Say hello in one sentence.").text)
02

OpenAI

Industry standard — GPT-4o, function calling, Assistants

Step-by-step

  1. 1

    Create an OpenAI account

    Sign up at platform.openai.com with email or Google/Microsoft.

  2. 2

    Add billing (for continued use)

    Settings → Billing → add a payment method when trial credits run out.

  3. 3

    Generate API key

    API keys → "Create new secret key" → name it (e.g. notebook-dev) → copy immediately.

  4. 4

    Save in .env

    `OPENAI_API_KEY=sk-...` in `.env`. Add `.env` to `.gitignore`.

Free / trial credits

  • New accounts may receive limited free trial credits (varies by region)
  • After trial: pay-as-you-go — you only pay for tokens you use
  • gpt-4o-mini is very cheap for learning (~$0.15/1M input tokens)
  • No monthly minimum — ideal once you add a payment method

Paid usage

  • gpt-4o: flagship model for complex reasoning and vision
  • Batch API & caching for lower cost at scale
  • Usage tiers unlock higher rate limits as spend grows

Environment variable

OPENAI_API_KEY

Quick test (Python)

test_openai.py
1import os2from dotenv import load_dotenv3from openai import OpenAI4
5load_dotenv()6client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))7r = client.chat.completions.create(8    model="gpt-4o-mini",9    messages=[{"role": "user", "content": "Say hello in one sentence."}],10)11print(r.choices[0].message.content)
03

Grok (xAI)

Fast reasoning from xAI — great alternative to compare models

Step-by-step

  1. 1

    Sign up at xAI Console

    Go to console.x.ai and create an account (X/Twitter login may be available).

  2. 2

    Create API key

    Navigate to API Keys → "Create" → copy the key (shown once).

  3. 3

    Save in .env

    `XAI_API_KEY=your_key_here` in your `.env` file.

  4. 4

    Test with OpenAI SDK

    xAI is OpenAI-compatible: set `base_url='https://api.x.ai/v1'` and use your XAI key.

Free credits

  • xAI often provides promotional free credits for new developers
  • Check console.x.ai for current offers and monthly free tiers
  • OpenAI-compatible API — easy to swap in existing code
  • Grok models strong at reasoning and coding tasks

Paid usage

  • Prepaid credits or pay-as-you-go via xAI console
  • Competitive pricing on Grok-2 and Grok-3 family models
  • Higher rate limits with paid balance

Environment variable

XAI_API_KEY

Quick test (Python)

test_grok.py
1import os2from dotenv import load_dotenv3from openai import OpenAI4
5load_dotenv()6client = OpenAI(7    api_key=os.getenv("XAI_API_KEY"),8    base_url="https://api.x.ai/v1",9)10r = client.chat.completions.create(11    model="grok-2-1212",12    messages=[{"role": "user", "content": "Say hello in one sentence."}],13)14print(r.choices[0].message.content)

Keep your keys safe

  • Never paste API keys in chat, Discord, or public repos
  • Use `.env` locally and environment variables in production (Netlify, Vercel, etc.)
  • Add `.env` to `.gitignore` on day one
  • Rotate keys immediately if you accidentally expose one
  • Create separate keys per project — revoke without breaking everything

Keys ready? Start building.

Head to Phase 1 — Generative AI Foundations and run the code in each module with your new API key.

Start Phase 1 — GenAI