What an API is, and why you might want one
An API is the same exchange as the chat window with the web page taken away: a program sends the text and a program gets the reply, using an API key as the credential that stands in for you and that the billing runs against.
The API is the chat without the page
Everything so far has gone through a web page: you type, the page sends your words to the model, the page shows the reply. An API (application programming interface) is the same exchange with the page taken away. A program sends the words and a program receives the reply.
- 1Your scriptA few lines of Python or PowerShell on your computer
- 2One requestThe model's name, your instructions, your text, and your key
- 3The vendor's APIThe same models that sit behind the chat window
- 4One replyThe answer as plain text, plus a count of what it used
OpenAI, Anthropic, Google and xAI each sell one, and each has a short quickstart that gets you from a new key to a first answer: OpenAI, Anthropic, Google Gemini. The requests look almost the same across all of them.
Nothing about the model changes. It is no smarter and no less likely to be wrong. What changes is who is doing the typing: a person can send ten requests an hour, and a loop can send ten a minute, every one worded identically.
What that buys you
- The same instruction, hundreds of timesFour hundred tracker rows, each needing a one-line summary. Nobody pastes four hundred times; a loop does.
- Answers in a shape a program can useAsk for a category and a priority per row, get them back as columns you can sort and filter in Excel.
- A check on every answerA script can refuse any reply that lacks a paragraph reference and put it in a pile for a person. A chat window cannot.
- Your own tools around the modelA script can read files on your machine, call the model, and write the result into a spreadsheet, a ticket or an email draft.
What an API key is
The web page knows who you are because you logged in. A script cannot log in, so the vendor gives you a long random string instead, the API key, and the script sends it with every request. OpenAI keys start with sk-, Anthropic keys with sk-ant-.
That makes the key a credential, like a password:
- Whatever is sent with your key is billed to you, or to whoever owns the account.
- Anyone who has the string can use it. It does not check who is holding it.
- It belongs in one place on your machine, usually an environment variable, never in a chat, an email, a shared drive, a screenshot or the script itself. Google's own guidance: never check a key into source control, and never build one into a web or mobile app (Gemini API keys).
- If one leaks, delete it in the vendor's console and make a new one. That takes a minute; an unnoticed leak can cost a great deal more.
If you want a key for work, ask your IT or security office first. Many organizations already hold an account with a vendor and would rather give you a key under it than find your personal one on an expense claim.
What it costs
The chat apps charge a flat monthly fee. The API charges for what you use, counted in tokens: a price per million tokens in and a higher price per million tokens out, different for every model. A token is roughly three quarters of a word.
| What drives the bill | Why |
|---|---|
| The model you pick | The careful models cost several times what the fast ones do (Anthropic pricing, OpenAI pricing) |
| How much you send each time | The whole prompt is billed on every call, including a long document you attach to each of four hundred rows |
| How much it writes back | Output tokens cost more than input tokens |
| How many times the loop runs | A mistake in a loop repeats at machine speed; test on five rows before you run five thousand |
For a few hundred short rows on a fast model, the bill is usually a few cents to a few dollars. Set a spending limit in the vendor's console before you start. Watch free tiers: Google's free Gemini API tier may use what you send to improve its products, and the paid tier does not (Gemini API pricing).
Do you need it? Usually not.
| Your job | Use | Why |
|---|---|---|
| One document, one question | The chat | Nothing to set up, and you read the answer as it arrives |
| The same job every week on new material | A project, a GPT or a Gem | The files and instructions are saved once |
| The same prompt on a timer | A Grok automation, or scheduled tasks where your plan has them | The vendor runs it and keeps each result; no key to look after |
| Hundreds of rows or files, the same instruction for each | The API | Only a loop can do it, worded identically every time |
| An answer that has to land in a spreadsheet column | The API | A script can demand a fixed shape and put it where it belongs |
| A check that has to run on every single reply | The API | A script can refuse an answer; a chat window cannot |
If your job is in the top three rows, stay where you are. The API costs you a key to look after, a script to maintain and a bill to watch.
What it is not
- Not a way around the data rules. A script sends your text to the same vendor the chat does. Nothing sensitive goes to a personal account, and a work account only as your organization's rules allow.
- Not the chat features. No saved projects, no Gems, no memory of last week. Each request carries everything the model needs, or the model does not have it.
- Not a smarter model. The same models, the same mistakes. What you gain is control over the prompt, the loop and the checks.
- Not only for programmers. A short script is within reach of anyone who can follow a quickstart, and a chatbot will help you write it.
Where it goes from here
The Advanced path builds on this. Pipelines puts the model in a chain of fixed steps with a check after it. Tools and function calling shows how a model asks your code to run something. Skills files packages a procedure the model loads on demand, and Agents puts the model in a loop with tools. Coding sessions covers working with a coding agent that writes the script for you.
Vendor facts checked ; re-verify before relying on them.