OpenAI Agents SDK
Run OpenAI Agents SDK agents on Morse's private, OpenAI-compatible API: set the base URL, pick a model, and check it works.
Give the Agents SDK an OpenAI client with Morse's base URL and your key, and turn its tracing off.
pip install openai-agentsimport os
from agents import Agent, OpenAIChatCompletionsModel, Runner, set_tracing_disabled
from openai import AsyncOpenAI
set_tracing_disabled(True)
client = AsyncOpenAI(
base_url="https://inference.trymorse.ai/v1",
api_key=os.environ["MORSE_API_KEY"],
)
agent = Agent(
name="Assistant",
instructions="Answer in one sentence.",
model=OpenAIChatCompletionsModel(model="moonshotai/kimi-k3.1-pro", openai_client=client),
)
result = Runner.run_sync(agent, "What is a TEE?")
print(result.final_output)Name a model by its id
In Python, set the client once and put openai/ before the Morse id. Without the prefix, the SDK reads the part before the slash as a provider and raises Unknown prefix.
from agents import set_default_openai_api, set_default_openai_client
set_default_openai_client(
AsyncOpenAI(base_url="https://inference.trymorse.ai/v1", api_key=os.environ["MORSE_API_KEY"]),
use_for_tracing=False,
)
set_default_openai_api("chat_completions")
agent = Agent(name="Assistant", model="openai/moonshotai/kimi-k3.1-pro")The SDK sends the id without the prefix. In TypeScript, name the Morse id as it is.
Tools
Function tools, handoffs, sessions, and guardrails work. The SDK sends each function tool in tools and runs the calls the model returns.
from agents import function_tool
@function_tool
def get_weather(city: str) -> str:
"""The weather now in a city."""
return f"It's raining in {city}."
agent = Agent(
name="Assistant",
model=OpenAIChatCompletionsModel(model="moonshotai/kimi-k3.1-pro", openai_client=client),
tools=[get_weather],
)
print(Runner.run_sync(agent, "Is it raining in Lisbon?").final_output)Morse refuses the SDK's hosted tools, such as web search and file search, since they run on OpenAI's servers.
Send Morse's own parameters
Put them in extra_body on the agent's ModelSettings.
from agents import ModelSettings
agent = Agent(
name="Assistant",
model=OpenAIChatCompletionsModel(model="z-ai/glm-5.3", openai_client=client),
model_settings=ModelSettings(extra_body={"provider": {"min_privacy": "tee"}}),
)The Responses API
Use OpenAIResponsesModel, and set store to False. Morse stores no response, so the SDK sends the whole conversation each turn.
from agents import ModelSettings, OpenAIResponsesModel
agent = Agent(
name="Assistant",
model=OpenAIResponsesModel(model="moonshotai/kimi-k3.1-pro", openai_client=client),
model_settings=ModelSettings(store=False),
)Don't pass previous_response_id or a conversation id to a run. See OpenAI Responses API for what Morse refuses.