From 3feab2c0d000e4a9602798078d0a7366a75822b3 Mon Sep 17 00:00:00 2001 From: Rishab Motgi Date: Thu, 21 May 2026 12:23:12 -0700 Subject: [PATCH] use 'is not None' check for max_nonstreaming_tokens in timeout calculation The truthiness guard silently ignored max_nonstreaming_tokens=0, which would mean streaming is always required. Using 'is not None' matches the type annotation (int | None) and makes the intent explicit. --- src/anthropic/_base_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/anthropic/_base_client.py b/src/anthropic/_base_client.py index c77bb55df..db4c36de7 100644 --- a/src/anthropic/_base_client.py +++ b/src/anthropic/_base_client.py @@ -733,7 +733,7 @@ def _calculate_nonstreaming_timeout(self, max_tokens: int, max_nonstreaming_toke default_time = 60 * 10 expected_time = maximum_time * max_tokens / 128_000 - if expected_time > default_time or (max_nonstreaming_tokens and max_tokens > max_nonstreaming_tokens): + if expected_time > default_time or (max_nonstreaming_tokens is not None and max_tokens > max_nonstreaming_tokens): raise ValueError( "Streaming is required for operations that may take longer than 10 minutes. " + "See https://github.com/anthropics/anthropic-sdk-python#long-requests for more details",