Index Ai Academy
Phase 0 · Tools · Talking to APIs

Calling APIs from Python

Send requests, read JSON responses, and handle failures.

About 30 minutes · Free lesson

Start this lesson

Why it matters

This is the lesson where your code starts talking to the outside world. Calling an LLM, pulling campaign data, posting results to Slack, feeding an agent the tools it uses: each one is a few lines of requests. The habits here (check the status, read the error, set a timeout) are what separate a script that works once from one you can leave running.

What you'll be able to do

  • Send GET and POST requests with the requests library
  • Pass query parameters and JSON bodies without building strings by hand
  • Read status codes and JSON responses in code
  • Handle the three ways an API call fails: error status, no connection, too slow

Before this lesson

Next in this phase: API keys and secrets