Pydantic AI
Use Morse's private, OpenAI-compatible API as the model of a Pydantic AI agent: set it up, pick a model, and check it works.
Give an OpenAIChatModel an OpenAICompatibleProvider with Morse's base URL and your key.
pip install "pydantic-ai-slim[openai]"import os
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai_compatible import OpenAICompatibleProvider
provider = OpenAICompatibleProvider(
"morse",
base_url="https://inference.trymorse.ai/v1",
api_key=os.environ["MORSE_API_KEY"],
)
agent = Agent(
OpenAIChatModel("moonshotai/kimi-k3.1-pro", provider=provider),
instructions="Answer in one sentence.",
)
result = agent.run_sync("What is a TEE?")
print(result.output)The provider's name, morse, labels the run in its message history and traces. Pydantic AI reads the part of the id before the slash to choose how it builds each request for that model's family.
Tools
A tool is a function on the agent. Pydantic AI sends it in tools and runs the calls the model returns.
@agent.tool_plain
def get_weather(city: str) -> str:
"""The weather now in a city."""
return f"It's raining in {city}."
print(agent.run_sync("Is it raining in Lisbon?").output)Streaming
async with agent.run_stream("Write a haiku about rain.") as result:
async for text in result.stream_text(delta=True):
print(text, end="", flush=True)Send Morse's own parameters
Put them in extra_body in the agent's model_settings.
agent = Agent(
OpenAIChatModel("z-ai/glm-5.3", provider=provider),
model_settings={"extra_body": {"provider": {"min_privacy": "tee"}}},
)