Request in, response out
An AI API is a web service: your code sends a request with a model name and messages, and receives a response with the generated output. Official SDKs (software development kits) for Python, JavaScript and other languages wrap these requests for you.
Tokens
Models read and write tokens, chunks of text roughly ¾ of an English word on average. Pricing is per million tokens, usually with different rates for input (what you send) and output (what the model writes). Long documents and long chat histories cost more because every request includes them as input.
Context window
Each model has a context window: the maximum tokens it can consider at once, including your instructions, the conversation and its reply. Large windows hold long documents but cost more to fill.
Choosing a model
Providers offer families of models, from small and fast to large and capable, and many offer “reasoning” models that think longer on hard problems. A good approach:
- Start with a capable model to prove the feature works.
- Build a test set.
- Try smaller, cheaper models and keep the cheapest that passes.
Model names, limits and prices change frequently. Always check the provider’s current documentation and pricing page rather than old blog posts.
Statelessness
APIs do not remember previous requests by default. To continue a conversation, your code sends the relevant history again (or uses a provider feature that stores conversation state).
Practice task
Open the pricing and model pages for two AI providers. For one small and one large model at each, note the input price, output price and context window, and estimate the cost of summarizing a 5,000-word document.