Cheat sheet · Specialise
LLM APIs cheat sheet (OpenAI)
Opens with creditsA quick-revision book on building features with large language model APIs: tokens, prompts, streaming, structured output, tool calling, retrieval, caching, batching, cost, evals and security. Each edition shows the same ideas with one provider’s official Python SDK; model names come from a MODEL setting so the code outlives any one model.
Chapters
8 chapters · 56 concepts
1How LLM APIs workAn LLM API takes text (and sometimes images) in and returns generated text, billed by the token. These ideas shape every request you will write.6 concepts
- 1TokensModels read and write tokens: chunks of text that are often a word or part of one.
- 2Context windowThe maximum number of tokens a model can take in one request, counting the system prompt, the conversation history, tool definitions, documents and the output.
- 3The Responses APIOpenAI’s current main endpoint.
- 4Your first requestCreate a client (it reads the API key from an environment variable) and send a prompt.
- 5Reading token usageEvery response reports how many input and output tokens it used (and cached tokens, where relevant).
- 6Choosing a modelProviders offer tiers: large models for hard reasoning and coding, mid-size for most product work, small fast ones for classification and high volume.
6 in this chapterOpen this chapter2Prompts, roles and samplingHow you structure a request: who says what, which instructions persist, how history is kept, and which knobs change the style and length of the answer.8 concepts
- 1Messages and rolesA conversation is a list of turns, each with a role: the user, and the model (called
assistant, ormodelin Gemini). - 2System promptsStanding instructions that apply to the whole conversation: role, tone, rules, output format and context about the product.
- 3Keeping conversation stateEither resend the full history yourself each turn, or use a provider feature that keeps it for you where one exists.
- 4Clear, structured instructionsState the task, the audience, the constraints and the output format explicitly, and separate instructions from data with headings or tags such as
<document>. - 5Few-shot examplesIncluding a handful of example inputs and ideal outputs in the prompt so the model copies the pattern.
- 6Temperature and samplingTemperature controls randomness when picking the next token: low values give focused, repeatable answers, higher values more varied ones.
- 7Reasoning and effortReasoning models think before answering, using extra hidden output tokens.
- 8Output limits and stop reasonsYou cap output length, and each response says why it stopped: finished naturally, hit the limit, called a tool or was declined.
8 in this chapterOpen this chapter- 1Messages and rolesA conversation is a list of turns, each with a role: the user, and the model (called
- Streaming, structured output and imagesGetting output into a shape your product can use: streamed for chat interfaces, schema-checked JSON for code, and images as input when text is not enough.6 conceptsOpens with credits
- Tool calling and agentsTool calling lets the model ask your code to do things: look up an order, run a query, send an email. Your code runs the tool and sends the result back, in a loop, until the model answers.7 conceptsOpens with credits
- Embeddings and retrieval (RAG)Retrieval-augmented generation finds the most relevant pieces of your own data and puts them in the prompt, so answers are grounded in current, private information the model was never trained on.7 conceptsOpens with credits
- Cost, caching, batching and reliabilityWhat changes when real traffic arrives: repeated prompts should hit the cache, bulk jobs should go through batch APIs, and every call needs retries, timeouts and a budget.8 conceptsOpens with credits
- Evals and observabilityPrompts and models change behaviour in ways unit tests do not catch. Evals turn "it seems better" into a number, and tracing shows what actually happened in production.7 conceptsOpens with credits
- Security and safetyLLM features add new attack surface: text can carry instructions, output can carry payloads, and API keys are valuable. Design as if every input and output is untrusted.7 conceptsOpens with credits
- 9Glossary, A to ZEvery concept in the sheet and the smaller terms it uses, in one list.78 terms
About this sheet
Building on OpenAI, Anthropic and Gemini APIs: prompts, streaming, structured output, tools, RAG, caching, cost, evals and safety.
Related on Sefism
Picked from the other libraries by shared topics.
Roadmaps
See allBest practices
See all- Best Practices for Building LLM AppsHow to build LLM apps and agents that hold up in production: prompts, evals, prompt injection, tool permissions, cost, logging and privacy.
- Prompt Engineering Best PracticesHow to write prompts that work the same way on the hundredth input as on the first: clear instructions, structure, examples, reasoning, output control and testing.
- Best Practices for AI Coding AssistantsHow to get reliable code from AI coding assistants and agents: instruction files, task prompts, verification, review, security, dependencies and session hygiene.
Checklists
See all- RAG Production ChecklistA RAG production checklist: chunking, embeddings, hybrid search, reranking, per-user permissions, citations, evals, re-indexing and cost, with how to verify each check.
- LLM Evaluation ChecklistAn LLM evaluation checklist: success criteria, eval datasets, code and model graders, judge calibration, agent evals, safety tests and production monitoring, with how to verify each check.
- AI Feature Launch ChecklistAn AI feature launch checklist: use case fit, evals, UX for errors, disclosure, human override, abuse filters, rate limits, cost caps, prompt privacy, monitoring and rollback.
Project structures
See all- GenAI RAG app (FastAPI) project structureFor developers turning a "chat with your documents" demo into an app people can rely on. A FastAPI backend where every layer has a home: ingestion workers, retrieval, prompts as versioned files, model clients with fallbacks and cost caps, guards, evals that gate CI, and tracing, so a wrong answer can be traced to the step that caused it.
- AI agent with an MCP server project structureFor developers who want to give AI assistants safe access to their own data or API. A TypeScript MCP server built on the official SDK, organised by feature (tasks, projects) with each feature owning its tools, resources and prompts, served over stdio for local hosts and Streamable HTTP with OAuth for remote ones, plus a small agent and the evals that prove a model can use it.
- Machine learning project project structureFor students and analysts whose model works in a notebook and now needs to be reproducible, reviewable, served and watched. It starts from the Cookiecutter Data Science v2 layout (immutable raw data, numbered notebooks, a real Python package) and grows into versioned data with DVC, typed parameters, data validation with pandera, experiment tracking and a model registry with MLflow, a FastAPI prediction service, drift monitoring and, for a team, scheduled retraining, model cards, fairness checks and shadow deployment.
Career questions
See all- Which AI tools do employers expect junior developers to know in 2026?Employers rarely require a specific brand. They expect you to use an AI coding assistant well (in the editor and in the terminal), to review and test what it produces, to call an LLM API in a small feature, and to explain when you would not use AI. Pick one assistant, learn it properly, and show judgement in your projects.
- How do I use AI to become a better engineer instead of becoming dependent on it?Decide the job AI does before you open it. Use it as a tutor, reviewer and sparring partner that explains and challenges, not a vending machine that hands you finished code. Attempt first, ask second, and always be able to explain and defend what you ship.
- How do I start learning AI agents as a software engineer?Start with one LLM API and plain code: a loop that calls the model, lets it pick a tool, runs the tool and feeds the result back. Build one small agent that does a real task end to end, add evaluation and guardrails, and only then reach for a framework. Agents are software engineering first.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
- 1:1 Mentorship
- Fresh Graduate Mentorship
- Career Guidance
Brand deals, promos and partnerships: tauseeffayyaz@gmail.com