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

# Pydantic

> Using Nebius Token Factory models with Pydantic

Pydantic AI is a Python agent framework

[Pydantic docs](https://ai.pydantic.dev/)\
[Pydantic + Nebius AI docs](https://ai.pydantic.dev/models/openai/#nebius-ai-studio)

## Prerequisites

1. [Create an API key](https://tokenfactory.nebius.com/project/api-keys) to authorize requests to Nebius Token Factory.
2. Save the API key into a `NEBIUS_API_KEY` environment variable:

   ```shellscript theme={null}
   export NEBIUS_API_KEY="<API_key>"
   ```
3. Install the `pydantic` package:

   ```shellscript theme={null}
   pip install pydantic_ai
   ```

## Create an Agent Application

Simplest application.  `NEBIUS_API_KEY` will be inferred from env variables.

```python theme={null}
from pydantic_ai import Agent

agent = Agent('nebius:Qwen/Qwen3-32B-fast')
result = agent.run_sync('What is the capital of France?')
print(result.output)
#> The capital of France is Paris.
```

You can use also use the `NebiusProvider` class:

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

model = OpenAIChatModel(
    'Qwen/Qwen3-32B-fast',
    provider=NebiusProvider(api_key='your-nebius-api-key'),
)
agent = Agent(model)
result = agent.run_sync('What is the capital of France?')
print(result.output)
#> The capital of France is Paris.
```

## More Examples

View [more examples](https://github.com/nebius/token-factory-cookbook/blob/main/agents/README.md#pydantic-ai) in our cookbook
