Skip to content

Pydantic AI

Pydantic AI’s OpenAIModel and AnthropicModel both accept a base_url — so pointing them at TapPass is one line. Every structured output, tool call, and retry is governed.

Terminal window
export OPENAI_BASE_URL=https://tappass.example.com/v1
export OPENAI_API_KEY=tp_...
from pydantic_ai import Agent
from pydantic import BaseModel
class Answer(BaseModel):
content: str
confidence: float
agent = Agent("openai:gpt-4o-mini", result_type=Answer)
result = agent.run_sync("What's the capital of Belgium?")
print(result.data.content, result.data.confidence)
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel
model = OpenAIModel(
"gpt-4o-mini",
base_url="https://tappass.example.com/v1",
api_key="tp_...",
)
agent = Agent(model, result_type=Answer)
from pydantic_ai.models.anthropic import AnthropicModel
model = AnthropicModel(
"claude-3-5-sonnet-20241022",
base_url="https://tappass.example.com",
api_key="tp_...",
)

Pydantic AI’s @agent.tool functions run in your process, but their invocations are logged in the audit trail — and you can gate them with tool_decision.rego server-side.

tappass-examples/pydantic-ai