Using PydanticAI
PydanticAI provides a high-level interface for working with various LLM providers, including OpenRouter.Installation
Configuration
You can use OpenRouter with PydanticAI through its OpenAI-compatible interface:Output
print(result) prints the whole run result object that wraps this text. To print just the answer, print the result’s text attribute: result.output in current PydanticAI releases, result.data in older ones.
For more details about using PydanticAI with OpenRouter, see the PydanticAI documentation.