← Blog

What Is an API Call? How Requests and Responses Work

2026-09-07 · 5 min read · SubToAPI Team

An API call is a request that one piece of software sends to another to ask it to do something or return some data. You send the request over the network (usually HTTPS), the receiving server processes it, and it sends back a response — typically as JSON. That's the whole concept: a structured message out, a structured message back.

If you've ever used curl, called fetch() in JavaScript, or clicked a button in an app that suddenly shows a weather forecast, a map, or an AI-generated answer, an API call happened somewhere in that chain. It's the basic unit of communication between software systems, and understanding it is the first real step toward building anything that talks to another service.

The anatomy of an API call

Every API call has the same core ingredients, regardless of which API you're hitting:

A simple GET request in curl looks like this:

curl https://api.example.com/v1/users/42 \
  -H "Authorization: Bearer YOUR_TOKEN"

And a POST request that sends data:

curl https://api.example.com/v1/users \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "Ada", "role": "engineer"}'

In both cases, you're making an API call: a single round trip where you ask for something and get a structured answer back.

What happens behind the scenes

When you make an API call, several things happen in sequence:

  1. Your client (browser, app, script, or server) builds the HTTP request with the right method, headers, and body.
  2. The request travels over the network to the API server.
  3. The server authenticates the request (checks your API key or token), validates the input, and runs whatever logic the endpoint is responsible for — querying a database, calling a model, processing a file, etc.
  4. The server returns an HTTP response with a status code (like 200 OK, 401 Unauthorized, or 429 Too Many Requests) and a body, usually JSON.
  5. Your client parses that response and does something with it — renders it, stores it, or triggers another action.

That's true whether the API returns a list of products, a payment confirmation, or a chat completion from an AI model. The mechanics don't change; only the payload and the logic behind the endpoint do.

Synchronous vs. streaming API calls

Most API calls are synchronous: you send the request, wait, and get one complete response back. This is fine for fast operations, but for anything that takes time to generate — like a long AI response — waiting for the entire payload can feel slow.

That's where streaming comes in. Instead of one big response at the end, the server sends chunks of data as they become available, and your client processes them incrementally. This is common with AI APIs where text is generated token by token. The API call itself is still a single request, but the response is delivered progressively instead of all at once.

A practical example: calling an AI model as an API

A concrete example makes this easier to internalize. Suppose you want to send a prompt to an AI model and get a response back programmatically instead of typing into a chat window. That's an API call to a "messages" or "completions" endpoint. Here's what it looks like against SubToAPI, which turns your existing Claude access into a standard HTTPS API:

const response = await fetch("https://api.subtoapi.app/v1/messages", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "claude-3-5-sonnet",
    max_tokens: 500,
    messages: [
      { role: "user", content: "Summarize the concept of an API call in one sentence." }
    ]
  })
});

const data = await response.json();
console.log(data);

Here, the endpoint is /v1/messages, the method is POST, the headers carry your API key (sub_live_...), and the body contains your prompt and parameters. The response comes back as JSON with the model's reply plus usage metadata like token counts. That single request-response cycle is, again, one API call — just applied to an AI model instead of a database or a payments system.

If you want to see this pattern end-to-end, the quickstart guide walks through generating a key and making your first call, and the messages documentation and streaming documentation cover request formats and how streamed responses are structured in more detail.

Why API calls matter for developers and products

Once you understand what an API call is, a lot of modern software makes more sense. Every integration — payment processing, sending emails, geocoding an address, running an AI model — is really just a sequence of API calls following a documented contract. Learning to read API documentation, structure a request, and handle the response correctly is one of the most transferable skills in software development, because the pattern repeats across virtually every service you'll ever integrate with.

It's also why usage-based pricing is common: many APIs, including AI ones, charge per call or per unit of data processed (like tokens), because each call consumes server resources on the provider's side.

Questions

Is an API call the same as an HTTP request? For web APIs (the vast majority today), yes — an API call is typically implemented as a single HTTP request paired with its response. Some older or specialized APIs use other protocols, but the request/response concept is the same.

What's the difference between an API call and an API endpoint? An endpoint is the fixed address for a specific action or resource (like /v1/messages). An API call is the actual act of sending a request to that endpoint and receiving a response — the endpoint is the destination, the call is the trip.

Do API calls always cost money? Not always, but many do, especially for compute-intensive services like AI models. Providers often meter usage per call or per token and bill accordingly — check the pricing page of whichever API you're using to understand the cost model before scaling up.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →