When you chat with an AI assistant, you type into a website or app. But programs can talk to AI models too, without anyone typing. They do it through an API.
API stands for "application programming interface." That is a mouthful, so here is the short version: an API is an agreed set of rules that lets one program ask another program for something and get an answer back.
A trip to a restaurant
Think about ordering food. You do not walk into the kitchen and cook. You look at the menu, tell the waiter what you want, and the waiter brings it back.
An API works the same way:
- The menu is the API's documentation. It lists what you can ask for and how to ask.
- Your order is the request. Your program sends it to the other program.
- The food is the response. The other program sends it back.
You never see the kitchen. You only need to know how to order. In the same way, your program does not need to know how the AI model works inside. It only needs to send a request in the right shape.
Requests and responses
With an AI model, a request usually holds the text you want the model to read, plus a few settings. The response holds the model's reply, along with some details such as how much text was used.
This happens over the internet, often in less time than it takes to read this sentence. Your weather app, your bank app, and many websites use APIs all day long to fetch information from other services.
API keys are secrets
Before a provider answers your requests, it needs to know who is asking. So it gives you an API key: a long string of letters and numbers that you send along with each request.
Treat that key like a password. Anyone who has it can make requests as you. Do not paste it into emails, chat messages, screenshots, or code you share online. If a key does leak, most providers let you cancel it and make a new one.
You pay for what you use
AI providers usually charge by the token. A token is a small chunk of text, often part of a word. You pay for the tokens you send in and the tokens the model sends back. Long prompts and long replies cost more than short ones. Prices differ by provider and model, and they change often, so check the provider's pricing page. Many let you set a spending limit, which is worth doing before you start.
Try it
Pick an app on your phone that shows live information, like weather or bus times. Write down, in one sentence each, what you think its request and response might be. For example: "Request: weather for my town today. Response: 14 degrees and cloudy."