diff --git a/litellm/utils.py b/litellm/utils.py index 875ffd33feb..8df027b8745 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -3042,6 +3042,8 @@ def openai_token_counter( # This is the case where we need to count tokens for a streamed response. We should NOT add +3 tokens per message in this branch num_tokens = len(encoding.encode(text, disallowed_special=())) return num_tokens + elif text is not None: + num_tokens = len(encoding.encode(text, disallowed_special=())) num_tokens += 3 # every reply is primed with <|start|>assistant<|message|> return num_tokens