A fake client and a chat loop
The fake has the same method path as an OpenAI-style SDK. Change the scripted replies and run again.
Calling a language model is sending a list of messages (system, user, assistant) as JSON over HTTP and reading text back. Different providers use slightly different shapes, so you hide the call behind a small function and test everything else with a fake client.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write build_messages(system, history, user) that returns the full list with the system message first and the new user message last.
Write openai_text(response) and anthropic_text(response) that pull the answer text out of each shape (as plain dictionaries).
Write load_key(env, name) that returns the key from a dictionary of settings, or raises RuntimeError with a helpful message.
Explain it without notes
Why must you send the whole conversation on every call?
What are the main differences between the OpenAI-compatible and Anthropic Messages request and response shapes?
How do you make code that calls an LLM testable?
A model reply arrives but your JSON parser fails on it. Before blaming the prompt, what do you check in the response object?
Expected output
system: Be concise.
user: What is a list comprehension?
assistant: A list comprehension builds a list in one line.
user: Can it filter?
assistant: Yes: add an if at the end.
calls made: 2
messages sent on call 2: 4