# PydanticAI (/docs/sdk/pydantic-ai)

[PydanticAI](https://ai.pydantic.dev) agents run on OhMyGPT through its built-in `OpenAICompatibleProvider`. One provider object gives your agents every chat model in the catalog, with structured output and tools working as usual. The examples use `pydantic-ai-slim` 2.64.

## Install [#install]

```bash
pip install "pydantic-ai-slim[openai]"
```

## Create the model [#create-the-model]

```python title="ohmygpt.py"
import os

from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai_compatible import OpenAICompatibleProvider

provider = OpenAICompatibleProvider(
    "ohmygpt",
    base_url="https://api.ohmygpt.com/v1",
    api_key=os.environ["OHMYGPT_API_KEY"],
)
model = OpenAIChatModel("zhipu/glm-5.3-flash", provider=provider)
```

Pass any model ID from `GET /v1/models` as the first argument. For a free test run, use `"ohmygpt/mock"`: it answers every call, including tool calls, so each agent below runs end to end at no cost.

## Run an agent [#run-an-agent]

```python
from pydantic_ai import Agent

from ohmygpt import model

agent = Agent(model, instructions="Answer in one sentence.")
result = agent.run_sync("What is the capital of France?")
print(result.output)
print(result.usage)
```

```text
The capital of France is Paris.
RunUsage(input_tokens=25, output_tokens=38, requests=1)
```

## Structured output [#structured-output]

```python
from pydantic import BaseModel
from pydantic_ai import Agent

from ohmygpt import model


class City(BaseModel):
    name: str
    country: str


agent = Agent(model, output_type=City)
print(agent.run_sync("Tell me about Tokyo.").output)
```

```text
name='Tokyo' country='Japan'
```

PydanticAI gets the object through a tool call, so the model must support tool calling.

## Tools [#tools]

```python
from pydantic_ai import Agent

from ohmygpt import model

agent = Agent(model)


@agent.tool_plain
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"18°C and cloudy in {city}"


print(agent.run_sync("What is the weather in Paris?").output)
```

```text
The weather in Paris is currently **18°C and cloudy**.
```

The agent sends the tool result back and returns the model's final answer. On `ohmygpt/mock` the tool runs once with `city=""`.
