Skip to content

The agent that grows with you

fix(aux): keyed custom endpoints get top-level reasoning_effort, not the nested reasoning object

teknium15ba9cb9fc3f8
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index a2970bbc8a9..8944ffeef74 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -6386,6 +6386,23 @@ class _ProfileProjection(NamedTuple):
messages_wire: bool = False
+def _routes_to_custom_endpoint(provider_norm: str, effective_base: str) -> bool:
+ """True when a profile-less provider name is really a configured OpenAI-compatible custom endpoint.
+
+ Keyed ``providers:`` / ``custom_providers`` entries (by bare key, or ``main``/``auto`` resolving to
+ one) and an explicit base_url on a name no provider catalog knows. Never true for a provider that
+ has its own profile (callers check that first) or a first-class catalog provider without a base_url.
+ """
+ name = _normalize_aux_provider(provider_norm)
+ if name == "custom":
+ return True
+ with contextlib.suppress(Exception):
+ from hermes_cli.runtime_provider import _get_named_custom_provider
+ if _get_named_custom_provider(name) is not None:
+ return True
+ return bool(effective_base) and not _preserve_provider_with_base_url(name)
+
+
def _project_provider_profile(
provider: str, provider_norm: str, model: str, effective_base: str, reasoning_config: Optional[dict],
) -> _ProfileProjection:
@@ -6399,6 +6416,13 @@ def _project_provider_profile(
from providers import get_provider_profile
from providers.base import ProviderProfile
profile = get_provider_profile(provider_norm)
+ if profile is None and _routes_to_custom_endpoint(provider_norm, effective_base):
+ # A keyed ``providers:`` entry referenced by its bare key (or via ``main``/``auto``) is
+ # the same OpenAI-compatible custom endpoint the main path already projects with the
+ # ``custom`` profile (``custom:<key>`` falls back inside get_provider_profile). Without
+ # it the generic nested ``extra_body.reasoning`` fallback below ships to a strict
+ # gateway that only accepts top-level ``reasoning_effort`` -> 400 (#75089).
+ profile = get_provider_profile("custom")
if profile is not None:
messages_wire = profile.api_mode == "anthropic_messages"
body = profile.build_extra_body(model=model, base_url=effective_base, reasoning_config=reasoning_config) or {}
diff --git a/tests/agent/test_auxiliary_named_custom_providers.py b/tests/agent/test_auxiliary_named_custom_providers.py
index 7c8022e23bb..9b2485d62b3 100644
--- a/tests/agent/test_auxiliary_named_custom_providers.py
+++ b/tests/agent/test_auxiliary_named_custom_providers.py
@@ -536,3 +536,46 @@ class TestBareNamedAuxCredentialSurvivesAsyncRebuild:
headers = self._wire_headers(async_client)
assert headers["authorization"] == "Bearer vk-test-1234"
assert headers["x-gw-session"] == "aux-session-tag"
+
+
+class TestKeyedCustomProviderReasoningWire:
+ """Aux calls to a keyed ``providers:`` entry take the ``custom`` profile's reasoning wire (#75089).
+
+ Referenced by bare key or via ``main``, a keyed OpenAI-compatible endpoint must get top-level
+ ``reasoning_effort`` (what the main path sends), never the aggregator-only nested
+ ``extra_body.reasoning`` that strict gateways reject with 400.
+ """
+
+ _KEYED = {
+ "model": {"default": "vendor/model", "provider": "groq"},
+ "providers": {"groq": {"name": "groq", "api": "https://api.groq.com/openai/v1", "api_key": "k"}},
+ }
+
+ @pytest.mark.parametrize("provider", ["groq", "main", "custom:groq"])
+ def test_keyed_entry_sends_top_level_reasoning_effort(self, tmp_path, provider):
+ _write_config(tmp_path, self._KEYED)
+ from agent.auxiliary_client import _build_call_kwargs
+ kwargs = _build_call_kwargs(
+ provider, "vendor/model", [{"role": "user", "content": "hi"}],
+ reasoning_config={"enabled": True, "effort": "medium"},
+ base_url="https://api.groq.com/openai/v1",
+ )
+ assert kwargs.get("reasoning_effort") == "medium"
+ assert "reasoning" not in (kwargs.get("extra_body") or {})
+
+ def test_profile_backed_and_unknown_providers_keep_their_wire(self, tmp_path):
+ _write_config(tmp_path, self._KEYED)
+ from agent.auxiliary_client import _build_call_kwargs
+ nested = {"reasoning": {"enabled": True, "effort": "medium"}}
+ # Aggregator profile: nested extra_body.reasoning is its wire; unchanged.
+ kwargs = _build_call_kwargs(
+ "openrouter", "vendor/model", [{"role": "user", "content": "hi"}],
+ reasoning_config={"enabled": True, "effort": "medium"}, base_url="https://openrouter.ai/api/v1",
+ )
+ assert kwargs["extra_body"] == nested and "reasoning_effort" not in kwargs
+ # No keyed entry, no base_url, no profile: generic fallback, never the custom projection.
+ kwargs = _build_call_kwargs(
+ "someunknown", "vendor/model", [{"role": "user", "content": "hi"}],
+ reasoning_config={"enabled": True, "effort": "medium"},
+ )
+ assert kwargs["extra_body"] == nested and "reasoning_effort" not in kwargs