Free lesson · Module 1, lesson 6 of 7

Setting up: Python, a project, secret keys and a local model

Create the course project with a locked list of packages, keep the API key in an environment file that is never committed, and run a small open model in Google Colab as a free fallback.

Lessons in this module

Lesson notes

For the student

From this lesson on you run code. You set up the course project once, on your laptop or in Google Colab: the same Python and the same packages as every other student, a secret key kept in a private file, and one command that tells you the setup is ready. The code is in the companion folder companion/agentic-ai-engineering/; its README.md lists the five setup commands for a laptop, and notebooks/colab_setup.ipynb does the setup in Google Colab.

A lock file: the same packages on every machine

  • The course uses Python 3.12 and uv, a tool that installs Python and packages
  • pyproject.toml lists what the project asks for; uv.lock pins every package to one exact version
  • uv python install 3.12 installs the Python version; uv sync installs exactly what uv.lock lists
  • You never edit uv.lock by hand

The secret key

  • An API key is a secret text that tells a model provider who is calling. Treat it like an ATM PIN
  • The course default is a hosted model with a free tier: sign up on the model provider's website and copy the key
  • cp .env.example .env, then paste the key after AIKIT_API_KEY= in .env
  • .gitignore lists .env, so Git never commits it. .env.example is committed: it shows the names, never your key
  • The four names this lesson uses: AIKIT_API_KEY (required for a hosted model), AIKIT_BASE_URL and AIKIT_MODEL (used from module 2), AIKIT_LOCAL_URL (optional). .env.example lists more names; module 2 explains them
  • Never put the key in code, in a screenshot or in a print. If it leaks, make a new key on the provider's website and delete the old one

How the project reads `.env`

  • Each line is NAME=value. Blank lines and lines starting with # are skipped
  • The line is split at the first =, so a value may contain =
  • The project reads the file with its own short function, parse_env. It is kept in aikit/settings.py, and check_setup.py uses it
  • A value set in the terminal's environment wins over the same name in .env: {**file, **environ} keeps the later value

The setup check

  • uv run python check_setup.py prints four lines, each starting with OK or MISSING: the Python version, the lock file, the key, the local model server
  • The first three are required. With no key, the third line starts with MISSING and the exit code is 1 (a local model needs no key: see Google Colab below)
  • A key made only of spaces is MISSING too
  • The key is never printed, so the four lines are safe to share
  • The check sees that a key is set. It does not call the provider, so a wrongly typed key shows up at the first model call

Google Colab: a small open model, the free fallback

  • Google Colab is a notebook in your browser that runs on a borrowed machine. You install nothing, and you need no key
  • Open notebooks/colab_setup.ipynb from the companion folder in Google Colab and run its cells from top to bottom
  • It unpacks the project on the notebook machine, runs uv sync, starts a local model server there with the small open model the notebook starts, and writes a .env for it
  • A local model server is a program that runs a model on the same machine. It asks for no key, so the .env the notebook writes has no AIKIT_API_KEY line. Its line AIKIT_PROVIDER=local tells the project that the model is local (AIKIT_PROVIDER is one of the names module 2 explains)
  • The third line now says OK AIKIT_API_KEY is not needed for a local model. The fourth says OK local model server answers at http://localhost:11434, and the notebook ends with one real model call
  • On a laptop no local model server is running, and line four says OK local model server (optional, not running) at http://localhost:11434. Your model there is the hosted free tier
  • The model's name is a setting in the notebook's first cell, and you may change it
  • The notebook machine is borrowed: when it shuts down, the project folder, the .env and the model are deleted. Run the notebook again in your next session

Try it

  • Do the setup, on a laptop or in Google Colab, and get four OK lines from uv run python check_setup.py. Paste the four lines in your notes (they contain no key)
  • Then, on a laptop, plant one error in .env: type # in front of the AIKIT_API_KEY line. Run the check and read the MISSING line (the .env in Google Colab has no such line, so these steps are for a laptop)
  • Before you fix the file, run AIKIT_API_KEY=demo uv run python check_setup.py (in PowerShell, run $env:AIKIT_API_KEY = "demo" first, and close that terminal afterwards). The key line says OK: the environment supplied the value the file no longer has
  • Remove the #, run the check again, and get four OK lines

Lesson quiz

Checked in your browser. Nothing is sent or saved.

5 questions

Question 1 · easy

What does uv.lock do in the course project?

Question 2 · easy

Where does your API key go?

Question 3 · medium

A line in .env reads AIKIT_MODEL=small=v2. What value does the project read for AIKIT_MODEL?

Question 4 · medium

.env has AIKIT_API_KEY=abc, and you run AIKIT_API_KEY=demo uv run python check_setup.py. Which value does the project use?

Question 5 · hard

You paste your key into .env with one character typed wrong. What does check_setup.py show on the key line?

What an AI engineer does: the role, the skills, the interviewNext: Your first agent in forty lines