Open
Description
Initial Checks
- I confirm that I'm using the latest version of Pydantic AI
- I confirm that I searched for my issue in https://github.com/pydantic/pydantic-ai/issues before opening this issue
Description
When manually passing a token limit to the agent that's too restrictive and causes the model run to fail, the error we raise is of the wrong type
from pydantic_ai import Agent
Agent("google-gla:gemini-2.5-pro-preview-05-06", model_settings=dict(max_tokens=5)).run_sync("write a haiku")
yields
UnexpectedModelBehavior: Content field missing from Gemini response, body: (...)
instead of UsageLimitExceeded
Example Code
from pydantic_ai import Agent
Agent("google-gla:gemini-2.5-pro-preview-05-06", model_settings=dict(max_tokens=5)).run_sync("write a haiku")
Python, Pydantic AI & LLM client version
Python 3.12.4
Pydantic 0.3.1
google-gla:gemini-2.5-pro-preview-05-06