What Does API Mean? A Food-Delivery Analogy and an AI API Call
An API (application programming interface) is a window a program opens to the outside world, where you ask and get answers in a fixed format. You send a request in the agreed format, the other side sends back a result in the agreed format, and you don't need to know what happens in between. Calling an AI model works the same way: you send an HTTP request to a URL and read the text that comes back.
This article answers "what does API mean" with a food-delivery analogy, then breaks down a single AI API call step by step.
What does API mean? The food-delivery analogy
Say you order food on your phone. You don't walk into the kitchen, and you don't need to know how the chef cooks. All you do is:
- Open the app, pick dishes, enter an address, and submit the order.
- The platform checks who you are and whether you can place an order.
- The restaurant prepares the food and a courier delivers it.
Here is how that maps to an API:
| Food delivery | API term | What it means |
|---|---|---|
| Placing an order | Request | You tell the other side what you want, in the required format |
| Menu and ordering rules | API documentation | What you can order and what information to provide |
| Where the order is submitted | Endpoint | A URL that requests are sent to |
| Logging in to your account | Authentication (API key) | Proves you're allowed to use the service, and is used for billing |
| The meal that arrives | Response | The result the other side returns |
| "Order failed" message | Status code and error message | For example: not logged in, over quota, service busy |
So "what is an API" has a short answer: it's an agreement that defines where to send things, in what format, how to prove who you are, and what you'll get back.
What do a request and a response actually look like?
Web pages and APIs use the same protocol, HTTP. A request usually has four parts:
- URL: for example
https://example.com/v1/chat(an example, not a real endpoint). - Method: the common ones are GET (fetch something) and POST (submit something). Calling an AI model is almost always a POST.
- Headers: extra information, and authentication usually goes here.
- Body: what you actually want to say. Most APIs use JSON.
A response has two parts as well: a status code (200 means success, 4xx is usually a problem on your side, 5xx is usually a problem on the other side) and a body.
Is calling an AI model just sending an HTTP request?
Yes. The details differ between AI providers, but the idea is the same: POST a piece of JSON to a URL, say which model to use and what you want to say, and the other side returns the text the model generated.
Below is a structural sketch. The URL and model name are placeholders; check the official documentation of the service you use for the real values:
curl https://接口地址/路径 \
-H "Authorization: Bearer 你的API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "模型名",
"messages": [{"role": "user", "content": "用一句话解释什么是 API"}]
}'
(The placeholders translate as: 接口地址/路径 = endpoint URL/path, 你的API_KEY = your API key, 模型名 = model name, and the message reads "Explain what an API is in one sentence".)
Line by line:
curlis a command-line tool for sending HTTP requests.- The first line is the endpoint URL, which decides who the request goes to.
- The
Authorizationline is authentication. Your key goes here. - After
-dis the body: which model to use and what you said. - In the returned JSON, the model's answer sits in a particular field. Check the documentation for the exact field name.
Many model services use a similar "OpenAI-compatible" format, which is why many tools only need a URL and a key. See What "OpenAI-compatible API" means. To actually send your first request, the fastest route is to follow the steps in How to use an LLM API.
What are an API key and an endpoint, and what should you watch out for?
A key is a string of characters that works like an account plus a password: the other side uses it to identify you and to bill you. A few habits are worth building from day one; for the full explanation see What is an API key:
- Don't paste your key into chat groups, screenshots, or public code repositories.
- Create a separate key for each use, so that if one leaks you only need to disable that one.
- If you see unusual usage, disable the key first and investigate afterward.
Why the endpoint (also called the base URL) can be swapped is another common question; see What is a base URL. In short, as long as the other side follows the same format, your tool can point at a different address and connect to a different service.
What if a call fails?
Work through the table below from top to bottom. It will pinpoint most beginner errors.
| Symptom | Likely cause | What to do |
|---|---|---|
| 401 or "unauthorized" | Key is wrong, expired, or disabled | Copy the key again and watch for leading or trailing spaces |
| 403 | No permission, or your region or account status isn't supported | Check the service's official notes and supported regions |
| 404 | Wrong URL or path | Check the full path against the documentation |
| 400 or invalid parameters | Malformed JSON or wrong model name | Check quotes, commas, and the spelling of the model name |
| 429 | Too many requests, or quota used up | Slow down, or check your quota |
| 5xx | The service itself has a problem | Retry later and check the official status page |
| Keeps timing out | Slow or broken network path | Try another network and test the connection |
The last two rows can be checked with tools. The cdnping API status page probes each official API entry point from the Cloudflare edge every 5 minutes, which helps you tell "the provider is down" from "the problem is on my side". If you suspect your own network, the online speed test on the home page measures initial connection and round-trip time to each AI API from your browser. For background, see How to read latency when accessing AI APIs from China.
I'm a beginner. What should I do next?
Here is a suggested order:
- Read What is an AI API to get the concepts straight.
- Pick a service, create a key, and send your first request using the curl structure above.
- Once it works, put the URL and key into the tools you normally use.
If you're not sure whether you need a web subscription or an API, start with Subscription or API for beginners.
If you want to use coding tools like Claude Code or Codex but can't easily make overseas payments, you can take a look at AGI Plan. AGI Plan is a commercial partner of cdnping, so please read the following description with that relationship in mind. It is a multi-provider LLM aggregation gateway with monthly subscriptions, paid in RMB, with no overseas credit card needed. One subscription can switch between multiple capability groups, and to keep using tools such as Claude Code and Codex you only need to change one endpoint address. The site states that it is not an officially authorized channel, and some models are marked as available outside China only; see the models page for specifics. Before using any service, please read its terms of service and follow local regulations. To see the setup steps, start with the AGI Plan getting-started page.