Try this first

Run this. It is the smallest useful program in the course.

If you are running a model locally, this works as written:

from openai import OpenAI

client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")

response = client.chat.completions.create(
    model="gemma4",
    messages=[{"role": "user", "content": "Say hello in one short sentence."}],
    max_tokens=100,
)

print(response)

If you are using OpenAI itself, delete the base_url line and use your real key and model
name. Nothing else changes. That is not a coincidence — Ollama deliberately copies OpenAI’s
shape, which is why one adapter will later cover both.

Note that we print response, not the text. We want to see the whole thing before we start
picking pieces out of it.

What came back

You did not get a string. You got an object, and the interesting part is that it has more in
it than the answer.

print(response.choices[0].message.content)   # the text
print(response.choices[0].finish_reason)     # why it stopped
print(response.usage)                        # what it cost

Three things matter to us, and they will matter for the rest of the course:

What Why you care
The text The answer
Why it stopped This becomes the entire control flow — Lesson 1.5
The usage How the bill is calculated — Module 7

Run it again with a longer question and watch usage change. You are looking at the meter.

The first thing that is not obvious

The reply is not simply a string, in any provider. It is a structure, because a reply can
contain more than words — it can contain a request to run a tool, and on some models it can
contain the model’s reasoning as well.

That is why we print the whole object first, and why the course never writes
response.choices[0].message.content without knowing what else might be in there.

Two parameters worth understanding now

model. Whichever you chose in Lesson 1.1. Nothing in this course depends on it.

max_tokens. A hard limit on how much the model may write in one reply. If the model hits
it, the reply is cut off mid-sentence — we handle that in Lesson 1.5. Keep it generous.

A reply is a structure, not a string. Look at the whole thing before you reach into it.

Try this before the next lesson

Ask for something long with max_tokens=20. Print the text and the finish reason together.

Look at exactly where the sentence stops. That ragged edge is what a truncated reply looks
like in production, and now you will recognise it.