Day 3 - Set Up Multiple LLM API Keys and Generate a Question to Ask
Week 1 · Day 3 · Lecture 13. Lab file: 1_foundations/2_lab2.ipynb. Today's lab has two goals: get so comfortable with chat.completions.create that it becomes second nature, and start gluing multiple LLM calls together into an agentic pattern — a step up from the Day 1 challenge.
How these labs work
Rather than type code from scratch while you watch, the instructor runs pre-written cells and explains them — you run them alongside, then come back in to change, refine and experiment. If you learn better by typing, duplicate a cell and write your own version instead. Either way, the experimentation is the point: being an AI engineer is largely about working like a data scientist, which means trying things out. Good experiments are worth sharing back — community contributions via PR, or a LinkedIn post (tag the instructor and they'll help amplify it).
Step 1: add more API keys (optional)
Day 1 set you up with an OpenAI key. Today's lab can call up to eight different LLMs, so you have the option to add more provider keys to your .env file — but none of this is required. You can follow along using only OpenAI, or even without adding any new keys at all.
If you do want to add more:
- OpenRouter is the recommended one to add first — it gives free access to a wide range of models through a single key, so you can experiment without spending anything.
- Add any other provider keys you already have or want to try (Anthropic, Google, DeepSeek, etc.).
- Follow the exact variable naming from Guide 9 in the guides folder, e.g.
ANTHROPIC_API_KEY=<your key>— get the variable name and the key exactly right, then save the file (Cmd+S / Ctrl+S).
Run the cell that loads the .env file (Shift+Enter) — it should return True. If you get a NameError, see FAQ #4 below; if you get an ImportError, see FAQ #5.
Step 2: verify each key is actually working
The lab includes a check cell that tests each key you've set (OpenAI, Anthropic, Google, DeepSeek, and others) and reports whether it exists and looks right — not just that a variable is set, but that its value has the shape you'd expect from that provider (an Anthropic key has its own prefix, an OpenRouter key starts with sk-or, and Google's key format has varied over time). You only need the keys for providers you actually want to use — leaving the rest blank is completely fine.
Step 3: don't pick the test question yourself — ask an LLM to
The lab's real exercise is testing eight different LLMs against the same question and comparing how they do. The interesting design choice: the question itself is generated by an LLM, not written by hand. That avoids the instructor's own bias in picking something too easy, too hard, or too narrow — and it's a small taste of using one LLM call to set up the input for others.
The prompt used to generate the question is deliberately specific:
"Please come up with a challenging, nuanced question with a succinct answer that I can ask a number of LLMs to evaluate their intelligence. Not a mathematical puzzle, but rather more of a thought-provoking question that requires intelligent insight. Include in your question that the answer must be short." — plus an instruction to answer only with the question, no explanation.
Two design choices are worth noticing here: explicitly ruling out math puzzles (the model defaults to those otherwise), and asking for a short answer — useful when you're about to compare eight responses side by side.
Step 4: make the call
The request follows the same shape from Day 1: package your prompt as a list of dictionaries with role and content keys, e.g. [{"role": "user", "content": "<the prompt above>"}], then call the client:
- Create a client instance for the provider you're calling (OpenAI, in this case).
- Call
client.chat.completions.create(model=..., messages=...)— using the strongest available model here makes sense, since you only need to generate one question, not run it at scale. - Read the result from
response.choices[0].message.content(note:choices, plural, then index0). - Render it nicely with
display(Markdown(...))rather than a plainprint().
One real example this produced: "What is one human virtue that can become a vice when optimized too aggressively, and why? Answer in no more than two sentences." — a genuinely open-ended, non-mathematical question that rewards judgment rather than calculation, which is exactly the target.
What you should now understand
- Adding more provider keys is optional — OpenRouter is the best one to add if you want free access to more models.
- Always verify a key both exists and has the right shape/prefix for its provider before trusting it.
- Letting an LLM generate the test question (rather than picking it yourself) removes your own bias and demonstrates chaining one LLM call into the input for others.
- Explicitly steering the prompt away from math puzzles and toward a short answer makes the resulting comparison across models more useful.
response.choices[0].message.contentis how you pull the text out of a chat completion response.
Resource links
- OpenRouter — free access to many models with one key
- Course resources page (Guide 9 covers provider setup; the FAQ covers common setup errors)
- This lecture on Udemy
Next
Lecture 1.14 sends this generated question to all eight LLMs and compares their answers using the OpenAI-compatible API.