CourseAI System Design: The Complete Course · Course guide · part 3 of 107
Part 3 · Course guide

Setup: Colab, Model Providers, Libraries and Prices

13 min read·

This takes about ten minutes. You do it once.

Many lessons need no key at all: the arithmetic, the estimator, the ingestion pipeline, the queue, the web service and the simulations on the shared data all run inside the notebook. The lessons that call a hosted model are marked in each module README and in this table:

ModuleLessons that call a hosted model
1Lesson 1 (the same question twice)
2Lesson 1 (one optional call)
3Lessons 2 and 5 (token counts and timing, measured)
4Lessons 1 and 2, and the lab
6Lessons 2 and 3, and the lab
7Lessons 1, 2 and 4, and the lab
8Lessons 1 and 2 (lesson 3 optional), and the lab
9Lessons 1, 2, 4 and 6 (lesson 3 optional), and the lab
10Lesson 1 (the lab optional)
11Lesson 2
12Lessons 1 and 2, and the lab
13Lessons 1 and 2, and the lab
16The capstone lab

Modules 5, 14 and 15 make no hosted calls.

1. Colab

All code runs in Google Colab on the free CPU. Open a new notebook, paste each code block into a cell in order, and run it. No lesson needs a GPU.

The course targets the Python version Colab runs, which was 3.12 at the last check recorded for this series (13 October 2026); the course's own test environment is Python 3.12.15. Print it once in your first notebook:

python
import sys
print(sys.version)

Code walkthrough

  • sys.version is the version of Python running your notebook. If it does not start with 3.12 (or a later 3.x), some pinned libraries may refuse to install; the run-locally page says which.

2. Choose a model provider

You only need one provider. You switch by changing one word in the setup cell.

ProviderWhat it isWhere you run itCost
GroqA cloud service that runs open-weight models very fastGoogle Colab, or your own computerFree plan with limits
Google GeminiGoogle's own models, through the Gemini APIGoogle Colab, or your own computerFree tier with limits
OllamaA program that runs a model on your own machineYour own computer (07-run-locally.md)Free; you supply the computer

In Colab, choose Groq or Gemini. They need a free key and nothing else. Ollama runs the model on your machine, so no key is needed and no text leaves your computer, which is one of the options Leila weighs in Module 7 when a tenant's contract restricts where its data may go.

Free plans limit requests per minute and per day. If you hit a limit you get an error with the number 429. Wait a minute and try again, or switch provider. Module 14 reads the limit headers and treats them as a capacity ceiling.

3. Get a key

Groq

  1. Go to console.groq.com and sign in.
  2. Open API Keys and create a key.
  3. Copy it. You will not be shown it again.

Model list: console.groq.com/docs/models

Google Gemini

  1. Go to aistudio.google.com and sign in.
  2. Choose Get API key and create a key.
  3. Copy it.

Model list: ai.google.dev/gemini-api/docs/models

4. Store the key safely in Colab

Never paste a key into a code cell. Notebooks get shared, and a key in a shared notebook is a key someone else can spend. (Module 10 lesson 5 is about the same rule at company scale: secrets never live in code.)

  1. In the left sidebar of your notebook, click the key icon (Secrets).
  2. Add a secret. The name must be exactly GROQ_API_KEY (for Groq) or GOOGLE_API_KEY (for Gemini). The value is your key.
  3. Turn on Notebook access for it.

5. The setup cell

Every lesson that calls a hosted model begins with these cells. Paste them, set PROVIDER, and run.

The course uses LangChain, a widely used Python library that gives every model provider the same interface, so the rest of your code does not care which one you chose. That is also the first architectural idea of the course: the model is a dependency behind one boundary, not something written all through the code (Module 4 lesson 3).

python
%pip install -q -U langchain langgraph langchain-groq langchain-google-genai langchain-ollama
python
import os
from langchain.chat_models import init_chat_model

PROVIDER = "groq"   # "groq" or "gemini" in Colab; "ollama" on your own computer
MODELS = {"groq": "groq:openai/gpt-oss-20b", "gemini": "google_genai:gemini-3.5-flash-lite", "ollama": "ollama:llama3.2:3b"}
KEY = {"groq": "GROQ_API_KEY", "gemini": "GOOGLE_API_KEY", "ollama": None}[PROVIDER]
if KEY and KEY not in os.environ:
    from google.colab import userdata   # keys live in Colab's Secrets panel
    os.environ[KEY] = userdata.get(KEY)
llm = init_chat_model(MODELS[PROVIDER], temperature=0, max_retries=6)
python
print(llm.invoke("Reply with the single word: ready").text)

If it prints ready (or something close), you are set up. In the course's test run on 18 October 2026 it printed ready on both Groq and Gemini.

Code walkthrough

  • %pip install ... installs the libraries once per notebook: langchain (the framework), langgraph (its companion for multi-step workflows, used from Module 8) and one connector per provider. This line is the same in every course in the series.
  • PROVIDER = "groq" is the one word you change to switch provider.
  • MODELS names the model for each provider as provider:model-name. This is the only place model names appear, so when a name changes you edit one line.
  • KEY is the name of the secret the provider needs. Ollama needs none.
  • The if block runs only in Colab when the key is not already set: it copies your key from the Secrets panel into an environment variable, which is where LangChain looks for it.
  • init_chat_model(...) creates the model object, llm. temperature=0 asks for the most consistent output. max_retries=6 makes the client wait and try again when the provider says "too many requests" (a 429).
  • llm.invoke(...) sends one message and returns a reply; .text is the reply as a string.

Two tiers, for the routing lessons. From Module 7 the gateway routes between a small, cheap model and a large one. Lessons that need the large tier add this line after the setup cell, and nothing else changes:

python
LARGE = {"groq": "groq:openai/gpt-oss-120b", "gemini": "google_genai:gemini-3.8-flash", "ollama": "ollama:llama3.2:3b"}
big = init_chat_model(LARGE[PROVIDER], temperature=0, max_retries=6)

Code walkthrough

  • LARGE names the stronger model for each provider; Ollama keeps the same local model, because a laptop rarely runs a second, larger one.
  • big is the large-tier model object, created the same way as llm. The gateway decides which of the two each request goes to.

What the providers report back

Every reply carries usage_metadata, the provider's own count of tokens. The estimator in Module 3 is checked against it. In the course's test run on 18 October 2026 the shapes were:

Providerusage_metadata keys seenNotes
Groq (gpt-oss-20b, gpt-oss-120b)input_tokens, output_tokens, total_tokens, output_token_details.reasoningReasoning tokens are counted inside output_tokens and billed as output. Groq's prompt-caching page reports cached input in the raw response as usage.prompt_tokens_details.cached_tokens; Module 8 lesson 2 reads it
Gemini (gemini-3.5-flash-lite, gemini-3.8-flash)the same, plus input_token_details.cache_readgemini-3.5-flash-lite printed a warning that it "uses fixed sampling defaults" and ignores temperature. Expect its answers to vary between runs

When the provider rejects a request or a reply

Sometimes a provider returns an error instead of a reply: a malformed answer, a model name that no longer exists, a brief outage. max_retries does not help when the request itself is the problem. The course handles it the same way everywhere: try once more, and if that also fails, say so plainly instead of crashing.

python
def ask(model, messages):
    """Returns (reply, None), or (None, reason) after two refusals."""
    for attempt in range(2):                     # one retry: the next reply is usually fine
        try:
            return model.invoke(messages), None
        except Exception as err:
            last = err
    return None, f"provider_error: {type(last).__name__}"

Code walkthrough

  • ask sends the messages and returns the reply with no reason, or no reply with a reason.
  • On an error it tries once more; after a second error it gives up and names the error. In the test run, a made-up model name gave provider_error: NotFoundError on Groq and provider_error: GoogleModelNotFoundError on Gemini.

Lessons use this shape: a request the model could not answer gets the result "provider_error" and is counted as a failure in every score, so one bad reply never stops a notebook and never quietly improves a result. This small function is also the seed of the gateway: Module 7 turns "try once more" into a fallback chain across providers, and Module 11 adds timeouts, a retry budget and a circuit breaker.

Lessons that run the golden sets (54 Ask questions, 18 Cases tasks) cache every reply to disk, so a rerun does not pay twice and stays inside the free plans.

6. Prices and limits (checked 18 October 2026)

This is the course's one table of model prices. Lessons that count cost say "prices from course-guide/02" and use these numbers (the same numbers are PRICE_SNAPSHOT in 06-shared-data.md). When a provider changes them, this table changes and the lessons follow. US dollars per 1,000,000 tokens, standard paid tier.

Model (as written in the setup cell)Gateway tierInputCached inputOutputNotes
groq:openai/gpt-oss-20bsmall (default)$0.075$0.0375$0.30131,072-token context, up to 65,536 output. Cached input is 50% off; the cache expires after 2 hours unused
groq:openai/gpt-oss-120blarge$0.15$0.075$0.60Same context and caching
google_genai:gemini-3.5-flash-litesmall (default)$0.30$0.03$2.50Batch: $0.15 input, $1.25 output
google_genai:gemini-3.8-flashlarge$0.75$0.075$3.75Until 31 December 2026; doubles to $1.50 and $7.50 on 1 January 2027. Batch: $0.375 and $1.875
ollama:llama3.2:3blocal$0$0No fee per token; you pay for the machine. A 2.0 GB download
google_genai:gemini-embedding-2 (shown, not used)$0.20Hosted embeddings; the course embeds locally with sentence-transformers for $0

The roadmap's illustrative prices. The worked estimate in Module 3 uses "$1 per million input, $5 per million output" and "a tier at a fifth the price". Those are round numbers for arithmetic, not any provider's price, and the course labels them illustrative wherever they appear.

Limits. Groq's rate-limits page lists 30 requests a minute, 1,000 a day, 8,000 tokens a minute and 200,000 tokens a day for the two gpt-oss models, labelled as base limits for its Developer plan; your own limits are on your console's limits page. Google's rate-limits page says Gemini limits depend on your usage tier and are shown in Google AI Studio.

Deprecations to know about. Groq's deprecations page lists llama-3.1-8b-instant and llama-3.3-70b-versatile as shut down on 16 August 2026, although its models page still listed them on 18 October 2026. Do not use them. Google lists gemini-2.0-flash and gemini-3-pro-preview as shut down. Module 7 lesson 4 uses these as the example of deprecation as a planned event.

Sources (all read 18 October 2026): Groq, Supported models, Prompt caching, Rate limits, Deprecations; Google, Gemini models, Gemini Developer API pricing, Rate limits; Ollama, llama3.2. These are the numbers in this course most likely to go out of date.

7. Closed and managed models, shown but not run

Lessons show how the same call looks on OpenAI or Anthropic models and on the three big cloud platforms, using the official SDK or LangChain snippet from their current documentation, labelled not run here. The course does not call them, so no key is needed and no number in the course comes from them.

PlatformWhat it is (from its own documentation, read 18 October 2026)Python package a snippet uses
Amazon BedrockAWS's managed model service; its Converse API gives one interface across models (Converse and ConverseStream)boto3 1.43.114
Google Gemini Enterprise Agent PlatformGoogle Cloud's AI platform, formerly Vertex AI (renamed in the 22 April 2026 release notes)google-genai 2.31.0
Microsoft FoundryMicrosoft's AI platform, formerly Azure AI Foundry; Azure OpenAI resources are upgraded to Foundry resourcesopenai
OpenAI, AnthropicClosed model providers with their own APIsopenai 3.35.1, anthropic 1.15.0

Versions are the latest on PyPI on 18 October 2026, recorded so a snippet names a real version. With LiteLLM installed (Module 7), pip chooses openai 2.54.0, because LiteLLM 1.106.0 requires a version below 3.0.

8. The libraries

Colab already ships numpy, pandas, torch and transformers. Each lesson installs only what it imports, in one cell near the top, with the version pinned so your run matches the course's. numpy, pandas and torch stay at Colab's own versions, because forcing them can make Colab ask you to restart the runtime.

Versions are the latest releases on PyPI, read on 18 October 2026; "Released" is the upload date of that release.

LibraryPinReleasedFirst usedWhat it is for
pytestpytest==9.1.119 Jun 2026Module 1 (lab)The repository's tests
tiktokentiktoken==0.14.017 Aug 2026Module 3Estimating tokens before a call (the provider's count is the truth)
pydanticpydantic==2.14.111 Oct 2026Module 4Validating structured data at boundaries
langchain, langchain-corelangchain==1.4.6, langchain-core==1.6.1214 and 16 Oct 2026Module 4The model client; the setup cell installs them unpinned with -U
langchain-groq, langchain-google-genai, langchain-ollama1.1.3, 4.4.2, 1.1.0Jun, Oct and Apr 2026Module 4Provider connectors
scikit-learnscikit-learn==1.9.1added 18 Oct 2026Module 4 (lesson 2)The trained intent classifier compared with the rule and generative routers
presidio-analyzer, presidio-anonymizer (optional)2.2.364added 18 Oct 2026Module 5 (lesson 3)Open-source personal-data detection, with spaCy's en_core_web_sm model. Conflict: Presidio 2.2.364 requires numpy below 2.5.0, so it cannot be installed beside the labs' numpy==2.5.4 (pip ResolutionImpossible, checked 19 October 2026). Run its cell in a notebook of its own; Intake's default is the regex-v2 detector
openlineage-pythonopenlineage-python==1.54.0added 18 Oct 2026Module 5 (lesson 3)Lineage events in the OpenLineage format
sentence-transformerssentence-transformers==6.1.018 Sep 2026Module 6Local embeddings; requires huggingface-hub below 2.0
huggingface-hubhuggingface-hub==1.33.024 Sep 2026Module 6Pin it in every cell that installs sentence-transformers, langchain-huggingface or litellm (see below)
faiss-cpufaiss-cpu==1.15.116 Sep 2026Module 6An in-memory vector index
chromadbchromadb==1.5.95 May 2026Module 6An embedded vector database
qdrant-clientqdrant-client==1.19.116 Sep 2026Module 6Qdrant in local mode in Colab, and the client for the Qdrant server locally
rank-bm25rank-bm25==0.2.216 Feb 2022Module 6Keyword search; old but stable
transformersColab's own; locally transformers==5.20.116 Oct 2026Module 7Timing prefill and decode on a small model on CPU
litellmlitellm==1.106.018 Oct 2026Module 7The open-source gateway library, compared with the hand-built gateway
langgraphlanggraph==1.2.1616 Oct 2026Module 8Workflows, state, checkpoints and approvals
langgraph-checkpoint-sqlitelanggraph-checkpoint-sqlite==3.1.212 Oct 2026Module 8SqliteSaver, a checkpoint store in a file; install it beside langgraph==1.2.16
redis, fakeredis, rqredis==8.1.0, fakeredis==2.40.0, rq==2.12.0Jul, Oct and Aug 2026Module 8A job queue; fakeredis stands in for a Redis server in Colab
mcpmcp==2.3.02 Oct 2026Module 9The official Model Context Protocol SDK (specification revision 2026-07-28)
a2a-sdka2a-sdk==1.2.25 Oct 2026Module 9 (Recommended topics)The Agent2Agent protocol SDK; Module 9 lesson 4 runs it in-process
temporaliotemporalio==1.34.0added 18 Oct 2026Module 8 (lesson 4)The durable-workflow SDK; it needs a Temporal server, so the lesson's steps run locally, not in Colab (see 07-run-locally.md)
fastapi, httpxfastapi==0.143.5, httpx==0.28.118 Oct 2026, 6 Dec 2024Module 10The web service; httpx is what TestClient uses
opentelemetry-api, opentelemetry-sdk, opentelemetry-exporter-otlp1.45.16 Oct 2026Module 13Standard tracing
arize-phoenix, arize-phoenix-otel, openinference-instrumentation-langchain20.23.0, 0.17.2, 0.1.79Sep and Oct 2026Module 13A self-hostable trace viewer; Elastic License 2.0 (source-available)
ragasragas==0.4.313 Jan 2026Module 13 (optional)An open evaluation library, compared with the hand-built harness

Libraries used only on your own computer (uvicorn, psycopg, pgvector, langfuse, a Temporal server for temporalio, docker) are on 07-run-locally.md.

The huggingface-hub pin. The newest huggingface-hub was 2.2.0 (8 October 2026), but sentence-transformers 6.1.0, langchain-huggingface 1.2.3 and litellm 1.106.0 all require a version below 2.0. Colab may already have a 2.x version. Every cell that installs one of them pins it:

python
%pip install -q sentence-transformers==6.1.0 huggingface-hub==1.33.0

Code walkthrough

  • sentence-transformers==6.1.0 installs the embedding library at the course's version; huggingface-hub==1.33.0 keeps the download library below 2.0, which sentence-transformers needs. If Colab then asks you to restart the runtime, do so and run the cells again from the top.

Two libraries the course does not use, and why. arq (a Redis job queue) requires redis below 6, which conflicts with the pinned redis 8.1.0, so the course uses RQ. langchain-mcp-adapters 0.3.2 requires mcp below 2.0, so Module 9 writes its own short adapter between MCP tools and LangGraph instead.

Checked on paper, not yet in Colab. On 18 October 2026 a pip install --dry-run of the course's libraries (with huggingface-hub==1.33.0, leaving out arize-phoenix and the serving engines), for Python 3.12 on Linux, wheels only, resolved with no conflict: 193 packages. That proves the pins fit together; the first lesson pilot installs and imports them in Colab and records the result here.

9. Open models from Hugging Face (no key)

ModelLicenceFirst usedWhat it is for
sentence-transformers/all-MiniLM-L6-v2Apache 2.0 (as recorded in this series on 14 October 2026)Module 6Embedding Northdesk's documents and questions
Snowflake/snowflake-arctic-embed-xsApache 2.0 (model card, read 23 October 2026)Module 6 (lesson 1)A candidate embedding model, measured against MiniLM on Northdesk's questions
cross-encoder/ms-marco-MiniLM-L6-v2Apache 2.0 (model card, as Module 6 lesson 1 records)Module 6 (lesson 1)The reranker
HuggingFaceTB/SmolLM2-135M-InstructApache 2.0 (read on the Hub, 18 October 2026)Module 7 (lesson 3)Timing prefill and decode on CPU
BAAI/bge-base-en-v1.5MIT (read on the Hub, 19 October 2026)Module 14 (lesson 2)The embedding model Ask migrates to: 768 dimensions, 512 word pieces

Each lesson names any model it downloads, with its licence read from the Hugging Face Hub on the day it was written; licences can change, so check the model card before you ship one.

10. When something goes wrong

What you seeWhat it meansWhat to do
SecretNotFoundErrorThe secret is missing or misnamedCheck the name is exactly GROQ_API_KEY or GOOGLE_API_KEY
NotebookAccessErrorThe secret exists but this notebook cannot read itTurn on Notebook access for the secret
ModuleNotFoundError: google.colabRunning locally with no key setSee 07-run-locally.md: create the .env file
AuthenticationError (401)The key is wrong or was deletedCreate a new key and update the secret
provider_error: NotFoundError or GoogleModelNotFoundErrorThe model name is out of datePut a current model name in MODELS
RateLimitError (429)You hit the free plan's limitWait a minute, or switch PROVIDER; golden-set runs cache replies so a rerun costs nothing
pip says a package requires huggingface-hub<2.0A newer hub was installedReinstall with huggingface-hub==1.33.0 in the same cell, then restart the runtime
A warning that temperature will be ignoredThe Gemini model uses fixed samplingNothing to do; expect answers to vary a little between runs
A connection error with OllamaOllama is not runningOllama runs on your own computer only: see 07-run-locally.md