0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
27 small wins to finish your pathNext lesson →

Swapping in a real model

A real model is the one line that replaces ShopModel(), so the desk calls OpenAI instead of the stand-in.

Last updated: 28 Sep, 2026 · openai-agents 0.22.3

Every lesson so far ran on the ShopModel stand-in from Model: a stand-in you can run without a key, which needs no API key. To go live you change one thing: the agent's model. This program needs OPENAI_API_KEY set, so it is shown here, not run, and carries no captured output.

The one line that changes

On the capstone desk, model=ShopModel() becomes a model id string. The SDK reads OPENAI_API_KEY from the environment.

python
# before: the deterministic stand-in
desk = Agent(name="Shop desk", instructions="...",
             tools=[lookup_order], model=ShopModel())

# after: a real OpenAI model
desk = Agent(name="Shop desk", instructions="...",
             tools=[lookup_order], model="gpt-4.1")

The explicit form with OpenAIResponsesModel

A model id is the short way. For full control you build the model object yourself and pass your own client.

python
from agents import OpenAIResponsesModel
from openai import AsyncOpenAI

model = OpenAIResponsesModel(model="gpt-4.1",
                             openai_client=AsyncOpenAI())  # reads OPENAI_API_KEY
desk = Agent(name="Shop desk", instructions="...",
             tools=[lookup_order], model=model)

The desk on a real model

The full program with the real model. It needs a key, so it is not run here and has no output.

python
from agents import Agent, Runner, function_tool, set_tracing_disabled
set_tracing_disabled(True)

@function_tool
def lookup_order(order_id: str) -> str:
    "Look up an order by its id."
    return f"Order {order_id}: shipped on 3 March, arriving 7 March."

# The one change from the capstone: a real model id instead of ShopModel().
# Needs OPENAI_API_KEY in the environment; the SDK reads it for you.
desk = Agent(
    name="Shop desk",
    instructions="Help shoppers with their orders.",
    tools=[lookup_order],
    model="gpt-4.1",   # was model=ShopModel()
)

result = Runner.run_sync(desk, "Where is my order A17?")
print(result.final_output)

What changes and what stays

  • Only the model line changes; the tool, the handoff, the guardrail, and the session are all untouched.
  • The answer now comes from the model's own words, not the stand-in's fixed rules, so it varies run to run.
  • The key is read from OPENAI_API_KEY; without it the run raises an authentication error.

Stand-in vs real model

ModelWhat you get
ShopModel()Deterministic replies, no key, free, same output every run
model="gpt-4.1"Real answers, needs OPENAI_API_KEY, billed, output varies

When to move off the stand-in

  • The desk is wired and tested against the stand-in and you want real language in the replies.
  • You are ready to send real requests and pay per call.
Watch out. With no OPENAI_API_KEY the real-model run raises an authentication error, not a blank reply. Set the key in the environment before you run it.
Try it yourself
  • Set OPENAI_API_KEY and run the program against gpt-4.1.
  • Change the id to a smaller model such as gpt-4.1-mini and compare the reply.
  • Switch to the OpenAIResponsesModel form and confirm the desk behaves the same.

Every expert started right here.