Skip to content

Your lightweight open-source personal agent.

fix(providers): clamp max_tokens to >= 1 before calling LiteLLM (#523)

The Mavik10e9e0cdc9ec
diff --git a/nanobot/providers/litellm_provider.py b/nanobot/providers/litellm_provider.py
index 786513901..a39893be4 100644
--- a/nanobot/providers/litellm_provider.py
+++ b/nanobot/providers/litellm_provider.py
@@ -122,6 +122,10 @@ class LiteLLMProvider(LLMProvider):
"""
model = self._resolve_model(model or self.default_model)
+ # Clamp max_tokens to at least 1 — negative or zero values cause
+ # LiteLLM to reject the request with "max_tokens must be at least 1".
+ max_tokens = max(1, max_tokens)
+
kwargs: dict[str, Any] = {
"model": model,
"messages": messages,