Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

What an API Actually Is · Lesson 2 of 9

The Shape of a Request

A free lesson from Swipe AI · Building With AI APIs, level 1 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Different providers, same basic recipe underneath. 📦

Nearly every AI API call has the same basic shape, even though the exact details differ between providers: an endpoint (the specific address the request is sent to), an API key (a private credential that proves the request is really from you and lets the provider bill your account), and a payload (the actual content of the request — usually your prompt, plus some settings).

The response that comes back is typically structured data (not just plain text) — it usually includes the model's actual answer, plus extra information like how many tokens the request used. Your code reads that structured response and pulls out the specific piece it needs.

Conceptual shape of a request:

endpoint:  "https://<provider>/generate"
api_key:   "sk-••••••••••••" (kept secret, never shared publicly)
payload:   {
             prompt: "Summarize this text in one sentence.",
             max_output_length: 50
           }

response:  {
             output: "The text explains how photosynthesis works.",
             tokens_used: 34
           }
The exact field names vary by provider, but this request/payload/response shape is consistent across almost all of them.

An API key deserves real caution: it's tied to your account and its usage bill, so it should never be pasted into code that gets shared publicly or shown on screen — treat it the way you'd treat a password, not a piece of ordinary text.

Quick check

What is an API key's actual purpose?

Fill in the blank

The actual content sent in an API request — usually the prompt plus settings — is called the ____.

True or false

It's safe to paste an API key into code that will be shared publicly, as long as the request itself succeeds.

Keep your streak going in Swipe AI

Swipe through every level of Building With AI APIs on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →