Two request shapes side by side
Compare where the system text sits in each body.
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
OpenAI-compatible request body:
{
"model": "your-model-name",
"messages": [
{
"role": "system",
"content": "You are a concise tutor."
},
{
"role": "user",
"content": "What is a list comprehension?"
}
]
}
Anthropic Messages request body:
{
"model": "your-model-name",
"max_tokens": 200,
"system": "You are a concise tutor.",
"messages": [
{
"role": "user",
"content": "What is a list comprehension?"
}
]
}