For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
ModelsChatRankingsDocs
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
  • Overview
    • Quickstart
    • Principles
    • Models
    • Stripe Projects
    • FAQ
    • Report Feedback
  • Models & Routing
    • Model Fallbacks
    • Provider Selection
    • Auto Exacto
    • Private Models
  • Features
    • Workspaces
    • Presets
    • Response Caching
    • Tool Calling
    • Structured Outputs
    • Message Transforms
    • Zero Completion Insurance
    • ZDR
    • App Attribution
    • Service Tiers
    • Sovereign AI
    • Router Metadata
    • Input & Output Logging
      • For Providers
      • Frameworks and Integrations Overview
      • Awesome OpenRouter
      • Effect AI SDK
      • Arize
      • LangChain
      • LiveKit
      • Langfuse
      • Mastra
      • OpenAI SDK
      • Anthropic Agent SDK
      • PydanticAI
      • Replit
      • TanStack AI
      • Vercel AI SDK
      • Xcode
      • Zapier
      • Infisical
LogoLogo
ModelsChatRankingsDocs
On this page
  • Using PydanticAI
  • Installation
  • Configuration
Community

PydanticAI

Using OpenRouter with PydanticAI
Was this page helpful?
Previous

Replit

Using OpenRouter with Replit Agent and Replit Apps
Next
Built with

Using PydanticAI

PydanticAI provides a high-level interface for working with various LLM providers, including OpenRouter.

Installation

$pip install 'pydantic-ai-slim[openai]'

Configuration

You can use OpenRouter with PydanticAI through its OpenAI-compatible interface:

1from pydantic_ai import Agent
2from pydantic_ai.models.openai import OpenAIModel
3
4model = OpenAIModel(
5 "anthropic/claude-sonnet-4.6", # or any other OpenRouter model
6 base_url="https://openrouter.ai/api/v1",
7 api_key="sk-or-...",
8)
9
10agent = Agent(model)
11result = await agent.run("What is the meaning of life?")
12print(result)

For more details about using PydanticAI with OpenRouter, see the PydanticAI documentation.