LLM103 · Working with LLM APIs
About Course
Learn to send requests to LLM APIs from Python, manage conversations, stream responses, handle errors and rate limits, and keep costs predictable.
Who it is for
Developers who know basic Python and want to integrate hosted or local language models into their own applications.
Prerequisites
LLM102 or equivalent Python experience, including JSON and HTTP requests.
What you will be able to do
- Build a chat request with system, user and assistant messages and parse the response and token usage
- Implement streaming output and retries with exponential backoff for rate-limit and server errors
- Estimate the monthly cost of an API-based feature from token counts and request volume
- Write a thin provider-agnostic wrapper that can switch between a hosted API and a local model
Lessons
- Lesson 1 · Anatomy of an LLM API request
- Lesson 2 · Streaming, errors, retries and rate limits
- Lesson 3 · Cost, conversations and provider choice
- Lesson 4 · Lab and assignment
Lab: A reusable LLM client with retries and cost tracking
You will build a small Python client that sends chat requests, streams answers, retries on temporary errors and logs token usage for each request. You will run the same code against a hosted free-tier API and a local model served by Ollama through its OpenAI-compatible endpoint.
Free tools: Google Colab or VS Code, the Gemini API free tier from Google AI Studio, and Ollama with a small open model on your computer
Assessed assignment
Use your client to build a command-line "reply drafter" for a small HVAC company: it reads a customer email from a file, sends it with a system message describing tone and business hours, and prints a draft reply. Support a multi-turn mode that keeps conversation history within a token budget. Include a cost estimate for 500 emails per month based on your logged usage and the provider's current published prices, and explain how you would switch to the local model.
| Criterion | Weight | What excellent work looks like |
|---|---|---|
| Working integration | 30% | The drafter runs against at least one provider, produces sensible drafts and handles a missing key or network failure gracefully. |
| Reliability features | 25% | Retries with backoff, timeouts and streaming are implemented correctly and only retry errors that are safe to retry. |
| Conversation and token management | 20% | History is trimmed or summarized to stay within a stated budget, and the approach is explained. |
| Cost analysis | 25% | The monthly estimate uses real logged token counts, current prices with the date checked, and a clear formula. |
Portfolio piece
A reusable Python LLM client and a reply-drafter tool with usage logs and a documented monthly cost estimate.
Next step
Continue with LLM104 · Prompt Design and Structured Outputs for Developers · 6 hours · $42.00
Course Content
LLM103 · Working with LLM APIs (6 h)
-
Lesson 1 · Anatomy of an LLM API request
-
Lesson 2 · Streaming, errors, retries and rate limits
-
Lesson 3 · Cost, conversations and provider choice
-
Lesson 4 · Lab and assignment
-
LLM103 Assessment · Working with LLM APIs
