runtype-pydantic-ai
Send Pydantic AI agent runs to Runtype. Each run appears as a first-class execution: transcript, system prompt, model calls, tool calls with arguments and results, token usage, cache usage, cost, loop iterations, stop reason and sub-agents.
- Works with
pydantic-ai1.90+ and 2.x from one entry point. - Composes with Logfire and any OpenTelemetry setup. Your other exporters keep receiving the original spans, and only agent-run spans reach Runtype.
- Sends everything Runtype can show by default. Every content kind has its own off switch, and
content=Falsesends shape and cost only. Exception messages and stack traces never leave the process; a failed run reports the exception class name.
Install
pip install runtype-pydantic-ai
Quick start
Set RUNTYPE_API_KEY to a key with the TELEMETRY:WRITE scope and RUNTYPE_AGENT_ID to the Runtype
agent that owns the runs. Then add one call at startup:
import runtype_pydantic_ai
runtype_pydantic_ai.instrument()
Every Agent in the process is now traced. In a short-lived script, keep the handle and flush before
exit:
handle = runtype_pydantic_ai.instrument()
...
handle.force_flush()
With Logfire
Call instrument() after logfire.configure() and it joins Logfire's provider. Alternatively, pass
the processor in:
import logfire
import runtype_pydantic_ai
logfire.configure(additional_span_processors=[runtype_pydantic_ai.span_processor()])
logfire.instrument_pydantic_ai(include_content=True, version=5)
Use version=5 on pydantic-ai 1.x. The 1.x default, format 2, is still understood, but it reports
less.
With another OpenTelemetry provider
instrument() leaves a global non-Logfire provider alone and traces through a private one, because
prompt content would otherwise reach every exporter on it. To share a provider, pass it:
runtype_pydantic_ai.instrument(tracer_provider=provider)
Its other exporters then receive raw content, and redact does not apply to them. Use content=False
to keep content off every exporter.
If Agent.instrument_all() already ran, instrument() keeps those settings and joins the provider
they use, and raises if it cannot reach that provider. An agent with its own instrumentation, such as
Agent(instrument=True), traces to its own provider, so pass that provider too.
Several agents in one process
Map Pydantic AI agent names to Runtype agents, or pin a block of code to one:
runtype_pydantic_ai.instrument(agent_ids={"chat": "agent_a", "run": "agent_b"})
with runtype_pydantic_ai.runtype_agent("agent_c"):
await agent.run("...")
A sub-agent called from a tool stays a branch of the outer run, under the outer run's Runtype agent.
Every top-level run is its own Runtype execution, even when several share a web request's span. A run under such a span gets a new trace id in Runtype, so it will not match the id in your other backend.
One agent only
To trace a single agent rather than all of them:
handle = runtype_pydantic_ai.instrument()
Agent.instrument_all(False)
agent = Agent("openai:gpt-5-mini", capabilities=[runtype_pydantic_ai.capability(handle)])
Early 1.x releases have no public Instrumentation capability, and capability() says so. Use
Agent(instrument=handle.settings) there.
Content
from runtype_pydantic_ai import ContentOptions
runtype_pydantic_ai.instrument(content=False)
runtype_pydantic_ai.instrument(content=ContentOptions(tool_results=False, max_chars=16_384))
runtype_pydantic_ai.instrument(content=ContentOptions(redact=lambda value, attribute: scrub(value)))
Each switch also applies inside message lists. tool_arguments=False and tool_results=False remove
those payloads from tool call parts, system_instructions=False removes system messages, and
output_messages=False removes earlier assistant turns from gen_ai.input.messages.
redact receives the parsed value and the attribute name. Returning None, or raising, drops that one
attribute and keeps the span.
Values are capped to fit ingest's limits. Oversized message lists stay valid JSON: large parts become a marker, then the oldest turns are dropped and the newest kept.
Custom attributes
Attributes are allow-listed. To send your own, name their prefixes:
runtype_pydantic_ai.instrument(passthrough_attribute_prefixes=["myapp."])
Options
| Environment variable | Purpose |
|---|---|
RUNTYPE_API_KEY |
Runtype key with the TELEMETRY:WRITE scope. Required. |
RUNTYPE_AGENT_ID |
Default Runtype agent for runs. |
RUNTYPE_OTLP_URL |
Full trace URL. Defaults to https://api.runtype.com/v1/otel/v1/traces. |
Metadata
Release files for runtype-pydantic-ai 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| runtype_pydantic_ai-0.2.0.tar.gz | 22.8 kB | Without provenance | Details for runtype_pydantic_ai-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| runtype_pydantic_ai-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for runtype_pydantic_ai-0.2.0-py3-none-any.whl |
Total release size: 40.6 kB
Release files / runtype_pydantic_ai-0.2.0.tar.gz
| Download URL | runtype_pydantic_ai-0.2.0.tar.gz |
|---|---|
| Size | 22.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
489b12a7c8a8fc030f6d70663e790f26ad6cfa9800f820aa6e867ec60a35cae0
|
|
BLAKE2b-256 checksum How to use checksums |
e3fc611542722be205ed199af5f5a8546d003bc4a72b817a06bda97c33259a78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / runtype_pydantic_ai-0.2.0-py3-none-any.whl
| Download URL | runtype_pydantic_ai-0.2.0-py3-none-any.whl |
|---|---|
| Size | 17.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f0f991f67cb3f1e8c0ae5415a05bda2c05dbaf20c4c03a40cdacf454ab6bea7
|
|
BLAKE2b-256 checksum How to use checksums |
61fba82dad34ce523ab7f8710137f61419f8da0fe107ca39b83bf81b0ce9a394
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for runtype-pydantic-ai 0.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.