fix: restrict provider URL detection to exact hostname matches - #13229
Closed
Aslaaen wants to merge 1 commit into
Closed
fix: restrict provider URL detection to exact hostname matches#13229Aslaaen wants to merge 1 commit into
Aslaaen wants to merge 1 commit into
Conversation
Contributor
|
Merged via PR #13302 — your original commit was cherry-picked onto current main with your authorship preserved (see 5356797f on main). Thank you for the fix, @Aslaaen! Your report caught a real false-positive class, and we took it as the starting point for a full codebase sweep that hardened 26 more call sites across OpenRouter, GitHub Copilot, Kimi, Qwen, ChatGPT/Codex, Bedrock, GitHub Models, Vercel AI Gateway, Nous, Z.AI, Moonshot, Arcee, and MiniMax. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix provider URL auto-detection so direct OpenAI and xAI routing is based on the parsed URL hostname instead of substring matches.
Previously, custom endpoints such as:
https://api.openai.com.example/v1https://proxy.example.test/api.openai.com/v1https://api.x.ai.example/v1could be misclassified as native OpenAI/xAI endpoints because detection searched the whole URL string. That could incorrectly force
codex_responsesrouting for OpenAI-compatible custom providers that only include those strings in their host suffix or path.This change parses the base URL hostname and only treats exact
api.openai.comandapi.x.aihosts as native direct endpoints.Changes
hermes_cli.runtime_provider._detect_api_mode_for_url()to use exact hostname checks.AIAgent.base_url.AIAgentdirect OpenAI and xAI checks to use exact hostname matching.Tests
uv run --frozen --extra dev python -m pytest -q -n 4 tests/hermes_cli/test_detect_api_mode_for_url.py tests/agent/test_direct_provider_url_detection.py.venv\Scripts\python.exe -m py_compile hermes_cli\runtime_provider.py run_agent.py tests\hermes_cli\test_detect_api_mode_for_url.py tests\agent\test_direct_provider_url_detection.pygit diff --check -- hermes_cli\runtime_provider.py run_agent.py tests\hermes_cli\test_detect_api_mode_for_url.py tests\agent\test_direct_provider_url_detection.py