Skip to content

02 — Setting up the environment + API key

Duration: 10 min Prerequisites: Python 3.9+, an OpenAI account (free to create).

Terminal window
mkdir project-2
cd project-2
# Shared library (mandatory)
git clone https://github.com/inskillflow/csv-llm-shared.git
# The OpenAI app
git clone https://github.com/inskillflow/csv-llm-openai.git

If you already did Project 1, you already have csv-llm-shared/ cloned — you can reuse it (just clone csv-llm-openai/ next to it).

Terminal window
pip install -r csv-llm-shared/requirements.txt # pandas, plotly, pyyaml
pip install -r csv-llm-openai/requirements.txt # + streamlit, openai, python-dotenv

Sanity check:

Terminal window
python -c "import pandas, plotly, yaml, streamlit, openai, dotenv; print('OK')"
  1. Sign in at platform.openai.com.
  2. Go to Settings → Billing and add at least $1 of credit. (You can spend more later but $1 is the minimum payment.)
  3. Go to Settings → API keys → Create new secret key.
  4. Give it a name like csv-llm-openai-course and click Create.
  5. Copy the key (sk-...). You won’t see it again. Save it somewhere temporary (a sticky note window, not committed anywhere).

The repo ships with a template:

Terminal window
copy csv-llm-openai\.env.example csv-llm-openai\.env

Open csv-llm-openai\.env in your editor and paste:

OPENAI_API_KEY=sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

csv-llm-openai/.gitignore already contains:

.env
.cache/
__pycache__/

Double-check with git status after copying:

Terminal window
cd csv-llm-openai
git status

Expected: no mention of .env. If you see .env listed as untracked, STOP, and verify .gitignore is correct before going further.

Quick sanity check that your key works:

Terminal window
python -c @"
import os
from dotenv import load_dotenv
load_dotenv('csv-llm-openai/.env')
from openai import OpenAI
client = OpenAI()
r = client.chat.completions.create(
model='gpt-4o-mini',
messages=[{'role':'user','content':'Say OK in one word.'}],
)
print(r.choices[0].message.content)
"@

Expected output:

OK

If you see OK, you’re good. If you see AuthenticationError, re-check the key and that the .env was loaded.

The app reads csv-llm-openai/data/data1-anonymized.csv by default. Confirm it’s there:

Terminal window
ls csv-llm-openai\data\data1-anonymized.csv
# expected: 1 file, ~57 KB

It should exist (the repo ships with it).

Across the 7 chapters and 4 canonical questions, you’ll make roughly:

  • 10 chat completions (test calls, demos)
  • ~6,000 input tokens + ~3,000 output tokens total
  • Total cost: under $0.005 — half a cent.

You’ll hit your $1 minimum hundreds of courses before running out.

ErrorLikely causeFix
AuthenticationError: Incorrect API keyWrong key, or trailing whitespace in .envRe-copy the key, no quotes, no spaces
RateLimitError: 429New account, billing not activeAdd $1 of credit in Settings → Billing
ModuleNotFoundError: openaiPip install missedpip install -r csv-llm-openai/requirements.txt
.env shows up in git statusWrong .gitignoreAdd .env to csv-llm-openai/.gitignore
  • One key, one .env file, one .gitignore entry — that’s the whole secret-management story.
  • Smoke test with openai.chat.completions.create() confirms the key works.
  • Cost for the full course: under one cent.

Next: llm.py side-by-side — Ollama vs OpenAI →