Skip to content

fix: restrict provider URL detection to exact hostname matches - #13229

Closed
Aslaaen wants to merge 1 commit into
NousResearch:mainfrom
Aslaaen:fix/provider-url-detection-host-boundary
Closed

fix: restrict provider URL detection to exact hostname matches#13229
Aslaaen wants to merge 1 commit into
NousResearch:mainfrom
Aslaaen:fix/provider-url-detection-host-boundary

Conversation

@Aslaaen

@Aslaaen Aslaaen commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

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/v1
  • https://proxy.example.test/api.openai.com/v1
  • https://api.x.ai.example/v1

could be misclassified as native OpenAI/xAI endpoints because detection searched the whole URL string. That could incorrectly force codex_responses routing 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.com and api.x.ai hosts as native direct endpoints.

Changes

  • Add host parsing helper for provider URL detection.
  • Update hermes_cli.runtime_provider._detect_api_mode_for_url() to use exact hostname checks.
  • Cache the parsed base URL hostname on AIAgent.base_url.
  • Update AIAgent direct OpenAI and xAI checks to use exact hostname matching.
  • Add regression tests for host suffix and path-segment false positives.

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.py
  • git 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

@teknium1

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants