Agents sdk, use a diff model

Im playing around with the new agents SDK, but I cant find a way to use a diff model that is not openai.
For example I want to use claude or gemini, can I do that, or am I locked in?

1 Like

It’s all a bit messy but the best post I found with a solution is here:

from openai import AsyncOpenAI
from agents import OpenAIChatCompletionsModel,Agent,Runner
from agents.model_settings import ModelSettings
from agents import set_default_openai_client, set_tracing_disabled

external_client = AsyncOpenAI(
    base_url = 'http://localhost:11434/v1',
    api_key='ollama', # required, but unused
)
set_default_openai_client(external_client)
set_tracing_disabled(True)


agent = Agent(
    name="Assistant", 
    instructions="You are a helpful assistant",
    model=OpenAIChatCompletionsModel(
        model="gemma3:12b",
        openai_client=external_client,
    )
    )

result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
print(result.final_output)

# Code within the code,
# Functions calling themselves,
# Infinite loop's dance.

The AsyncOpenAI module can be given any URL and key.

1 Like