From 96514de472d0019c10e5fa5928738094cb7d6a74 Mon Sep 17 00:00:00 2001 From: vominh1919 Date: Tue, 28 Apr 2026 16:46:09 +0700 Subject: [PATCH] fix(auxiliary): avoid locking into custom path when api_key is empty When auxiliary. config has base_url set but api_key is empty (common when user expects env var fallback), _resolve_task_provider_model() returned provider="custom" with api_key=None. This caused downstream client construction to make API calls without an Authorization header, resulting in HTTP 401 errors. Fix: only return "custom" when BOTH cfg_base_url AND cfg_api_key are non-empty. When base_url is set without api_key but with a known provider (e.g. "openrouter"), pass through to that provider so it can resolve credentials from environment variables. Fixes #16829 --- agent/auxiliary_client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py index 62695af83a..3017e7703d 100644 --- a/agent/auxiliary_client.py +++ b/agent/auxiliary_client.py @@ -3132,8 +3132,14 @@ def _resolve_task_provider_model( if task: # Config.yaml is the primary source for per-task overrides. - if cfg_base_url: + if cfg_base_url and cfg_api_key: + # Both base_url and api_key explicitly set → custom endpoint. return "custom", resolved_model, cfg_base_url, cfg_api_key, resolved_api_mode + if cfg_base_url and cfg_provider and cfg_provider != "auto": + # base_url set without api_key but with a known provider — use + # the provider so it can resolve credentials from env vars + # (e.g. OPENROUTER_API_KEY) instead of locking into "custom". + return cfg_provider, resolved_model, cfg_base_url, None, resolved_api_mode if cfg_provider and cfg_provider != "auto": return cfg_provider, resolved_model, None, None, resolved_api_mode