Learn the mechanics of calling model APIs by doing — your first request, running open models locally with Ollama and Hugging Face, streaming, structured outputs, function calling, prompt caching, and managing tokens and cost. Every lesson is runnable Python.
Before you start
You will run real Python against a model API. You need Python 3.10+, the Anthropic SDK, and an API key from the Anthropic Console. The first lesson sets this up. The API mechanics are the same on every provider — this course uses Claude so the code is concrete.
Your First API Call
Install an SDK, set your key safely, and make a model call you understand line by line — the request shape, the message list, and how to read the response.
Hosted vs. Local: Hugging Face & Ollama
You do not have to call a paid API. Run open models on your own machine with Ollama, pull models from Hugging Face, and know when hosted beats local and vice versa.
Streaming Responses
Show text as it is generated instead of freezing on a spinner. Stream tokens from the API, accumulate the final message, and understand the event types you receive.
Structured Outputs (JSON Mode)
When your code has to consume the model’s answer, free text is a liability. Force valid JSON, define the shape, and validate it before anything downstream touches it.
Function Calling & Tool Use
Let the model call your code — look up data, hit an API, run a calculation — and use the result in its answer. Define a tool, run the request loop, and return the output.
Prompt Caching
When a big system prompt or document is reused across calls, caching it cuts cost and latency dramatically. Mark the reusable prefix and understand what actually gets cached.
Tokens, Cost & Context
Everything you send and receive is priced and bounded by tokens. Count them before you send, keep a conversation under the context window, and estimate what a call will cost.