v2.9.0

pydantic/pydantic-aiv2.9.0Jul 11, 2026by dsfaccini

AI Summary

This release acknowledges a security advisory affecting AG-UI, introduces a new `/usage` CLI command for tracking tokens, adds support for GPT-5.6 models and reasoning mode, and exposes usage limits in `RunContext`. It also includes several bug fixes related to Anthropic Files API, `repr()` crashes, cancellation deadlocks, and output strategies.

Key Highlights

  • Acknowledges and backports security advisory GHSA-jpr8-2v3g-wgf9 to v1.107.1
  • Adds `/usage` slash command to CLI for cumulative token usage
  • Adds GPT-5.6 models and reasoning mode to OpenAI integration
  • Exposes `usage_limits` in `RunContext` for tools and capabilities
  • Fixes `repr()` crash on message parts and cancellation deadlock

New Features

  • /usage slash command in CLI
  • GPT-5.6 models and reasoning mode support
  • RunContext usage_limits exposure
  • Auto-enable Anthropic Files API beta when UploadedFile is present
  • Honor end_strategy='early' for NativeOutput, PromptedOutput, and image output

Full Release Notes

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

## What's Changed

### 🛡️ Security

A moderate advisory, **[GHSA-jpr8-2v3g-wgf9](https://github.com/pydantic/pydantic-ai/security/advisories/GHSA-jpr8-2v3g-wgf9)** (CWE-863), affecting the AG-UI `UIAdapter.sanitize_messages` dangling-tool-call strip, was fixed in **`2.5.0`** and backported to **`1.107.1`** on the v1 line. If you are on `2.5.0` or later you already have the fix; this note calls it out now that the advisory is public.

- **Affected**: `pydantic-ai` / `pydantic-ai-slim` `>= 2.0.0, < 2.5.0` (v2) and `>= 1.88.0, < 1.107.1` (v1)
- **Patched**: `2.5.0` (v2) and `1.107.1` (v1)
- **Not affected** if every sensitive tool uses `requires_approval=True` / `ApprovalRequiredToolset`, or if your tool handlers validate their arguments and enforce authorization themselves.

### 🚀 Features
* Add `/usage` slash command to `clai` CLI for cumulative token usage by @adtyavrdhn in https://github.com/pydantic/pydantic-ai/pull/6245
* feat(openai): add GPT-5.6 models and reasoning mode by @Wh1isper in https://github.com/pydantic/pydantic-ai/pull/6414
* feat(`RunContext`): expose the run's `usage_limits` to tools and capabilities by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6341
### 🐛 Bug Fixes
* Auto-enable Anthropic Files API beta when messages contain `UploadedFile` by @gaurav0107 in https://github.com/pydantic/pydantic-ai/pull/5815
* Fix `repr()` crash on message parts whose field `!=` returns a non-bool (#6415) by @hramezani in https://github.com/pydantic/pydantic-ai/pull/6421
* fix: mark non-crypto hashes with usedforsecurity=False (FIPS precaution) by @stef41 in https://github.com/pydantic/pydantic-ai/pull/5053
* Guard against id-less `MCPToolset` on the `DBOSAgent` wrapper path by @dsfaccini in https://github.com/pydantic/pydantic-ai/pull/6406
* fix: make nested `capture_run_messages` capture correctly (#1568) by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6345
* Fix cancellation deadlock when a wrapped model request or agent run survives cancellation by @0ywfe in https://github.com/pydantic/pydantic-ai/pull/6426
* Honor `end_strategy='early'` for `NativeOutput`, `PromptedOutput`, and image output by @DouweM in https://github.com/pydantic/pydantic-ai/pull/6427

## New Contributors
* @stef41 made their first contribution in https://github.com/pydantic/pydantic-ai/pull/5053
* @0ywfe made their first contribution in https://github.com/pydantic/pydantic-ai/pull/6426

**Full Changelog**: https://github.com/pydantic/pydantic-ai/compare/v2.8.0...v2.9.0