1 / 8
AI · Grade 11 · Chapter 7

Building with AI APIs

Talking to AI directly from our own code.

Here's a problem

From Chat Window to Code

We've used AI chat interfaces all year. But what if we wanted our own program to send a question to an AI and get a real answer back — automatically, without opening a browser?

Discuss before revealing: What do you think a program needs to "talk" to an AI service over the internet?
Today's tool

APIs for AI

An API (Application Programming Interface) lets our code send requests to an AI service and receive responses — the same technology powering countless AI-integrated apps.

How it looks

A Basic API Call

# simplified API call structure
response = client.send(
  prompt="Explain gravity simply"
)
print(response.text)
Let's build it together

Make a Real API Call

Together, we'll make a basic API call to an LLM and print the response.

Activity: Live-code a simple script that sends a prompt to an AI API and prints the response. Students type along and try different prompts.
Quick check

What do you send to an API to get a response?

AA request, often including a prompt
BNothing, it responds automatically
BA printed document
DA username only
Click to reveal answer
Let's discuss

What could you build if your program could talk to AI directly?

Thinking about your Innovation Challenge project — what becomes possible once your code can call an AI API?

Before you go

Today we learned...

APIs let our own programs talk directly to AI services. Next week: search and sort algorithms!