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.

See the PydanticAI adapter guide for the recording lifecycle, replay overrides, tool policies, payload handling, and failure behavior.

Licensed under Apache-2.0.

Metadata

Release files for kitaru-pydantic-ai 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kitaru-pydantic-ai 0.3.0
File Size Uploaded
kitaru_pydantic_ai-0.3.0.tar.gz 15.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kitaru-pydantic-ai 0.3.0
File Interpreter ABI Platform
kitaru_pydantic_ai-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.9 kB

Release files / kitaru_pydantic_ai-0.3.0.tar.gz

Download URL kitaru_pydantic_ai-0.3.0.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b1ceaa73ee2f8855d0e275e3488a2b94c1e63c6e49a7f4a60a04f712538c33ae
BLAKE2b-256 checksum
How to use checksums
8d847382523040395a048117722389fd337cf45f71b378615d85bb680fdb4f2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release files / kitaru_pydantic_ai-0.3.0-py3-none-any.whl

Download URL kitaru_pydantic_ai-0.3.0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f1a7c2104b7bbfe0eb70ec7b572af4d8530f9d06cbf502fe31e857a0f9b5e1c3
BLAKE2b-256 checksum
How to use checksums
41b20bb055200eb3f72fd72f7bdec2cd5eacf1ffc2e8f0df2a69684ba5339e29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 21, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.1

2 release files

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page