PydanticAI
Typed Python agent development on TheRouter.ai
PydanticAI can call TheRouter.ai through its OpenAI model class, giving typed tool and schema workflows across many providers.
Overview
This page mirrors the OpenRouter workflow and adapts it for TheRouter.ai. Use TheRouter.ai as your OpenAI-compatible endpoint and keep model IDs in `provider/model` format.
Installation
Install the required SDKs and keep your TheRouter.ai key in environment variables.
install.sh
pip install "pydantic-ai-slim[openai]"Configuration
Set TheRouter.ai base URL overrides and pass your API key. Add attribution headers when your app should appear in rankings.
TypeScript
const note = "Use OpenAI-compatible clients with https://api.therouter.ai/v1";Caveats
Integration note
Strict schema validation can surface model differences quickly; keep explicit response models and fallback strategies.
For production rollouts, pin SDK versions and validate model compatibility in staging before broad rollout.