Skip to main content

Kitaru PydanticAI adapter

Record and replay PydanticAI agent runs with Kitaru.

Install

uv add "kitaru-pydantic-ai[openai]"

Install kitaru-pydantic-ai without the extra when your project provides another PydanticAI model implementation.

Use

import uuid

from pydantic_ai import Agent

from kitaru_pydantic_ai import KitaruAgent

agent = KitaruAgent(
    Agent("openai:gpt-5-nano"),
    agent_id=uuid.UUID("018f0000-0000-7000-8000-000000000100"),
)
result = agent.run_sync("Hello")
print(result.output)

The adapter accepts the same run arguments as the wrapped PydanticAI agent. Kitaru workers provide task, replay, and authentication context through the standard task environment.

Model costs

The adapter estimates each completed LLM call's USD cost from its resolved model, provider, token usage, and request time. Pricing comes from the bundled genai-prices catalog. Unsupported models and providers leave the cost unset without failing the agent run. The recorded node attributes describe whether pricing was estimated or unavailable.

Supply cost_calculator for private models, negotiated rates, or provider billing rules. The callback receives a PydanticAIUsageSummary and returns a non-negative USD amount. A supplied callback takes priority over the bundled catalog.

from decimal import Decimal

from kitaru_pydantic_ai import KitaruAgent, PydanticAIUsageSummary


def calculate_cost(usage: PydanticAIUsageSummary) -> Decimal:
    uncached_input = usage.input_tokens - usage.cached_input_tokens
    return (
        Decimal(uncached_input) * Decimal("0.000002")
        + Decimal(usage.cached_input_tokens) * Decimal("0.0000002")
        + Decimal(usage.output_tokens) * Decimal("0.000008")
    )


agent = KitaruAgent(pydantic_agent, cost_calculator=calculate_cost)

Set estimate_costs=False when cost estimation should be disabled. This does not disable a supplied cost_calculator.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kitaru_pydantic_ai-0.1.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kitaru_pydantic_ai-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file kitaru_pydantic_ai-0.1.0.tar.gz.

File metadata

  • Download URL: kitaru_pydantic_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kitaru_pydantic_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0308b89ee58fecac2c2d91d5a430118734fd126621b298fbc98586552c01e4e8
MD5 404d215082cd3212d4743c9ace58d593
BLAKE2b-256 915b8d3709d88f682a44fcd10836f5075db68fdb0cdcf5fecc3dec6a96c72f67

See more details on using hashes here.

Provenance

The following attestation bundles were made for kitaru_pydantic_ai-0.1.0.tar.gz:

Publisher: release-plugins.yml on zenml-io/kitaru

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kitaru_pydantic_ai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for kitaru_pydantic_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3e8bfb9206544f3c1dd72eba6eb7324c76c737ebb52e074c1a32412e6059dbb
MD5 b8e4b52f82b151e0179ba40a88b041f6
BLAKE2b-256 e2d02dacb2d34ceceaaf36c6f8188eb9320e234b258e294beaf12daf5c9427da

See more details on using hashes here.

Provenance

The following attestation bundles were made for kitaru_pydantic_ai-0.1.0-py3-none-any.whl:

Publisher: release-plugins.yml on zenml-io/kitaru

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page