Skip to content

use 'is not None' for max_nonstreaming_tokens check in timeout calculation#1584

Open
rmotgi1227 wants to merge 1 commit into
anthropics:mainfrom
rmotgi1227:fix/nonstreaming-timeout-is-not-none
Open

use 'is not None' for max_nonstreaming_tokens check in timeout calculation#1584
rmotgi1227 wants to merge 1 commit into
anthropics:mainfrom
rmotgi1227:fix/nonstreaming-timeout-is-not-none

Conversation

@rmotgi1227
Copy link
Copy Markdown

Problem

_calculate_nonstreaming_timeout uses a truthiness guard on max_nonstreaming_tokens:

# _base_client.py line 736
if expected_time > default_time or (max_nonstreaming_tokens and max_tokens > max_nonstreaming_tokens):

The parameter is typed int | None. Checking truthiness silently skips the guard when the value is 0 — a value that would mean "streaming is always required regardless of token count." The condition evaluates to False and no ValueError is raised.

Fix

if expected_time > default_time or (max_nonstreaming_tokens is not None and max_tokens > max_nonstreaming_tokens):

is not None matches the type annotation, makes the intent explicit, and correctly handles a hypothetical max_nonstreaming_tokens=0 entry in MODEL_NONSTREAMING_TOKENS.

…ation

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.
@rmotgi1227 rmotgi1227 requested a review from a team as a code owner May 21, 2026 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants