@@ -2237,11 +2237,17 @@ def _resolve_delegation_credentials(cfg: dict, parent_agent) -> dict:
22372237 """Resolve credentials for subagent delegation.
22382238
22392239 If ``delegation.base_url`` is configured, subagents use that direct
2240- OpenAI-compatible endpoint. Otherwise, if ``delegation.provider`` is
2241- configured, the full credential bundle (base_url, api_key, api_mode,
2242- provider) is resolved via the runtime provider system — the same path used
2243- by CLI/gateway startup. This lets subagents run on a completely different
2244- provider:model pair.
2240+ OpenAI-compatible endpoint. ``delegation.api_key`` overrides the key; when
2241+ omitted, ``api_key`` is returned as ``None`` so ``_build_child_agent``
2242+ inherits the parent agent's key (``effective_api_key = override_api_key or
2243+ parent_api_key``). This lets providers that store their key outside
2244+ ``OPENAI_API_KEY`` (e.g. ``MINIMAX_API_KEY``, ``DASHSCOPE_API_KEY``) work
2245+ without a duplicate config entry.
2246+
2247+ Otherwise, if ``delegation.provider`` is configured, the full credential
2248+ bundle (base_url, api_key, api_mode, provider) is resolved via the runtime
2249+ provider system — the same path used by CLI/gateway startup. This lets
2250+ subagents run on a completely different provider:model pair.
22452251
22462252 If neither base_url nor provider is configured, returns None values so the
22472253 child inherits everything from the parent agent.
@@ -2254,12 +2260,13 @@ def _resolve_delegation_credentials(cfg: dict, parent_agent) -> dict:
22542260 configured_api_key = str (cfg .get ("api_key" ) or "" ).strip () or None
22552261
22562262 if configured_base_url :
2257- api_key = configured_api_key or os .getenv ("OPENAI_API_KEY" , "" ).strip ()
2258- if not api_key :
2259- raise ValueError (
2260- "Delegation base_url is configured but no API key was found. "
2261- "Set delegation.api_key or OPENAI_API_KEY."
2262- )
2263+ # When delegation.api_key is not set, return None so _build_child_agent
2264+ # falls back to the parent agent's API key via the credential inheritance
2265+ # path (effective_api_key = override_api_key or parent_api_key). This
2266+ # lets providers that store their key in a non-OPENAI_API_KEY env var
2267+ # (e.g. MINIMAX_API_KEY, DASHSCOPE_API_KEY) work without requiring
2268+ # callers to duplicate the key under delegation.api_key.
2269+ api_key = configured_api_key # None → inherited from parent in _build_child_agent
22632270
22642271 base_lower = configured_base_url .lower ()
22652272 provider = "custom"
0 commit comments