What Is an API

Updated · 5 min read
easyPython 3.13aiapiecosystemsecurityinterview

How does Navika's shop website talk to an AI model it doesn't own? Her developer friend says "we'll just call the API". Navika nods, but she isn't sure what that means. It turns out to be something she uses every time she orders food in a restaurant.

This lesson explains what an API is, how a request travels to an AI model and back, and the one rule about API keys everyone must follow.

The Waiter Analogy

An API, or Application Programming Interface, is an agreed way for one program to ask another program for something and get a result back. Think of a waiter: you don't walk into the kitchen; you give your order to the waiter in a format the kitchen understands, and the waiter brings back your food.

An API carries requests and results between programs
In a restaurantWith an AI API
You, the dinerThe user
The menuThe API's documentation: what you can ask for
Your orderThe request: model name, messages, settings
The waiterThe API
The kitchenThe model, on the provider's servers
Your food and the billThe response: the answer, and the tokens used

What a Request Looks Like

The picture shows a simplified request and response. Real ones differ by provider, but they share the same parts:

PartWhat it is
EndpointThe address the request goes to
API keyA secret that proves the request is allowed and who pays
Model nameWhich model to use
MessagesThe system prompt and the conversation
SettingsSuch as temperature and maximum output tokens
ResponseThe generated content, plus usage: input and output tokens

A later chapter on model APIs makes real API calls in Python, with the key loaded safely.

Keep API Keys Secret

An API key works like a password and a credit card at once: anyone who has it can use the service and run up charges in your name.

Common Mistakes

Thinking an API is a website. A website is for people; an API is for programs.

Hard-coding an API key "just for testing". Test code gets shared and committed; use an environment variable from the start.

Ignoring usage numbers in responses. They tell you what each request costs.

Interview Corner

What is an API?

An Application Programming Interface: an agreed way for one program to request something from another and receive a result, such as an app sending a question to an AI model and getting an answer back.

How should API keys be stored?

Outside the code, in environment variables or a secret manager, never in source files, prompts or repositories, and rotated immediately if exposed.

Practice

Exercise: map a request. Pick an app you use that has an AI feature. Write the six steps of one request in your own words, from your tap to the answer on screen, naming what you think the application adds before calling the model. Then list two things the response probably contains besides the answer.

Check your understanding:

  1. In the waiter analogy, what is the kitchen?
  2. What does an API key do?
  3. Where should an API key be stored?

Quick check: what is an API

4 questions
1What is an API?
2In the request flow, what does the application do?
3Where should an API key live?
4What does "usage" in a response tell you?

Key Takeaways

Quick reference

TermMeaning
APIAn agreed way for programs to request and receive results
EndpointThe address a request is sent to
API keyA secret that authorizes requests
Request / responseWhat is sent, and what comes back

Was this tutorial helpful?

Lesson 47 of 186