Skip to content

fix(auxiliary): inherit model.api_key for same-host custom endpoints when per-task key is empty - #59207

Merged
teknium1 merged 2 commits into
mainfrom
salvage/55911-aux-key-inherit
Jul 6, 2026
Merged

fix(auxiliary): inherit model.api_key for same-host custom endpoints when per-task key is empty#59207
teknium1 merged 2 commits into
mainfrom
salvage/55911-aux-key-inherit

Conversation

@teknium1

@teknium1 teknium1 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Auxiliary tasks configured with provider: custom + an explicit base_url but an empty per-task api_key now inherit the main model.api_key — instead of sending the no-key-required placeholder and 401ing on shared self-hosted gateways. Fixes #9318.

Salvage of #55911 by @Tranquil-Flow, cherry-picked onto current main with authorship preserved, plus a hardening follow-up: inheritance is host-gated — the main key is only inherited when the aux base_url resolves to the same hostname as the main model's base_url (runtime override or config). A misconfigured aux endpoint on a different host keeps the previous fail-safe behavior instead of leaking the main credential cross-host.

Changes

  • agent/auxiliary_client.py: _read_main_api_key() (contributor — mirrors _read_main_model/_read_main_provider, runtime override → config); _read_main_base_url() + _read_main_api_key_if_same_host() (follow-up) wired into the custom-endpoint key fallback chain after explicit key and OPENAI_API_KEY
  • tests/agent/test_auxiliary_client.py: contributor's 4 tests (adjusted for host gating) + 2 new negative tests (cross-host no-inherit, no-main-base_url no-inherit)

Validation

scenario Before After
shared gateway, empty aux key no-key-required → 401 inherits model.api_key
aux base_url on different host no-key-required no-key-required (unchanged — no leak)
explicit key / OPENAI_API_KEY wins wins (unchanged)
local server, no key anywhere no-key-required unchanged

scripts/run_tests.sh tests/agent/test_auxiliary_client.py: 293/293 green. E2E with real imports + temp HERMES_HOME using the exact #9318 repro config: same-host inherits sk-my-real-key, cross-host stays no-key-required.

Infographic

aux-key-inheritance

Tranquil-Flow and others added 2 commits July 5, 2026 14:59
…sk key is empty (#9318)

When an auxiliary task is configured with provider=custom and an explicit
base_url but an empty api_key, the custom_key fallback chain in
resolve_provider_client() jumped straight to the no-key-required
placeholder without consulting model.api_key from config.yaml.  Users
on self-hosted gateways who share the same endpoint and credentials for
both the main model and auxiliary tasks got 401 auth errors.

Add _read_main_api_key() following the same pattern as _read_main_model()
and _read_main_provider(): checks _RUNTIME_MAIN_API_KEY (runtime override)
first, then config.yaml model.api_key.  Insert it into the fallback chain
before no-key-required so real credentials are used when available, while
local servers without auth still get the placeholder.
Follow-up to the #55911 salvage: inherit model.api_key only when the aux
base_url resolves to the same hostname as the main model's base_url
(runtime override or config). A misconfigured aux endpoint on a different
host keeps the fail-safe no-key-required placeholder instead of leaking
the main credential cross-host.
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/auth Authentication, OAuth, credential pools labels Jul 5, 2026
@teknium1
teknium1 merged commit ede7e31 into main Jul 6, 2026
31 checks passed
@teknium1
teknium1 deleted the salvage/55911-aux-key-inherit branch July 6, 2026 00:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Auxiliary client falls back to "no-key-required" when per-task custom base_url is set but api_key is empty

3 participants