v2.51.0

pydantic/pydantic-aiv2.51.0Sep 25, 2026by DouweM

Upgrading?

AI Summary

Focuses on performance improvements, such as caching the agent graph and reducing overhead, while adding support for OpenAI GPT-Live and refining error handling for real-time sessions.

Key Highlights

  • Added OpenAI GPT-Live support with `OpenAILiveModel`.
  • Cache the agent graph to avoid rebuilding on every `Agent.run()`.
  • Reduce `RunContext` copying overhead in capability hooks.
  • Added `context_window_used` exposure on realtime sessions.

Breaking Changes

  • Match dated `gemini-3.8-live` ids and reject `google_affective_dialog` on specific versions.
  • Raise a `UserError` for a realtime `tool_choice` that forces a tool call.

New Features

  • Added `OpenAILiveModel` support.
  • Added `context_window_used` exposure on realtime sessions.
  • Cached the agent graph to improve performance.
  • Added `RealtimeSessionErrorEvent` for failed OpenAI realtime responses.

Full Release Notes

<!-- Release notes generated using configuration in .github/release.yml at 39328d5b0d4cce94d513b6afcd2b3191bd5708d5 -->

## What's Changed
### ⚠️ Compatibility Notes
* Match dated `gemini-3.8-live` ids, reject `google_affective_dialog` on Gemini 3.1 Flash Live and 3.8 Live at connect, and raise `RealtimeError` for Gemini Live close codes by @DouweM in https://github.com/pydantic/pydantic-ai/pull/8761
* Raise a `UserError` for a realtime `tool_choice` that forces a tool call on OpenAI, Azure OpenAI, and xAI by @DouweM in https://github.com/pydantic/pydantic-ai/pull/8755
### 🚀 Features
* Add OpenAI GPT-Live support with `OpenAILiveModel` by @DouweM in https://github.com/pydantic/pydantic-ai/pull/8390
* Expose `context_window_used` on realtime sessions, from GPT-Live's reported ratio or response usage by @DouweM in https://github.com/pydantic/pydantic-ai/pull/8803
### 🐛 Bug Fixes
* Reduce `RunContext` copying overhead in capability hooks by @Kludex in https://github.com/pydantic/pydantic-ai/pull/8775
* Keep `provider_details` on OpenAI Realtime tool-call responses and the response id on replies cut off by a drop or `close()` by @DouweM in https://github.com/pydantic/pydantic-ai/pull/8762
* Buffer text deltas in `CompletedStreamedResponse` replay by @Kludex in https://github.com/pydantic/pydantic-ai/pull/8799
* Resend a recent image with a typed Gemini Live turn, which doesn't see video frames by @DouweM in https://github.com/pydantic/pydantic-ai/pull/8756
* Cache the agent graph instead of rebuilding it on every `Agent.run()` by @Kludex in https://github.com/pydantic/pydantic-ai/pull/8658
* Stop spawning a task group when a toolset or capability fan-out has a single child by @Kludex in https://github.com/pydantic/pydantic-ai/pull/8774


**Full Changelog**: https://github.com/pydantic/pydantic-ai/compare/v2.50.0...v2.51.0

Related Repositories