github pydantic/pydantic-ai v2.40.0
v2.40.0 (2026-09-04)

2 hours ago

What's Changed

🚀 Features

  • Add pydantic_ai.prices.update_in_background() by @adtyavrdhn in #4841
  • Handle barge-in in the session: handle_barge_in=True, interrupt(played_bytes=...), and played_audio_bytes by @DouweM in #7870
  • Add provider_factory to infer_realtime_model by @DouweM in #8106
  • Add @agent.on_event for registering event listeners on an Agent by @DouweM in #8101
  • Add respond= to RealtimeSession.send() and document that a text turn solicits a reply by @DouweM in #8110
  • Add RealtimeSession.enqueue() for out-of-band prompts from code driving the session by @DouweM in #8109

🐛 Bug Fixes

  • Map finish_reason on OpenAI Responses stream terminal events by @pydanty in #7916
  • Fix defer_loading reveal synthesis splitting a parallel batch's tool_result from its tool_use by @pydanty in #7879
  • fix(realtime): roll back user-turn state when an audio chunk is not bytes-like by @simpleqt in #7905
  • Let a capability cache derived state again, and refuse a collection the merge cannot rebuild by @DouweM in #8099
  • Make a capability's auto-assigned registry key look like the run-local handle it is by @DouweM in #8119
  • Stop sending reasoning to the dated gpt-realtime-2025-08-28 snapshot by @DouweM in #8103
  • Subscribe stream_audio() and stream_transcripts() views when they are called, not on first iteration by @DouweM in #8107
  • End the realtime audio and transcript views when a tool fails and nobody is iterating by @DouweM in #8108
  • Let a realtime tool hang up with ctx.realtime_session.close() instead of wedging itself by @DouweM in #8105
  • Fix the realtime "Speaking first" and relay examples, the interrupt(played_ms=) cancel race, and two provider tables by @DouweM in #8132

New Contributors

Full Changelog: v2.39.0...v2.40.0

Don't miss a new pydantic-ai release

NewReleases is sending notifications on new releases.