Velamuvi AIAcademy

Lesson 1 of 12 · How the Web Talks

What Is an API?

Learn what an API is in plain English, with clear definitions of client, server, request, response and endpoint, and make your first real API call from Python in your browser.

  • 8 min read
  • Beginner
  • Reviewed
In this lesson you will learn
  • What an API is, explained with an everyday example
  • The meaning of client, server, request, response and endpoint
  • Why almost every AI tool is used through an API
  • How to make your first real API call, right in your browser

Programs talking to programs

When you check the weather on your phone, the weather app does not measure the temperature itself. It asks a weather service on the internet, and the service sends back the answer. Two programs, on two different computers, just had a short conversation.

That conversation follows rules that both sides agreed on in advance. Those rules are called an API.

In this course, "API" almost always means a web API.

The restaurant example

A restaurant is a good way to picture an API:

In the restaurantIn software
You, the customeryour program (the client)
The menuthe API's documentation: what you are allowed to ask for
Your order to the waitera request
The kitchenthe server, which does the work
The plate that comes backa response

You never walk into the kitchen. You do not need to know how the food is cooked. You only need to know what is on the menu and how to order. An API works the same way: it hides all the complicated work and gives you a simple way to ask for what you need.

The key words

Every API conversation is the same simple pattern: the client sends a request to an endpoint, and the server sends back a response. You will see this pattern in every lesson of this course.

An API is like a function on another computer

You already know functions. You call a function with some arguments, and it returns a value. An API call works the same way, except the function runs on someone else's computer.

Here is a pretend weather API, written as an ordinary Python function, so you can see the idea without the internet:

Try it yourselfPython
def weather_api(city):
    # Pretend server: in real life this data lives on another computer.
    forecasts = {
        "Hyderabad": {"temperature": 29, "sky": "sunny"},
        "London": {"temperature": 11, "sky": "rainy"},
    }
    if city in forecasts:
        return {"status": "ok", "data": forecasts[city]}
    return {"status": "error", "message": f"No forecast for {city}"}


response = weather_api("Hyderabad")
print(response)

response = weather_api("Atlantis")
print(response)

Notice two things that every real API does too:

  • The answer comes back in a fixed shape that you can rely on: a status and some data.
  • When something goes wrong, you still get a response. It just tells you what the problem was.

Your first real API call

Now the real thing. The code below asks Open-Meteo, a free weather service, for the current temperature in Hyderabad. It is sent over the internet from your own browser.

You will learn every part of this code during the course. For now, just press Run.

Try it yourselfPython
import requests

response = requests.get(
    "https://api.open-meteo.com/v1/forecast",
    params={"latitude": 17.38, "longitude": 78.49, "current": "temperature_2m"},
    timeout=10,
)

print("Status code:", response.status_code)
data = response.json()
print("Temperature now:", data["current"]["temperature_2m"], "°C")

You just used a web API. Your program (the client) sent a request to an endpoint, Open-Meteo's server looked up the weather, and the response came back with real data. Try changing the latitude and longitude to the location of your own city.

Why APIs matter so much in AI

The most powerful AI models are far too big to run on a laptop. They run on huge servers owned by companies such as OpenAI, Anthropic and Google. The way you use them from your own code is through their APIs:

  1. Your program sends a request with your question.
  2. The company's server runs the model.
  3. The response brings back the model's answer.

So when people say "I built an app with GPT" or "I used Claude in my project", what they mean is: their code sent requests to an API. Everything you learn in this course applies directly to that.

Common mistakes

Practice exercise

Act as the client: send a request for each book, and handle both kinds of response, answers and errors.

Your solutionPython
def book_api(title):
    # Pretend server with a tiny library catalogue
    catalogue = {
        "Dune": {"author": "Frank Herbert", "year": 1965},
        "Clean Code": {"author": "Robert Martin", "year": 2008},
    }
    if title in catalogue:
        return {"status": "ok", "data": catalogue[title]}
    return {"status": "error", "message": "Book not found"}


# Call book_api for each title below.
# If the status is "ok", print: <title> was written by <author> in <year>
# Otherwise print: <title>: <message>
titles = ["Dune", "Harry Potter", "Clean Code"]

# Output must be exactly:
# Dune was written by Frank Herbert in 1965
# Harry Potter: Book not found
# Clean Code was written by Robert Martin in 2008
Knowledge check

In an API conversation, which part does the work and sends back the answer?

Summary

  • An API is a set of rules that lets one program ask another for data or an action. A web API works over the internet.
  • The client sends a request to an endpoint, and the server sends back a response.
  • An API call is like calling a function that runs on another computer.
  • The big AI models are used through their APIs, so this skill is at the heart of AI engineering.

Next: what a request and a response actually look like inside.

Finished reading? Tick it off to track your progress.