From 32733cff53e219cf1da9cdf80fa1c2dadb6114c4 Mon Sep 17 00:00:00 2001 From: Jack Lakkapragada Date: Sat, 28 Feb 2026 06:24:13 -0600 Subject: [PATCH] fix: treat empty string api_key same as None for Together/GraySwan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When TOGETHER_API_KEY or GRAYSWAN_API_KEY is present but blank in a .env file (e.g. `TOGETHER_API_KEY=`), python-dotenv loads it as an empty string "". The previous `if api_key is not None:` check passes for "", causing AsyncTogether(api_key="") and AsyncGraySwan(api_key="") to raise AuthenticationError at startup — even when those providers are never used in the current run. Switch to `if api_key:` (truthy check) so an empty string is treated the same as None, matching the intended "key not provided" semantics. Co-Authored-By: Claude Sonnet 4.6 --- safetytooling/apis/inference/gray_swan.py | 3 ++- safetytooling/apis/inference/together.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/safetytooling/apis/inference/gray_swan.py b/safetytooling/apis/inference/gray_swan.py index 2ddb99e..2d2e18a 100644 --- a/safetytooling/apis/inference/gray_swan.py +++ b/safetytooling/apis/inference/gray_swan.py @@ -23,7 +23,8 @@ def __init__( ): self.num_threads = num_threads self.prompt_history_dir = prompt_history_dir - if api_key is not None: + # Use truthy check so empty string (from blank .env line) is treated as unset + if api_key: try: self.aclient = AsyncGraySwan(api_key=api_key) except TypeError as e: diff --git a/safetytooling/apis/inference/together.py b/safetytooling/apis/inference/together.py index 7a06141..1b94cd9 100644 --- a/safetytooling/apis/inference/together.py +++ b/safetytooling/apis/inference/together.py @@ -44,7 +44,8 @@ def __init__( ): self.num_threads = num_threads self.prompt_history_dir = prompt_history_dir - if api_key is not None: + # Use truthy check so empty string (from blank .env line) is treated as unset + if api_key: self.aclient = AsyncTogether(api_key=api_key) else: self.aclient = None