What Is an API
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.
| In a restaurant | With an AI API |
|---|---|
| You, the diner | The user |
| The menu | The API's documentation: what you can ask for |
| Your order | The request: model name, messages, settings |
| The waiter | The API |
| The kitchen | The model, on the provider's servers |
| Your food and the bill | The 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:
| Part | What it is |
|---|---|
| Endpoint | The address the request goes to |
| API key | A secret that proves the request is allowed and who pays |
| Model name | Which model to use |
| Messages | The system prompt and the conversation |
| Settings | Such as temperature and maximum output tokens |
| Response | The 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:
- In the waiter analogy, what is the kitchen?
- What does an API key do?
- Where should an API key be stored?
Key Takeaways
Quick reference
| Term | Meaning |
|---|---|
| API | An agreed way for programs to request and receive results |
| Endpoint | The address a request is sent to |
| API key | A secret that authorizes requests |
| Request / response | What is sent, and what comes back |
Was this tutorial helpful?