Skip to content

fix: infer provider from base URL for models.dev context length lookup#2206

Closed
0xbyt4 wants to merge 1 commit intoNousResearch:mainfrom
0xbyt4:fix/infer-provider-from-base-url
Closed

fix: infer provider from base URL for models.dev context length lookup#2206
0xbyt4 wants to merge 1 commit intoNousResearch:mainfrom
0xbyt4:fix/infer-provider-from-base-url

Conversation

@0xbyt4
Copy link
Copy Markdown
Contributor

@0xbyt4 0xbyt4 commented Mar 20, 2026

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-plus on 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 with DEFAULT_FALLBACK_CONTEXT (128K), skipping steps 4-8 entirely — including the models.dev lookup that has the correct context length.

Fix

  • Add _URL_TO_PROVIDER mapping: 11 known API hostnames to their models.dev provider IDs (DashScope->alibaba, Z.AI->zai, Kimi->kimi-coding, DeepSeek->deepseek, etc.)
  • Add _infer_provider_from_url() to extract the provider from a base URL
  • In step 5, when the explicit provider is generic (openrouter/custom/empty), infer from the base URL before the models.dev lookup
  • Refactor _is_known_provider_base_url() to use the same mapping (no duplicate hostname list)

Behavior change analysis

Scenario Before After Change
DashScope + qwen3.5-plus 128K (early return) 1M (models.dev) Fix
DeepSeek API 128K (early return) Correct (models.dev) Fix
OpenRouter URL with base_url set 128K (early return) Correct (step 6 metadata) Improvement
Together/Groq (not mapped) 128K (early return) 128K (early return) No change
Local Ollama Local query Local query No change
Unknown proxy 128K fallback 128K fallback No change
No base_url Steps 4-8 Steps 4-8 No change

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 URLs
  • qwen3.5-plus on DashScope resolves to 1M (was 128K)
  • glm-4-plus on Z.AI resolves to 202K
  • All 113 model_metadata tests pass
  • _is_known_provider_base_url() backward compatible for all 7 original URLs
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.
@teknium1
Copy link
Copy Markdown
Contributor

Merged via PR #2215. Your commit was cherry-picked onto current main with authorship preserved. Added one follow-up fix: dashscope-intl.aliyuncs.com (the official international endpoint) was added to the URL mapping. Thanks for the clean contribution!

@teknium1 teknium1 closed this Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants