What an API actually is
An API (Application Programming Interface) is how your own code talks to an AI model directly, instead of through the company's chat website. You send a request containing your text and get a response back, so you can build AI into your own app, script or product.
The core idea: instead of typing into a chat window, your code sends the same kind of request automatically. That is useful for anything that needs AI responses at scale or inside a workflow, such as summarising every support ticket as it arrives.
Basic concepts to know before starting
- API key. A private credential that identifies your account and authorises requests. Treat it like a password.
- Request and response. You send a structured message, usually JSON, containing your prompt. The API returns a structured response containing the model's answer.
- System and user messages. Many APIs let you give standing instructions (how the model should behave) separately from the user's actual question.
- Pricing by token. Most AI APIs charge for input and output tokens, not a flat fee, so cost grows with usage.
- Rate limits. Providers cap how many requests you can send per minute or day, which matters once you have many users.
What a request looks like
This is a provider-neutral sketch. Real field names, URLs and model names differ by provider, so always follow the provider's own quickstart:
key = read the API key from an environment variable
send a POST request to the provider's endpoint, with the key in the headers
body: the model name, a system instruction, and the user's message
read the answer from the JSON that comes back
Estimating cost before you build
Because you pay per token, you can estimate in advance. As a worked example with made-up prices (check your provider's real ones): if input costs $1 per million tokens and output costs $4 per million, a request with 2,000 input tokens and 500 output tokens costs about $0.002 plus $0.002, or roughly $0.004. A thousand such requests is about $4. The arithmetic is simple, but the real numbers can differ a lot by model, so check the price list.
A simple starting workflow
- Sign up for API access and generate a key.
- Read the provider's quickstart, which usually has a working example in several languages.
- Send one simple test request to confirm your setup works before building anything complex.
- Add error handling. Networks and services occasionally fail, so retry with a short, growing delay instead of hammering the service.
- Set a spending limit and watch your usage.
Common first-project mistakes
- Exposing the key. Hardcoding a key in code that is shared, put in a public repository, or sent to a user's browser is one of the most common and costly mistakes. Use environment variables or a secrets manager, and keep calls on your own server.
- No spending cap, so a bug or abuse runs up a large bill.
- Trusting the output blindly. Validate anything your code acts on, and don't send private user data without a reason (see Privacy & Data When Using AI).
Frequently asked
Do I need to know how to code to use an AI API?
Yes, at least basic programming knowledge in a language like Python or JavaScript — APIs are a developer tool, not a no-code interface, though some no-code platforms now offer AI integrations without direct coding.
Is using the API more expensive than a chat subscription?
It depends on usage volume — for light use, a chat subscription is often cheaper; for building an app serving many users, API pricing based on actual usage can be more cost-effective.
Can I use multiple AI providers' APIs in the same project?
Yes — many developers combine APIs from different providers to use each one's specific strengths, similar to the tool-combining approach covered in the Skilled track.
← Back Next: Fine-Tuning vs Prompting →