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.1

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.1
File Size Uploaded
kitaru_pydantic_ai-0.3.1.tar.gz 16.3 kB Details

Built distribution (wheel)

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

Total release size: 31.4 kB

Release files / kitaru_pydantic_ai-0.3.1.tar.gz

Download URL kitaru_pydantic_ai-0.3.1.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c2914c5b2a7b669a3fe6f1dedb3beea55c4dd8ab04afa3a7cd56c57d90e42a55
BLAKE2b-256 checksum
How to use checksums
a3fad500f15b7d01366a750303436961e08993c92e50dae4390486d11cf770c4
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 Oct 8, 2026.

Transparency log

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

Download URL kitaru_pydantic_ai-0.3.1-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e2c2d06f3a2d12bd02d5deb278df4f92d70b12ce6aa1dbe8dbd54ab1447e872
BLAKE2b-256 checksum
How to use checksums
e4bf286acae7ff6998ca8d3e1919df1b319ab7c0e2c7194ea0966ea371c0af17
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 Oct 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

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