diff --git a/pydantic_ai_slim/pydantic_ai/usage.py b/pydantic_ai_slim/pydantic_ai/usage.py index 834b37fc8..45fe21f8e 100644 --- a/pydantic_ai_slim/pydantic_ai/usage.py +++ b/pydantic_ai_slim/pydantic_ai/usage.py @@ -99,10 +99,13 @@ def has_token_limits(self) -> bool: This is useful because if we have token limits, we need to check them after receiving each streamed message. If there are no limits, we can skip that processing in the streaming response iterator. """ - return any( - limit is not None - for limit in (self.request_tokens_limit, self.response_tokens_limit, self.total_tokens_limit) - ) + if self.request_tokens_limit is not None: + return True + if self.response_tokens_limit is not None: + return True + if self.total_tokens_limit is not None: + return True + return False def check_before_request(self, usage: Usage) -> None: """Raises a `UsageLimitExceeded` exception if the next request would exceed the request_limit."""