Put AI inside your app: AI APIs
How apps call models like GPT, Claude and Gemini through an API: keys, costs, system prompts, streaming and keeping it safe.
Chat app vs API
When you use ChatGPT or Claude in the app, a person types and reads. When your own app needs AI (summarise a form, draft a reply, tag a support ticket), it talks to the model through an API instead: your code sends a request with instructions and text, and gets text back.
OpenAI, Anthropic and Google each offer APIs for their models, usually through an SDK (a ready-made code library) for JavaScript or Python. Platforms like the Vercel AI SDK or OpenRouter let one app switch between providers.
The parts of a request
- Model: which model to use. Bigger models are smarter and slower and cost more; smaller ones are cheap and fast.
- System prompt: your app's standing instructions ('You tag support emails as billing, bug or other. Reply with one word.').
- Messages: the user's text and any context you add (the email, the product info).
- Settings: maximum length of the reply, and sometimes temperature (how varied the wording is).
- Tools or structured output: ask for JSON in a fixed shape so your code can use the answer reliably.
Costs and limits
APIs charge per token, counted separately for what you send (input) and what you get back (output). Long documents and long replies cost more. Providers also have rate limits: how many requests or tokens per minute your key may use.
Keep costs predictable: set a spending limit in the provider's dashboard, cap reply length, send only the text the task needs, use a smaller model where it works, and cache answers you reuse.
Keep the key on the server
An AI API key is a credit card for your account. It must only live on the server (an API route, a server action or an edge function), stored as an environment variable. The browser calls your server; your server calls the AI. Never put the key in front-end code, where anyone can copy it.
Also check who is allowed to call your AI route (signed-in users only? how many times per day?) so strangers can't run up your bill.
Make it good: test with real examples
Collect 10 to 20 real examples with the answers you'd want, and run them every time you change the prompt or model. That small test set is called an eval. It turns 'seems better?' into a score.
Stream long replies (show words as they arrive) so the app feels fast, and show the user that AI wrote it, with a way to edit or report a bad answer.
Key terms
- API
- An agreed way for one piece of software to ask another for something.
- SDK
- A ready-made code library that makes a service's API easy to use from your language.
- API key
- A secret code that identifies your app to a service and is often tied to billing.
- System prompt
- Hidden standing instructions that shape every answer an AI app gives.
- Token
- A small chunk of text (a word, part of a word or punctuation) that models read and count usage in.
- Rate limit
- The most requests or tokens a key may use in a period, such as per minute.
- Streaming
- Showing an AI reply word by word as it's generated instead of waiting for the end.
- Structured output
- Asking a model to answer in a fixed shape, like JSON, so code can read it reliably.
- Eval
- A set of real examples with expected answers, run to measure an AI feature's quality.
- Environment variable
- A setting or secret the app reads at run time, kept outside the code.
Try it
Design an AI feature on one page
- Pick one job for AI in an app you'd build (for example: tag incoming messages).
- Write the system prompt and the exact JSON shape you want back.
- Write five example inputs with the answers you'd want: your first eval.
- Ask a coding agent to build a server route that calls the model, keeps the key in an environment variable, and runs your five examples.
Ask an AI tutor about this guide
Copy a prompt into ChatGPT, Claude or Gemini to go deeper. Check what it tells you against the guide.
- Explain it like I'm 12
- Quiz me (5 questions, one at a time)
- Show me a real example for my situation
- What do beginners get wrong?
Knowledge check
Five questions. Get 4 right to earn the AI Integrator badge. You can retake it as often as you like.
Question 1 of 5
Finished the How software works guides? Take the How software works track test for ten mixed questions.
My notes
Write what clicked, what confused you, and what you want to try. Saved in this browser only.
Learn it live
Digital Builders University runs small live workshops where you build something real with an instructor beside you, starting with Vibe Coding 101.
See workshopsPractise it
- Build Challenge: AI FAQ helper on a website (Pro, 4 hours)
- Game: Error Detective (read real error messages and pick the fix)
- Game: Code Scramble (put the lines of a working program back in order)
Official sites
- OpenAI API docs (opens in a new tab)
- Claude API docs (opens in a new tab)
- Gemini API docs (opens in a new tab)
- Vercel AI SDK (opens in a new tab)
Last reviewed November 25, 2026. AI tools change fast; check each tool’s own site for current features, plans and prices.
