OpenAI Agents SDKopenai-agents 0.22 · Python 3.10+
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
25 small wins to finish your pathNext lesson

Using a real model

Everything so far ran on a stand-in you wrote in lesson 3. Swapping in the real thing is one line, and nothing else in any program you have written changes.

The line

python
# in this course
support = Agent(name="Support", model=PretendModel(), tools=[lookup_order])

# on your own machine
support = Agent(name="Support", model="gpt-5", tools=[lookup_order])

A string instead of an object. The SDK builds the client for you and reads the key from the environment. There is no other change: the tools, the instructions, the handoffs, the guardrails and the sessions are all the same code.

Two things to set up

bash
pip install openai-agents
export OPENAI_API_KEY=your-key-here

Never put the key in the file. An environment variable keeps it out of your code and out of your repository.

Other providers

The SDK speaks to anything with an OpenAI-shaped API, which is most of them now, by pointing a client somewhere else.

python
from openai import AsyncOpenAI
from agents import OpenAIChatCompletionsModel

client = AsyncOpenAI(base_url="https://api.groq.com/openai/v1", api_key="...")
model = OpenAIChatCompletionsModel(model="llama-3.3-70b-versatile", openai_client=client)

Groq and Google both give away enough on a free tier to finish this course several times over, which makes them a good way to see a real model without a bill.

What changes when the model is real

  • It decides for itself. It will use tools you did not expect and skip ones you did, and the fix is the descriptions from lesson 2.
  • It is not repeatable. The same question can produce a different answer twice, which is why lesson 22 exists.
  • It costs per message. The whole conversation goes on every turn, which is why lesson 20 exists.
Try it here first
Run the file in the panel first. It prints what stays the same, which is everything except one line. That is the whole point of having built it against a stand-in.
Try it yourself
  • Get a free key from Groq and run lesson 4 against a real model.
  • Ask it something with no order id and see how it handles not knowing.
  • Turn tracing back on and read the run at platform.openai.com.

Slow is fine. Stopping is the only problem.