APIs & Agentic AI: Your First LLM Call
Unit 1, Lesson 1
Outcomes
APIs & Agentic AI
- By the end of this lesson, you will be able to define what an API is in plain language and give a real-world example.
- By the end of this lesson, you will be able to explain what agentic AI is and how it differs from a regular LLM call.
- By the end of this lesson, you will be able to set up Google Colab with a secure API key and make your first LLM call.
- By the end of this lesson, you will be able to identify risks of mishandling API keys and explain how to store them safely.
- By the end of this lesson, you will be able to configure a model with a system prompt, temperature, and token limit.
Preparation
Before this lesson, read the primer:
| Resource | Description |
|---|---|
| 🌱 Primer 1.1 | What is an API? Read this before class. |
Come ready to answer:
- In your own words, what is an API?
- What do you think would happen if your API key was posted publicly on GitHub?
Discussion
- Report on work accomplished
- Key takeaways
- Questions unaddressed
- Optional discussion questions
- In your own words, how would you explain an API to someone who has never programmed?
- What is the difference between using an AI app like ChatGPT and calling an LLM through an API?
- Why do you think companies charge per API call instead of a flat fee?
- Log partner’s contribution
Class
Lesson Overview
| Segment | Duration |
|---|---|
| Lecture: APIs & Agentic AI | 15 minutes |
| Activity: Colab Setup & First LLM Call | 15 minutes |
| Lecture: System Prompts & Model Configuration | 10 minutes |
| Activity: Configure Your Own Model | 15 minutes |
| Wrap-up & Preview | 5 minutes |
Part 1 APIs & Agentic AI
What is an API? (Reiterate from primer)
You read about APIs before class. Let’s make it concrete with what we’re actually doing today.
When you write this line of Python:
model.invoke("Tell me about the ocean.")Your computer is not doing the thinking. It is sending your message to Google’s servers through an API, waiting for a response, and handing it back to you. The API is the agreed-upon way your code talks to their AI.
Just like a restaurant menu tells you exactly what you can order and in what format, an API tells your program exactly what requests it can make and what to expect back.
Regular AI vs. Agentic AI
So far, everything you have heard about AI probably looks like this:
You type something → AI thinks → AI responds. Done.
That is a regular LLM call. One message in, one message out. The AI has no memory, no tools, and no ability to take action in the world.
Agentic AI is different. An agent can:
- Think in a loop reason about what to do next
- Use tools search the web, read files, run code, call APIs
- Observe results read the output of a tool and decide what to do next
- Keep going repeat until the job is done
You ask
→ Agent thinks: "what do I need?"
→ Agent uses a tool
→ Agent reads the result
→ Agent thinks again
→ Agent answers ✅
A regular LLM is like texting a smart friend they answer from memory. An AI agent is like hiring an intern they go look things up, take actions, and come back with a real answer.
This course is about building agents. But first, we need to learn how to talk to the AI at all. That starts today.
Why API Keys Need to Stay Secret
An API key is like a credit card number combined with a password. It proves to Google’s servers that the request is coming from your account.
If someone gets your API key they can:
- Make thousands of API calls billed to your account
- Use your quota, locking you out of the service
- Potentially access other services linked to your account
- Never paste your key directly in your code
- Never upload it to GitHub bots scan public repos for keys within seconds
- Always store it in a secrets manager or
.envfile
In this course we use Google Colab Secrets to store keys safely. You will set this up in the next activity.
Activity 1 Colab Setup & Your First LLM Call
Work through every step below. Do not move on until you see a response from the model at the bottom. Help your neighbor if they get stuck before moving ahead.
Step 1 Get your API key
- Go to aistudio.google.com/apikey
- Sign in with a personal Google account (not a school email)
- A key should be created automatically click to copy it
- Make sure you are using a personal Google account, not a school or work email
- If it says your region is not supported, check your Google account age verification settings
- As a last resort, an OpenAI key will also work ask your instructor for the code differences
Step 2 Store your key in Colab Secrets
Store it in Secrets instead. Here is how:
- Click the 🔑 key icon in the left sidebar of Colab
- Click “Add a new secret”
- Name it exactly:
GOOGLE_API_KEY - Paste your key as the value
- Toggle “Notebook access” ON
Then run this cell to load it:
import os
from google.colab import userdata
os.environ['GOOGLE_API_KEY'] = userdata.get('GOOGLE_API_KEY')
print("API key loaded!")Step 3 Install packages
%pip install -q -U langchain langchain-google-genaiIf you close and reopen the notebook, run it again.
Step 4 Make your first LLM call
from langchain.chat_models import init_chat_model
model = init_chat_model(
model="google_genai:gemini-2.5-flash"
)
response = model.invoke("Hello! What are you?")
print(response.content)You should see something like:
I'm Gemini, a large language model made by Google...
If it worked great! Help your neighbor get to the same point before moving on.
If it did not work raise your hand. Do not skip ahead.
Part 2 System Prompts & Model Configuration
You just made a raw LLM call. The model answered as itself with no instructions. But in real applications, we almost always want to shape how the model behaves. That is what system prompts and model configuration are for.
System Prompts
A system prompt is a set of instructions you give the model before the conversation starts. Think of it as the job description you hand a new employee on day one.
The user never sees the system prompt it runs silently in the background and shapes every response the model gives.
System prompt: "You are a grumpy pirate who answers every question
with nautical metaphors and mild complaints."
User: "What is 2 + 2?"
Model: "Arrr, that be 4, ye landlubber. Though why ye bother
me with such trivial arithmetic when there be treasure
to find, I'll never know..."
System prompts are one of the most powerful tools in agentic AI. They control:
- The agent’s persona and tone
- Its rules and constraints
- What tools it should use and when
- What it should never do
Temperature
Temperature controls how creative or predictable the model’s responses are.
| Temperature | Behavior | Good for |
|---|---|---|
0.0 |
Very predictable, consistent | Facts, SQL, code |
0.5 |
Balanced | General assistant |
1.0 |
Creative, varied | Brainstorming, writing |
>1.0 |
Wild, unpredictable | Rarely useful |
0 = the model always picks the most likely next word. 1 = it takes more risks. Higher = chaos.
Max Tokens
A token is roughly ¾ of a word. max_tokens limits how long the model’s response can be.
max_tokens=50→ a sentence or twomax_tokens=500→ a paragraphmax_tokens=2000→ a long essay
This matters because:
- Cost you are billed per token
- Speed shorter responses come back faster
- Control stops the model from rambling
Activity 2 Configure Your Own Model
Now you will build a configured agent using everything from Part 2. Follow the steps below and then experiment on your own.
Step 1 Install the agent package
%pip install -q -U langchain langgraph langchain-google-genaiStep 2 Build a configured agent
from langchain.chat_models import init_chat_model
from langchain.agents import create_react_agent
# Configure the model
model = init_chat_model(
model="google_genai:gemini-2.5-flash",
temperature=0.7,
max_tokens=300
)
# Give it a system prompt
system_prompt = "You are a helpful assistant who explains everything using food analogies."
# Create the agent
agent = create_react_agent(
model=model,
tools=[],
prompt=system_prompt
)
# Invoke it
response = agent.invoke({"messages": [{"role": "user", "content": "What is an API?"}]})
print(response["messages"][-1].content)Step 3 Experiment
Try changing each of these one at a time and observe what happens:
| What to change | Try this |
|---|---|
system_prompt |
Make the assistant explain things like a sports commentator |
temperature |
Change it to 0.0 then 1.0 notice the difference? |
max_tokens |
Set it to 50 what happens to the response? |
| The question | Ask something completely different |
The goal is to build intuition for how each setting changes the model’s behavior. Play around!
Step 4 Reflection
Before moving on, answer these in your notebook or out loud to a partner:
- What did changing the system prompt do to the response?
- What happened at very low vs. very high temperature?
- Why would you want to limit
max_tokensin a real application?
Before Next Class
Next lesson we go deeper into tools the hands of an AI agent. Before class:
- Finish any part of today’s activities you did not complete
- Make sure your Colab setup is working you will need it next class
- Read the primer for Lesson 1.2 before you arrive
| Practice | Primer | Next Lesson |
|---|---|---|
| 🏃♂️➡️ | 🌱 | ➡️ |