Skip to content

The agent that grows with you

fix(codex): profile declarations follow the host and never override OpenAI's own ladder

teknium1d7f26441419d
diff --git a/agent/transports/codex.py b/agent/transports/codex.py
index ac0076dc374..2053843f854 100644
--- a/agent/transports/codex.py
+++ b/agent/transports/codex.py
@@ -222,12 +222,17 @@ def _resolve_reasoning(model: str, params: dict[str, Any]) -> tuple[Any, bool]:
# Grok 4.6 accepts xhigh; older Grok tops out at high.
supported = XAI_GROK46_EFFORTS if is_grok_46_family(model) else XAI_LEGACY_EFFORTS
else:
- declared = _profile_declared_efforts(params.get("provider"), model, params.get("base_url"))
+ base_url = params.get("base_url")
+ is_codex_backend = params.get("is_codex_backend") is True
+ # OpenAI's own origins have a known per-model ladder; a profile declaration speaks for
+ # endpoints the transport cannot know (a custom relay, a catalog-driven router), never
+ # for a ``custom:`` entry that merely points at api.openai.com.
+ declared = None
+ if not (is_codex_backend or _is_openai_api_origin(base_url)):
+ declared = _profile_declared_efforts(params.get("provider"), model, base_url)
if declared is not None and not declared:
reasoning_enabled = False
- supported = declared or _codex_efforts_for_route(
- model, params.get("base_url"), is_codex_backend=params.get("is_codex_backend") is True
- )
+ supported = declared or _codex_efforts_for_route(model, base_url, is_codex_backend=is_codex_backend)
return clamp_effort(reasoning_effort, supported), reasoning_enabled
@@ -263,16 +268,18 @@ def _default_prompt_cache_retention_for_request(model: str, base_url: Any) -> Op
return "24h" if _EXTENDED_PROMPT_CACHE_MODEL_RE.search(normalized) else None
-def _is_official_openai_responses_route(model: Any, base_url: Any) -> bool:
- """Astra on the canonical API origin only — exact host, so a Responses-compatible proxy or a
- lookalike subdomain keeps the generic contract."""
- if not is_astra_model(model):
- return False
+def _is_openai_api_origin(base_url: Any) -> bool:
+ """Exact host, so a Responses-compatible proxy or a lookalike subdomain keeps the generic contract."""
from utils import base_url_hostname
return base_url_hostname(str(base_url or "")).lower() == "api.openai.com"
+def _is_official_openai_responses_route(model: Any, base_url: Any) -> bool:
+ """Astra on the canonical API origin only."""
+ return is_astra_model(model) and _is_openai_api_origin(base_url)
+
+
def _codex_efforts_for_route(model: Any, base_url: Any, *, is_codex_backend: bool = False) -> tuple[str, ...]:
"""Keep Astra's new vocabulary off unrelated Responses-compatible endpoints."""
if is_astra_model(model) and not (
@@ -328,16 +335,17 @@ def _content_cache_key(instructions: str, tools: Optional[list[dict[str, Any]]],
def _profile_declared_efforts(provider: Any, model: Optional[str], base_url: Any = None) -> Optional[tuple]:
"""Provider-profile-declared reasoning-effort vocabulary, or None (fail-open).
- Resolves by provider name, then by endpoint host. Lazy import: provider
- plugins import this transport during registry discovery.
+ Resolves by endpoint host first, then by provider name: a ``custom:<name>`` entry pointed
+ at a host with a registered profile must follow that host's vocabulary, not the generic
+ custom declaration. Lazy import: provider plugins import this transport during registry
+ discovery.
"""
try:
from providers import get_provider_profile
name = str(provider or "").strip().lower()
- profile = get_provider_profile(name) if name else None
- declared = profile.supported_reasoning_efforts(model) if profile is not None else None
- if declared is None and base_url:
+ declared = None
+ if base_url:
from agent.model_metadata import _infer_provider_from_url
inferred = _infer_provider_from_url(str(base_url))
@@ -345,6 +353,9 @@ def _profile_declared_efforts(provider: Any, model: Optional[str], base_url: Any
inferred_profile = get_provider_profile(inferred)
if inferred_profile is not None:
declared = inferred_profile.supported_reasoning_efforts(model)
+ if declared is None:
+ profile = get_provider_profile(name) if name else None
+ declared = profile.supported_reasoning_efforts(model) if profile is not None else None
except Exception as exc:
logger.debug("profile-declared efforts lookup failed: %s", exc)
return None
diff --git a/tests/agent/transports/test_router_codex_efforts.py b/tests/agent/transports/test_router_codex_efforts.py
index 2fdd06cd971..fb8a9aa1458 100644
--- a/tests/agent/transports/test_router_codex_efforts.py
+++ b/tests/agent/transports/test_router_codex_efforts.py
@@ -161,15 +161,16 @@ class TestHostResolvedProfile:
self, transport, seeded_catalog
):
# A providers.my-proxy entry pointed at api.router.com rides the same
- # host mandate onto this transport; the vocabulary must follow the
- # host, not the config-entry name.
+ # host mandate onto this transport under the runtime's ``custom:<name>``
+ # identity; the vocabulary must follow the host, not the config-entry
+ # name — and not the generic custom declaration either.
kw = transport.build_kwargs(
model="grok-4.6",
messages=[{"role": "user", "content": "Hi"}],
tools=[],
base_url="https://api.router.com/v1",
session_id="sid",
- provider="my-proxy",
+ provider="custom:my-proxy",
reasoning_config={"effort": "max"},
)
assert kw["reasoning"]["effort"] == "xhigh"
diff --git a/tests/plugins/model_providers/test_custom_profile.py b/tests/plugins/model_providers/test_custom_profile.py
index a3ba59733b4..33a59db9211 100644
--- a/tests/plugins/model_providers/test_custom_profile.py
+++ b/tests/plugins/model_providers/test_custom_profile.py
@@ -182,68 +182,37 @@ class TestCustomReasoningWithNumCtx:
class TestCustomResponsesEffortVocabulary:
- """``supported_reasoning_efforts`` keeps the two transports consistent (#114249).
+ """The Responses transport honours a custom endpoint's configured ``max`` (#114249).
- A custom relay's models are not on the OpenAI per-model ladder, so before
- this declaration the Responses transport clamped a configured ``max`` down
- to ``xhigh`` (CODEX_LEGACY_EFFORTS) while the same provider over
- chat-completions forwarded ``max`` unchanged.
+ A custom relay's models are not on the OpenAI per-model ladder; without the
+ profile declaration the Responses transport clamped a configured ``max`` to
+ ``xhigh`` while chat-completions on the same provider forwarded ``max``.
"""
- def test_declares_openai_compat_wire_set(self, custom_profile):
- from agent.reasoning_effort import OPENAI_COMPAT_WIRE_EFFORTS
-
- declared = custom_profile.supported_reasoning_efforts("deepseek-flash")
- assert declared == OPENAI_COMPAT_WIRE_EFFORTS
- assert "max" in declared
-
- def test_named_custom_route_resolves_to_the_declaration(self, custom_profile):
- """``custom:<name>`` resolves to this profile through the registry's
- custom-route fallback, so named relays inherit the same vocabulary."""
- import providers
-
- named = providers.get_provider_profile("custom:relay")
- assert named is custom_profile
-
- def test_responses_transport_keeps_configured_max(self):
+ def test_named_relay_keeps_configured_max_where_chat_completions_does(self, custom_profile):
from agent.transports.codex import _resolve_reasoning
- effort, enabled = _resolve_reasoning(
- "deepseek-flash",
- {
- "provider": "custom:relay",
- "base_url": "https://relay.example/v1",
- "reasoning_config": {"enabled": True, "effort": "max"},
- },
+ reasoning = {"enabled": True, "effort": "max"}
+ _, top_level = custom_profile.build_api_kwargs_extras(
+ reasoning_config=reasoning, base_url="https://relay.example/v1"
)
- assert (effort, enabled) == ("max", True)
-
- def test_responses_transport_still_clamps_ultra_to_max(self):
- """``ultra`` is Hermes-internal; even the widest declared wire set
- must not pass it through verbatim."""
- from agent.transports.codex import _resolve_reasoning
-
- effort, _ = _resolve_reasoning(
+ effort, enabled = _resolve_reasoning(
"deepseek-flash",
- {
- "provider": "custom:relay",
- "base_url": "https://relay.example/v1",
- "reasoning_config": {"enabled": True, "effort": "ultra"},
- },
+ {"provider": "custom:relay", "base_url": "https://relay.example/v1", "reasoning_config": reasoning},
)
- assert effort == "max"
+ assert (effort, enabled) == (top_level["reasoning_effort"], True) == ("max", True)
- def test_openai_backend_ladder_is_unchanged(self):
- """The declaration must not leak into the official OpenAI Responses
- backend: gpt-5.5 keeps rejecting ``max`` (clamps to xhigh, #68365)."""
+ def test_custom_entry_at_the_official_openai_origin_keeps_the_per_model_ladder(self):
+ """api.openai.com's vocabulary is known per model; the custom declaration must not
+ put ``max`` on the wire for a slug OpenAI rejects it on."""
from agent.transports.codex import _resolve_reasoning
effort, enabled = _resolve_reasoning(
- "gpt-5.5",
+ "gpt-5.2",
{
- "provider": "openai",
+ "provider": "custom:oai",
+ "base_url": "https://api.openai.com/v1",
"reasoning_config": {"enabled": True, "effort": "max"},
},
)
assert (effort, enabled) == ("xhigh", True)
-
diff --git a/website/docs/integrations/providers.md b/website/docs/integrations/providers.md
index 99b6c0ec268..1f5577e7182 100644
--- a/website/docs/integrations/providers.md
+++ b/website/docs/integrations/providers.md
@@ -1385,6 +1385,8 @@ Not to be confused with `secrets.command`, which runs a helper **once at startup
Older configs used a top-level `custom_providers:` list instead. It still works — Hermes reads both — and `hermes update` auto-migrates it to the `providers:` dict (config v12). Field names differ slightly in the dict format: legacy `model` is `default_model`, and legacy `api_mode` is `transport`.
:::
+**Reasoning effort on custom endpoints.** The configured `reasoning_effort` (`/reasoning max`, `agent.reasoning_effort`) reaches a custom endpoint unchanged on both the `chat_completions` and the `codex_responses` transport — up to `max`; only the Hermes-internal `ultra` is clamped to `max`. Two exceptions follow the host rather than the entry: a custom entry pointed at `api.openai.com` keeps OpenAI's per-model ladder (`max` is a gpt-5.6-only level there), and an entry pointed at a provider whose profile publishes a per-model vocabulary (Ramp Router) is clamped to that catalog. An endpoint that rejects the level answers with an HTTP 400 instead of Hermes silently downgrading it.
+
Some OpenAI-compatible endpoints need provider-specific request body fields. Add an `extra_body` map to the matching custom provider and Hermes will merge it into each chat-completions request for that endpoint:
```yaml