Skip to content

fix(router): preserve vendor namespaces and catalog paths in wildcard discovery - #45531

Closed
apex-mochen wants to merge 1 commit into
BerriAI:mainfrom
apex-mochen:fix/openrouter-wildcard-discovery
Closed

apex-mochen wants to merge 1 commit into
BerriAI:mainfrom
apex-mochen:fix/openrouter-wildcard-discovery

Conversation

@apex-mochen

Copy link
Copy Markdown
Contributor

Summary

Fixes #45506

OpenRouter wildcard model discovery is broken in two independent ways:

  1. Wrong catalog URL. OpenrouterConfig inherits the OpenAI-compatible
    get_models, which stripped api_base down to scheme://host and then
    requested /v1/models. With the documented
    api_base=https://openrouter.ai/api/v1, discovery requested
    https://openrouter.ai/v1/models (404) instead of
    https://openrouter.ai/api/v1/models.
  2. Upstream org namespace dropped. get_known_models_from_wildcard
    stripped the first slash segment of every id whose leading segment happens
    to be a known litellm provider. OpenRouter's catalog returns ids that are
    already org-namespaced (e.g. openai/gpt-oss-120b), so openrouter/*
    expanded to openrouter/gpt-oss-120b — an uncallable id — instead of
    openrouter/openai/gpt-oss-120b.

Changes

  • OpenAIGPTConfig.get_models: keep the api_base path; append /models
    when the base already ends with /v1, otherwise append /v1/models.
    Output for OpenAI's own base (https://api.openai.com) is unchanged.
  • get_known_models_from_wildcard: strip a leading provider segment only when
    it belongs to the same provider family as the expanded provider
    (leading == provider, leading.startswith(f"{provider}_"), or
    provider.startswith(f"{leading}_")), preserving upstream org namespaces.

Regression tests

  • TestOpenAIGPTConfigGetModels (3 cases): keeps the api_version path,
    plain-host still resolves to /v1/models, trailing slash normalized.
  • test_wildcard_openrouter_keeps_upstream_org_namespace: openai/anthropic/
    meta-llama ids survive as openrouter/<org>/<model>.
  • test_wildcard_custom_prefix_still_strips_same_family_alias: the existing
    ollama_server1/* + ollama_chat/* alias behaviour is preserved.

Verification

  • ruff check / ruff format --check clean on both source files.
  • ruff check --config ruff-tests.toml clean on both test files.
  • test_model_checks.py: 40 passed.
  • test_openai_gpt_transformation.py -k GetModels: 3 passed.

AI-assisted disclosure: code and tests were produced with AI assistance and
reviewed by the author.

… discovery

OpenRouter wildcard discovery requested /v1/models instead of
/api/v1/models because the inherited OpenAI-compatible get_models stripped
api_base down to scheme://host. It also dropped the upstream org namespace
from ids whose first segment coincides with a known litellm provider
(openai/gpt-oss-120b became openrouter/gpt-oss-120b) instead of keeping it
(openrouter/openai/gpt-oss-120b).

- gpt_transformation.get_models keeps the api_base path and only appends
  /models when the base already ends with /v1.
- get_known_models_from_wildcard strips a leading provider segment only when
  it belongs to the same provider family as the expanded provider, so upstream
  org namespaces survive re-prefixing.

Regression tests:
- test_get_models_keeps_api_version_path / plain_host / trailing_slash
- test_wildcard_openrouter_keeps_upstream_org_namespace
- test_wildcard_custom_prefix_still_strips_same_family_alias

Signed-off-by: apex-mochen <2756823972@qq.com>
@apex-mochen

Copy link
Copy Markdown
Contributor Author

All 67 check runs are failing at the shared Install dependencies step with repo-level uv sync failures — the same pattern is showing up across unrelated PRs in this repo, so this is an environment issue rather than something introduced by this diff. The patch itself passes local ruff checks and the targeted unit tests.

Could we get a re-run once the environment settles?

@apex-mochen apex-mochen changed the title [Bugfix][Router] Preserve vendor namespaces and catalog paths in wildcard discovery fix(router): preserve vendor namespaces and catalog paths in wildcard discovery Oct 13, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

Closing as superseded by #48820, which lists the OpenRouter catalog with vendor namespaces and the right path. Thanks for the early fix

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.

OpenRouter wildcard discovery loses vendor namespaces and endpoint model listing uses wrong path

2 participants