fix(auxiliary): preserve provider when base_url is passed explicitly - #53688
fix(auxiliary): preserve provider when base_url is passed explicitly#53688rmichelena wants to merge 1 commit into
Conversation
When _resolve_task_provider_model receives both an explicit provider and base_url, it was forcing the provider to "custom" — losing the ability to resolve credentials from provider-specific env vars (ZAI_API_KEY, OPENROUTER_API_KEY, etc.). The resulting client used 'no-key-required' and every vision call returned 401. The config-based path (cfg_base_url + cfg_provider) already had the correct logic. This fixes the explicit-args path to match.
Duplicate of #16727 (earliest-open canonical) — this is one of several open PRs fixing the same |
|
Closing as implemented on main: |
Fix: preserve provider when base_url is passed explicitly
Fixes #53687
Problem
_resolve_task_provider_model()forces the provider to"custom"wheneverbase_urlis passed as an explicit argument — even when a real provider name ("zai","openrouter", etc.) was also provided. This causes credential resolution to fail becauseresolve_provider_client("custom", ...)doesn't know about provider-specific env vars (ZAI_API_KEY,OPENROUTER_API_KEY, etc.) and falls back to"no-key-required", producing 401 errors on every call.Root Cause
The explicit-args path and the config-based path handle
base_urldifferently:The config path correctly preserves
cfg_providerwhencfg_base_urlis set. The explicit path doesn't.This matters because
resolve_vision_provider_client()internally re-calls_resolve_task_provider_model()with explicit args (provider + base_url), which triggers the buggy path:provider: zai, base_url: https://api.z.ai/...→_resolve_task_provider_model("vision")returns("zai", model, base_url, None, None)✅resolve_vision_provider_client(provider="zai", base_url="https://...", api_key=None)re-calls_resolve_task_provider_model("vision", "zai", ..., base_url="https://...", None)with explicit argsbase_urlbranch returns("custom", ...)instead of("zai", ...)← bugresolve_provider_client("custom", ...)→api_key = "no-key-required"→ 401Fix
Make the explicit-args
base_urlbranch preserve the provider name when one is given (and it's not"auto"or"custom"), mirroring the existing config-based logic:Verification
Tested with ZAI/GLM provider:
vision_analyze→401: token expired or incorrect(client created withapi_key='no-key-required')vision_analyze→ works correctly (client created with real API key fromGLM_API_KEY)Also updated the docstring to accurately reflect the new behavior.