In plain words
When a weather app on your phone shows 31°, it didn't measure anything. It sent a short, formatted request to a weather company's computers and got numbers back. That doorway between the two programs is an API, short for application programming interface.
An API is like a menu: it lists exactly what you can ask for and how to ask. You don't see the kitchen, and you don't need to.
In AI, this matters because most apps with AI features don't run their own model. They send your text to a model from OpenAI, Anthropic, Google or others through that company's API, pay per use, and show you the reply. An API key is the secret password that identifies who is asking and who gets the bill.
Everyday example
Ordering through the restaurant counter
At a busy dhaba, you don't walk into the kitchen. You go to the counter, order from the menu ("two paneer parathas, less butter") and show your token. The kitchen cooks, and the plates come back to the counter. The menu is the API's list of requests, your token is the API key, and the plates are the response.
Where the example breaks: A cook might accept an off-menu request. An API is strict: a request that doesn't match the expected format exactly is simply rejected with an error.
How it actually works
IBM's definition: an API is "a contract that enables software to access data or invoke functionality exposed by other software".
A request goes to an address
Most web APIs work over the same technology as websites (HTTP). The calling program sends a request to an address called an endpoint, such as
/weather?city=Delhi, with a method like GET (read) or POST (send).The key proves who is asking
The request carries an API key or token. The service checks it, applies limits and records usage for billing. Anyone holding your key can spend on your account, so it must stay secret, on a server, never inside a public app or a shared document.
A structured response comes back
The service replies in a predictable format, usually JSON, such as
{"temp": 31}. The calling app picks out what it needs and displays it.AI model APIs
For a language model, the request contains a system prompt, the conversation as a list of messages and settings like the model name and maximum length. The response is the model's reply plus a count of tokens used, which is how pricing is measured.
- Stands for
- Application programming interface
- Most common style
- REST over HTTP, using methods like GET and POST on web addresses called endpoints
- AI milestone
- OpenAI launched its GPT-3 API in private beta in June 2020, a "text in, text out" interface that let developers build on a large language model
- Everyday examples
- "Pay with" buttons on shopping sites, maps inside delivery apps, weather widgets, and AI features inside other apps
When an AI model calls an API itself to fetch data or take an action, that is tool use. MCP is a standard way of offering such tools to AI apps.
Questions people ask
What is an API key?
A long secret code that a service gives you to identify your requests. It controls access, enforces limits and decides who pays. Treat it like a password: don't paste it in public code, chats or screenshots, and revoke it if it leaks.
Is the ChatGPT app the same as the OpenAI API?
No. ChatGPT is an app for people, with its own subscription. The OpenAI API is for developers to put the same family of models into their own software, billed separately by usage. The other big AI companies offer the same split.
Why do AI APIs charge by tokens?
Because the work a model does grows with the amount of text it reads and writes. Text is measured in tokens, small pieces of words, so providers price input and output tokens separately.
Do you need to code to use an API?
Usually some, but less than before. No-code automation tools can call APIs for you, and AI coding assistants can write the connecting code from a plain description. You still need to keep the API key safe.