What it is
An API, or application programming interface, is a set of rules that lets one program talk to another. One side publishes what requests it accepts and what answers it returns. The other side follows those rules. Neither needs to know how the other works inside.
An analogy: an API is a restaurant menu and a waiter. You do not walk into the kitchen. You order from the menu, and the waiter brings back what you asked for.
How it works
Most web APIs work over the internet. Your software sends a request to an address, usually with some data attached, and the service sends a response, often in a format called JSON. A request names what you want, such as "generate text from this prompt," and includes proof of who you are, commonly an API key or an access token.
APIs and AI
Nearly every AI model is available through an API. A developer sends a prompt and settings such as temperature or a system prompt, and the model returns text, an image or a structured output. Billing is usually by tokens processed, which makes the API the place where cost, rate limits and latency become concrete.
Because so many services copy the same request format, an OpenAI-compatible API lets an app switch models by changing an address and a key. APIs are also how tool use works: when an AI agent books a meeting or searches a database, it is calling someone else's API. Standards like the Model Context Protocol exist to make those connections more uniform.
Why it matters
APIs are where products get built, and also where they get attacked. An exposed or poorly protected API can leak data, so it should require authentication, limit request rates and validate every input. Weaknesses such as SQL injection and SSRF often arrive through an API endpoint nobody watches closely.
What to remember
An API is a contract. When it changes, everything built on it can break, so providers announce versions and deprecations ahead of time. If you build on an AI model, read its API documentation first, and keep your keys out of public code.