> ## Documentation Index
> Fetch the complete documentation index at: https://docs.scitix.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Pydantic AI

> Learn how to use Pydantic AI with ScitiX Model Inference to build typed Python agents with tool calling support.

[Pydantic AI](https://github.com/pydantic/pydantic-ai) is a Python agent framework from the Pydantic team, with typed structured outputs and tool calling. Its OpenAI model class takes a custom provider, so you can point it at the ScitiX Model Inference API.

Default model here is `glm-5.2`; see the [Models](https://console.scitix.ai/model-inference/models) page for the full list and pricing.

## Configure

Create an API key on the ScitiX [API Keys](https://console.scitix.ai/model-inference/api_keys) page and export it:

```bash theme={null}
export SCITIX_API_KEY="<Your API Key>"
```

Build an `OpenAIChatModel` with an `OpenAIProvider` whose `base_url` is the ScitiX endpoint:

```python theme={null}
import os
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIChatModel
from pydantic_ai.providers.openai import OpenAIProvider

model = OpenAIChatModel(
    "glm-5.2",
    provider=OpenAIProvider(
        base_url="https://api.scitix.ai/model-api/v1",
        api_key=os.environ["SCITIX_API_KEY"],
    ),
)
agent = Agent(model)
```

| Field                        | Description                                                                                                               |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `OpenAIChatModel("<id>")`    | ScitiX model ID, e.g. `glm-5.2`. Class name is `OpenAIChatModel` in Pydantic AI 2.x; older 1.x used `OpenAIModel`.        |
| `OpenAIProvider(base_url=…)` | ScitiX OpenAI-compatible endpoint: `https://api.scitix.ai/model-api/v1`. The OpenAI provider appends `/chat/completions`. |
| `OpenAIProvider(api_key=…)`  | Your ScitiX API key, read from the environment                                                                            |

The class name is version-sensitive. Import the one that matches your installed version.

Choose a model with native tool calling for Pydantic AI's tool/structured-output features.

## Verify

Run a prompt — a normal reply confirms the connection (verified on **Pydantic AI 2.27.1**):

```python theme={null}
result = agent.run_sync("In one short sentence, which model are you?")
print(result.output)
# → a normal completion from ScitiX, e.g. "I am GLM, a large language model…"
```

A model's self-identification is unreliable; it may name a different family. Routing is set by the model ID you pass, and the ScitiX endpoint returns the requested model.
