Menu
CoddyTech

Your First Model Call

Part of the Calling Models From Code section of Coddy's AI Engineering journey. Lesson 1 of 22.

A large language model (LLM) is a program that reads text and writes a reply. Companies run their models on servers, and your code reaches one through an API: you send a request, the server sends back the model's answer.

With the Anthropic Python SDK, a request is one call. It needs three things: model (which model answers), max_tokens (the longest reply you accept) and messages (the conversation so far, here one question).

response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=100,
    messages=[{"role": "user", "content": "What is the capital of France?"}],
)
print(response.content[0].text)

This prints The capital of France is Paris.

In these lessons, coddy_ai.py stands in for the real SDK. It answers from fixed rules, so every run prints the same thing and the tests can check it. Your code is the code you would ship: in production you write import anthropic and keep your key in the ANTHROPIC_API_KEY environment variable, never in the code.

challenge icon

Challenge

Easy

Write a program that sends a question to the model and prints its reply.

  1. The starter reads the question into question.
  2. Call client.messages.create with model="claude-opus-5-5", max_tokens=200 and one user message holding the question.
  3. Print Answer: followed by the reply text.

For example, for the input What is the capital of Italy? the program prints:

Answer: The capital of Italy is Rome.

Try it yourself

import coddy_ai as anthropic  # in production: import anthropic

client = anthropic.Anthropic()

question = input()

# Send the question to the model, then print "Answer: " and the reply
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Calling Models From Code

Practice on your own: Online Python compiler