Building with LLM APIs flashcards
Call AI models from your own code: requests, tools, JSON, cost and safety.
What is an , in one plain sentence?
A doorway that lets one program ask another to do a job and get the result back, like a weather app asking a weather service for today's forecast.
Tap to turn over. Swipe right if you know it, left to see it again.
What you will learn
Start from zero
- APIs in plain words4 cards
- Keys and money3 cards
- Key words4 cards
Core basics
- First calls4 cards
- Tokens and cost3 cards
- Keys and safety3 cards
- Errors, retries and streaming4 cards
- Choosing models4 cards
Next steps
- Structured output2 cards
- Tool use3 cards
- Saving cost4 cards
- Files and images2 cards
- Reliability3 cards
- Testing4 cards
Go deeper
- Security4 cards
- Cost control2 cards
- Latency2 cards
- Context engineering2 cards
- Production design4 cards
- Privacy and data2 cards
- Quality at scale2 cards
Final test and certificate
10 questions drawn fresh from the whole topic, about 15 minutes. Sign in, score 80% or more and get a free certificate with your name and a public check link anyone can open, such as an employer or a teacher. Not signed in? Try a practice test from the cards.
Take the final testAbout these cards
- Reviewed 26 October 2026
- CoversClaude Messages API (anthropic-version 2026-10-21)OpenAI Responses APIGemini APIanthropic Python SDKPython 3.13
Checked against
Building with LLM APIs at a glance
An LLM API lets your own app send text to an AI model over the internet and get its answer back, so you can build AI into any product.
A restaurant waiter: your app hands the order (the request) to the waiter, the kitchen (the model) cooks, and the waiter brings back the dish (the response). You never enter the kitchen.
Words you will meet
- API
- A doorway that lets one program ask another program to do something
- API key
- A secret password that proves the request comes from your account
- Request
- The message your code sends: which model, what text, which settings
- Response
- What comes back: the answer plus facts like how many tokens were used
- Token
- A small piece of text; you pay per token in and out
- Model
- The AI brain you pick, from small and fast to large and smart
- JSON
- A neat text format for data that programs can read easily
- Rate limit
- The most requests or tokens you may send per minute
The steps
- 1. Start from zero (11 cards): What an LLM API is, keys, tokens and cost, and the words you need before Core basics.
- 2. Core basics (18 cards): First calls, roles, tokens, safe keys, raw HTTP, errors, streaming and model choice.
- 3. Next steps (18 cards): Structured output, tool use, caching, batching, files, reliability and testing.
- 4. Go deeper (18 cards): Security, cost control, latency, context engineering, production design and privacy.
All 11 cards in Start from zero
- What is an API, in one plain sentence?
- A doorway that lets one program ask another to do a job and get the result back, like a weather app asking a weather service for today's forecast.
- What is an LLM API?
- A service where your code sends text to a large language model and gets its reply, instead of a person typing into a chat window. The same models, but inside your own app.
- Why build with the API instead of just using a chat app?
- Code can run the same task a thousand times, feed in your own data, save results in your database and fit AI into your app's screens, all without anyone copying and pasting.
- What travels in a request and a response?
- The request says which model, your instructions and text, and settings like the longest allowed answer. The response brings the answer text plus how many tokens it used and why it stopped.
- What is an API key, and how should you treat it?
- A long secret string that proves requests come from your account, and every request is billed to you. Treat it like a bank PIN: never share it, never post it online, never put it inside a website or phone app.
- How are you charged for using an LLM API?
- Per token: a price per million tokens you send, and a higher price per million tokens the model writes. A token is roughly three quarters of an English word, so 1,000 words is about 1,300 tokens.
- Big model or small model: what is the trade-off?
- Bigger models reason better but are slower and cost more per token. Small models are quick and cheap for simple jobs such as sorting emails. Good apps pick the smallest model that does the job well.
- What is JSON, and why do AI apps care?
- A tidy text format for data, like
{"name": "Arjun", "age": 31}. Programs read it easily, so apps ask the model to answer in JSON when the answer must be saved or used by code. - What is a rate limit?
- The most requests or tokens your account may send per minute. Go over and the service replies "too many requests" and you wait a moment and try again.
- What does "the model has no memory between requests" mean?
- Each request starts fresh. To hold a conversation, your app sends the earlier messages again every time. The chat apps you know do this for you behind the scenes.
- What do you need before the Core basics level?
- A little Python (variables, functions, lists, dictionaries), a terminal, and an account with an AI provider to create a key. You will be able to write a working AI feature by the end.
Building with LLM APIs cheatsheet
Request essentials
modelModel id from configmax_tokensHard cap on answer lengthsystemStanding rules for the chatmessagesAlternating user and assistant turnstemperatureSampling knob; removed on some newer API versionsstop_sequencesStrings that end the answerstream=True / .stream()Send text as it is written
Reading the response
content[0].textAnswer textstop_reasonend_turn, max_tokens, tool_use, refusalusage.input_tokensTokens you sentusage.output_tokensTokens the model wroterequest-id headerQuote it to support
Errors
400Bad request: fix it, do not retry401 / 403Key or permission problem429Rate limited: back off and retry500Server error: retry with backoff529Overloaded: retry laterretry-afterSeconds to wait before retrying
Tools and JSON
tools=[{name, description, input_schema}]Declare functionstool_use blockModel asks to run a tooltool_result + tool_use_idYour code returns the outputoutput_config.format json_schemaForce replies to match a schemaadditionalProperties: falseNo surprise fields
Saving money
cache_control: ephemeralCache a stable prompt prefixbatch APIAbout half price, results within 24 hcount tokens firstKnow size before sendingsmaller model firstEscalate only when neededsummarise old turnsKeep long chats cheap