AI Engineer Agentic Track: The Complete Agent & MCP

Day 3 - Set Up Multiple LLM API Keys and Generate a Question to Ask

Beginner 15 minutes
Rupinder Singh
7 views
Setting up optional extra API keys (OpenRouter is the one to pick), verifying each key's shape, and the trick of having an LLM generate its own challenging, non-mathematical test question rather than picking one yourself.

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 index 0).
  • Render it nicely with display(Markdown(...)) rather than a plain print().

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.content is how you pull the text out of a chat completion response.

Resource links

Next

Lecture 1.14 sends this generated question to all eight LLMs and compares their answers using the OpenAI-compatible API.

Frequently Asked Questions (7)

Do I need to set up all eight LLM provider keys to do this lab?

No — you only need keys for the providers you actually want to use. You can follow along with just your Day 1 OpenAI key, or add one or two more (OpenRouter is the easiest, since it's free). Leaving the rest blank is completely fine.

I ran the .env loading cell and got a NameError. What should I check?

This is a common setup issue covered in FAQ #4 of the course FAQ — it usually means a variable or import from an earlier cell wasn't run, or was run in the wrong order. Re-run the notebook's cells from the top in sequence rather than jumping straight to a later cell.

I got an ImportError when loading my keys — what's wrong?

See FAQ #5 in the course FAQ — this is typically a missing or not-yet-installed package in your environment. Make sure you've run the environment setup from Day 1 (uv sync, or equivalent) before running this lab.

Why does my Anthropic/OpenRouter/Google key show as "not found" even though I added it?

Double-check three things: the exact variable name matches what the lab expects (e.g. ANTHROPIC_API_KEY, not a typo or different casing), there are no extra spaces or quotes around the key value, and you saved the .env file before re-running the loading cell.

Why does the lab insist the generated question must not be a mathematical puzzle?

Left unconstrained, LLMs asked to write an "intelligence test question" default to math or logic puzzles very readily. The point of this exercise is to compare models on judgment and nuance, not arithmetic, so the prompt explicitly rules math puzzles out.

Can I just write my own test question instead of generating one with an LLM?

You can, but you'd miss the point of this step — having an LLM generate the question removes your own bias about difficulty and topic, and demonstrates a basic agentic pattern (one LLM call feeding into others). Try the generation approach first, then feel free to experiment with your own questions afterward.

Where can I find more on how to structure a new AI project's dependencies from scratch?

See question 37 in the course FAQ, which explains how the instructor approaches picking packages when setting up a project from scratch.