Skip to content

fix(auxiliary.vision): keep named-provider credential pool with custom base_url#16389

Closed
Sanjays2402 wants to merge 1 commit into
NousResearch:mainfrom
Sanjays2402:fix/vision-zai-base-url-credentials-16290
Closed

fix(auxiliary.vision): keep named-provider credential pool with custom base_url#16389
Sanjays2402 wants to merge 1 commit into
NousResearch:mainfrom
Sanjays2402:fix/vision-zai-base-url-credentials-16290

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Closes #16290.

Problem

auxiliary.vision configured with provider: zai and a custom base_url (e.g. https://open.bigmodel.cn/api/paas/v4) failed to auto-resolve ZAI_API_KEY from the credential pool — every request hit 401 - {'error': {'code': '401', 'message': '令牌已过期或验证不正确'}}. Workaround was to hardcode api_key in config.yaml.

Root cause is exactly as @hackdion identified: in agent/auxiliary_client.py::resolve_vision_provider_client(), any non-empty resolved_base_url forced the call to resolve_provider_client("custom", ...). That branch only consults OPENAI_API_KEY / explicit_api_key, so the named provider's credential pool (which knows about ZAI_API_KEY, KIMI_API_KEY, etc.) was never asked.

Fix

Three small changes:

  1. resolve_vision_provider_client — when a named non-custom provider with credentials in the pool is requested and a custom base_url is supplied, route through the named provider with explicit_base_url. Falls back to the existing "custom" path if the named provider has no key, preserving prior behaviour for OPENAI_API_KEY-only setups.

  2. resolve_provider_client (api-key branch) — honour explicit_base_url / explicit_api_key overrides. These were already accepted by the "custom" branch but ignored for named api-key providers.

  3. _named_provider_has_credentials(provider) — small helper used by (1) so the routing decision stays cheap (no client construction) and never raises out of the hot path.

The doc'd workaround (hardcoded api_key in config.yaml) still works — when explicit_api_key is supplied the resolver goes straight to the custom path, same as before.

Tests

tests/agent/test_vision_provider_base_url_routing.py — 3 new focused tests:

  • test_vision_with_named_provider_and_base_url_routes_through_named_provider — direct repro of [Bug]: auxiliary.vision with provider=zai and custom base_url fails to auto-resolve ZAI_API_KEY #16290: provider="zai" + base_url="open.bigmodel.cn" routes through "zai" (not "custom") and forwards the explicit base_url.
  • test_vision_with_base_url_falls_back_to_custom_when_named_provider_has_no_creds — preserves prior behaviour when the credential pool is empty.
  • test_vision_with_explicit_api_key_skips_named_provider_routing — preserves the documented hardcoded-key workaround.
pytest tests/agent/test_vision_provider_base_url_routing.py \
       tests/agent/test_vision_resolved_args.py \
       tests/agent/test_auxiliary_client.py \
       tests/agent/test_auxiliary_client_anthropic_custom.py -q
99 passed (95 pre-existing + 4 new)

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder tool/vision Vision analysis and image generation labels Apr 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #16317 and #16308 — all three PRs address the same root cause in resolve_vision_provider_client() dropping named-provider credentials when base_url is set. Fixes #16290.

…m base_url (closes NousResearch#16290)

When auxiliary.vision was configured with provider=zai (or any named
api-key provider) AND a custom base_url, resolve_vision_provider_client
forced provider="custom" before calling resolve_provider_client. That
silently dropped the named provider's credential pool — for zai the
pool resolves ZAI_API_KEY from env / .hermes/.env / hermes auth login —
and only honoured OPENAI_API_KEY. The result was 401s from
open.bigmodel.cn unless the user hardcoded api_key in config.yaml.

Fix:

1. resolve_vision_provider_client: when the user explicitly named a
   non-custom provider that has credentials in the pool, route through
   the named provider with explicit_base_url, instead of folding it into
   "custom". Falls back to "custom" if the named provider has no key
   in the pool, preserving prior behaviour for setups that rely on
   OPENAI_API_KEY.

2. resolve_provider_client (api_key branch): honour explicit_base_url
   and explicit_api_key overrides for named providers. Previously these
   parameters were only consumed by the "custom" branch.

3. New helper _named_provider_has_credentials() so the routing decision
   stays cheap (no client construction) and never raises out of the hot
   path.

Tests: 4 new (tests/agent/test_vision_provider_base_url_routing.py) +
existing test_vision_resolved_args + tests/agent/test_auxiliary_client*
all pass:
  pytest tests/agent/test_vision_provider_base_url_routing.py
         tests/agent/test_vision_resolved_args.py
         tests/agent/test_auxiliary_client.py
         tests/agent/test_auxiliary_client_anthropic_custom.py -q
  -> 99 passed (95 pre-existing + 4 new).
@teknium1

Copy link
Copy Markdown
Contributor

This appears to be implemented on current main by a later fix. Automated hermes-sweeper review.

Evidence:

  • agent/auxiliary_client.py:4156 now keeps the requested named vision provider when resolved_base_url is set, falling back to custom only for empty/auto provider selection. That means provider: zai + custom base_url routes through resolve_provider_client("zai", explicit_base_url=...) rather than forcing "custom".
  • agent/auxiliary_client.py:3803 in the API-key provider branch resolves named-provider credentials and honors explicit_api_key / explicit_base_url before constructing the client.
  • tests/agent/test_vision_resolved_args.py:40 covers the ZAI regression: https://open.bigmodel.cn/api/paas/v4 must still call resolve_provider_client with provider "zai" and the explicit base URL.
  • The implementation landed in 6cf7a9e330cadabd2a0b7ae21f25dc400fc3aa63 (fix(vision): preserve explicit provider auth with custom base_url) and is contained in release tag v2026.5.7 and later.

Thanks for the focused repro and tests here; the current main fix addresses the same root cause discussed in #16290 and the related PR thread.

@teknium1 teknium1 closed this Jun 10, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists sweeper:implemented-on-main Sweeper: behavior already present on current main tool/vision Vision analysis and image generation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: auxiliary.vision with provider=zai and custom base_url fails to auto-resolve ZAI_API_KEY

3 participants