Skip to main content

Installation

Usage

How It Works

track_pydantic_ai patches Agent.run and Agent.run_sync to intercept LLM calls. After each agent run, it:
  1. Extracts the model name from the agent’s model configuration
  2. Extracts token counts from RunResult.usage() (RunUsage object)
  3. Infers the provider from the model string prefix
  4. Sends the usage event to MeshAI (buffered, non-blocking)
Works with all Pydantic AI-supported models: OpenAI, Anthropic, Gemini, Groq, Mistral, and others.

Alternative: Proxy (Zero-Code)

If your Pydantic AI agents use OpenAI or Anthropic, route through the proxy: