existential-birds avatar

Pydantic Ai Model Integration

This walks you through wiring up different LLM providers in PydanticAI using simple string formats like `openai:gpt-4o` or `anthropic:claude-sonnet-4-5`. The fallback model setup is the standout feature: chain multiple providers so if one hits rate limits or goes down, it automatically tries the next. You also get streaming for both plain text and structured Pydantic output, per-run model settings overrides, and usage tracking that shows token counts across requests. Useful when you're building something that needs to stay up despite API hiccups or when you want to route cheaper requests to mini models and save the expensive ones for complex work.

skills.sh installs
120
GitHub stars
87
last updated
Aug 21, 2026

Install

$ npx -y skills add existential-birds/beagle --skill pydantic-ai-model-integration --agent claude-code

Installs into .claude/skills of the current project.

Files

PydanticAI Model Integration

Provider Model Strings

Format: provider:model-name

from pydantic_ai import Agent

# OpenAI
Agent('openai:gpt-4o')
Agent('openai:gpt-4o-mini')
Agent('openai:o1-preview')

# Anthropic
Agent('anthropic:claude-sonnet-4-5')
Agent('anthropic:claude-haiku-4-5')

# Google (API Key)
Agent('google-gla:gemini-2.0-flash')
Agent('google-gla:gemini-2.0-pro')

# Google (Vertex AI)
Agent('google-vertex:gemini-2.0-flash')

# Groq
Agent('groq:llama-3.3-70b-versatile')
Agent('groq:mixtral-8x7b-32768')

# Mistral
Agent('mistral:mistral-large-latest')

# Other providers
Agent('cohere:command-r-plus')
Agent('bedrock:anthropic.claude-3-sonnet')

Model Settings

from pydantic_ai import Agent
from pydantic_ai.settings import ModelSettings

agent = Agent(
    'openai:gpt-4o',
    model_settings=ModelSettings(
        temperature=0.7,
        max_tokens=1000,
        top_p=0.9,
        timeout=30.0,  # Request timeout
    )
)

# Override per-run
result = await agent.run(
    'Generate creative text',
    model_settings=ModelSettings(temperature=1.0)
)

Fallback Models

Chain models for resilience:

Sponsors

Details

Repository
github.com/existential-birds/beagle
Categories
Backend & APIs, AI & Agent Building, Python
First seen
Jun 3, 2026

More from existential-birds/beagle

All 40
1mindverse avatarsecondme-referencemindverse/second-me-skillsSecondMe API 技术参考文档,供开发时查阅118skills.sh installs
2pedronauck avatartanstack-query-best-practicespedronauck/skillsTanStack Query (React Query) best practices for data fetching, caching, mutations, and server state management. Activate when building data-driven React applica117skills.sh installs
3anthropics avatarHook Developmentanthropics/claude-codeThis skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", 1skills.sh installs
4agentworkforce avatarusing-agent-relayagentworkforce/relayOnce you're inside an Agent Relay workspace as a registered participant or spawned worker, this is your operational playbook.0skills.sh installs
5ar9av avatarsection-writing-agentar9av/paperorchestraStep 4 of the PaperOrchestra pipeline (arXiv:2604.05018). ONE single multimodal LLM call that drafts the remaining paper sections (Abstract, Methodology, Experi0skills.sh installs
6awslabs avataraws-transformawslabs/agent-pluginsMigrate, modernize, and upgrade codebases to AWS. Transforms .NET Framework to .NET 8/10, mainframe COBOL to Java, VMware VMs to EC2, SQL Server to Aurora, and 0skills.sh installs