fix: infer provider from base URL for models.dev context length lookup#2206
Closed
0xbyt4 wants to merge 1 commit intoNousResearch:mainfrom
Closed
fix: infer provider from base URL for models.dev context length lookup#22060xbyt4 wants to merge 1 commit intoNousResearch:mainfrom
0xbyt4 wants to merge 1 commit intoNousResearch:mainfrom
Conversation
Custom endpoint users (DashScope/Alibaba, Z.AI, Kimi, DeepSeek, etc.) get wrong context lengths because their provider resolves as "openrouter" or "custom", skipping the models.dev lookup entirely. For example, qwen3.5-plus on DashScope falls to the generic "qwen" hardcoded default (131K) instead of the correct 1M. Add _infer_provider_from_url() that maps known API hostnames to their models.dev provider IDs. When the explicit provider is generic (openrouter/custom/empty), infer from the base URL before the models.dev lookup. This resolves context lengths correctly for DashScope, Z.AI, Kimi, MiniMax, DeepSeek, and Nous endpoints without requiring users to manually set context_length in config. Also refactors _is_known_provider_base_url() to use the same URL mapping, removing the duplicated hostname list.
Contributor
|
Merged via PR #2215. Your commit was cherry-picked onto current main with authorship preserved. Added one follow-up fix: |
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
Custom endpoint users (DashScope/Alibaba, Z.AI, Kimi, DeepSeek, etc.) get incorrect context lengths because their provider resolves as
"openrouter"or"custom", causing an early return at step 3 with 128K fallback — the models.dev lookup (step 5) is never reached.Reported issue:
qwen3.5-pluson DashScope (coding-intl.dashscope.aliyuncs.com) shows 128K instead of 1M.Root cause
_is_known_provider_base_url()didn't include DashScope, DeepSeek, OpenRouter, or Nous URLs. When a URL is "not known" and "not local", step 3 early-returns withDEFAULT_FALLBACK_CONTEXT(128K), skipping steps 4-8 entirely — including the models.dev lookup that has the correct context length.Fix
_URL_TO_PROVIDERmapping: 11 known API hostnames to their models.dev provider IDs (DashScope->alibaba, Z.AI->zai, Kimi->kimi-coding, DeepSeek->deepseek, etc.)_infer_provider_from_url()to extract the provider from a base URLopenrouter/custom/empty), infer from the base URL before the models.dev lookup_is_known_provider_base_url()to use the same mapping (no duplicate hostname list)Behavior change analysis
If a mapped URL serves a model not in models.dev, the lookup returns None and falls through to steps 6-8 as before — no regression.
Test plan
_infer_provider_from_url()verified for all 11 mapped URLs + unknown URLsqwen3.5-pluson DashScope resolves to 1M (was 128K)glm-4-pluson Z.AI resolves to 202K_is_known_provider_base_url()backward compatible for all 7 original URLs