Applied AI Engineering · Week 0
Set up your $0 lab
By the end of this page, one Python script on your laptop gets an answer from three AI models:
- a Gemini model on Google's free tier;
- a free model on OpenRouter;
- a small model running on your own laptop with Ollama.
Every lab in the course runs on these three, and none of them costs money. Plan for 30 to 45 minutes, most of it downloads.
You need:
- a laptop with Windows, macOS or Linux;
- 8 GB of RAM or more for the local model (less than that? See step 8);
- about 3 GB of free disk space.
1. Install uv
uv installs Python for you and runs the script with everything it needs.
macOS or Linux, in Terminal:
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows, in PowerShell:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Close the terminal, open a new one, and check it worked:
uv --version
2. Get a Gemini API key
- Go to aistudio.google.com/apikey and sign in with a Google account.
- Click Create API key and copy it.
Read this before you send anything. On the free tier, Google uses what you send to improve its products, and people at Google may read it. Never send a client's data, anyone's personal details, or anything confidential through a free tier. The course labs use public documents only.
3. Get an OpenRouter key
- Sign up at openrouter.ai.
- Open Keys in your account settings, create a key and copy it.
Free models on OpenRouter allow 20 requests a minute and 50 a day. That is enough for every lab if you don't run the same script over and over.
4. Install Ollama and download a small model
- Download Ollama from ollama.com/download and install it.
- In a terminal, download the model (2 GB):
ollama pull llama3.2:3b
- Check it answers:
ollama run llama3.2:3b "Say hello in five words."
5. Make your lab folder
Make a folder called ai-lab and open a terminal in it. Create a file named .env with your two
keys, one per line, with no spaces or quotes:
GEMINI_API_KEY=paste-your-gemini-key-here
OPENROUTER_API_KEY=paste-your-openrouter-key-here
Then create a file named .gitignore with this one line, so your keys never end up on GitHub:
.env
6. Run the script
Download hello_three.py from this page into the same folder, then run:
uv run hello_three.py
The first run takes a minute while uv installs Python and two packages. Each model then prints its answer, the tokens it read and wrote, and the seconds it took. The last line says "All three answered" when everything works.
7. If something goes wrong
| What you see | What it means | Fix |
|---|---|---|
GEMINI_API_KEY is missing from your .env file | The script can't find your key | Run the script from the folder that holds .env, and check the name is spelt exactly as above |
AuthenticationError | The key is wrong | Copy it again, or make a new one |
RateLimitError | You hit a free-tier limit | Wait a minute. On OpenRouter you may have used today's 50 requests. For Gemini, see your limits at aistudio.google.com/rate-limit |
APIConnectionError on the Ollama line | Ollama isn't running | Open the Ollama app, or run ollama serve in another terminal |
NotFoundError on the Ollama line | The model isn't downloaded | Run ollama pull llama3.2:3b |
NotFoundError on the OpenRouter line | That free model was withdrawn | Pick another model ending in :free at openrouter.ai/models, and change its model line in the script |
8. Less than 8 GB of RAM?
Skip step 4. In hello_three.py, change the Ollama entry to a second free OpenRouter model:
{
"label": "OpenRouter, small free model",
"base_url": "https://openrouter.ai/api/v1",
"key_name": "OPENROUTER_API_KEY",
"model": "liquid/lfm-2.5-2.6b:free",
},
You will miss the local-model parts of the labs, but everything else works.
hello_three.py
The script for step 6. Save it in your ai-lab folder.