fix(model-info): sync DeepSeek model metadata and add bare-name fallback (#20885)

The provider-prefixed entries (deepseek/deepseek-chat, deepseek/deepseek-reasoner)
in the model cost map were missing supports_response_schema, supports_system_messages,
supports_native_streaming, supports_parallel_function_calling, and had stale
max_input_tokens / max_output_tokens values. This caused supports_response_schema()
to return False for DeepSeek models regardless of calling convention.

Changes:
- Sync deepseek/deepseek-chat and deepseek/deepseek-reasoner entries with
  their canonical bare-name counterparts in both JSON files
- Add a bare-model-name fallback in _supports_factory so that when a
  provider-prefixed entry is missing a capability field, the bare model
  entry is consulted before returning False
- Fix pre-existing unused-import lint error (F401) in policy_resolve_endpoints.py
- Add 14 regression tests covering data consistency, API-level correctness,
  and the new fallback logic
This commit is contained in:
skylarkoo7 2026-02-11 12:48:10 +05:30
parent d9c69ae9e5
commit 737f12f0c6
5 changed files with 234 additions and 13 deletions

View File

@ -10756,14 +10756,22 @@
"input_cost_per_token": 2.8e-07,
"input_cost_per_token_cache_hit": 2.8e-08,
"litellm_provider": "deepseek",
"max_input_tokens": 128000,
"max_input_tokens": 131072,
"max_output_tokens": 8192,
"max_tokens": 8192,
"mode": "chat",
"output_cost_per_token": 4.2e-07,
"source": "https://api-docs.deepseek.com/quick_start/pricing",
"supported_endpoints": [
"/v1/chat/completions"
],
"supports_assistant_prefill": true,
"supports_function_calling": true,
"supports_native_streaming": true,
"supports_parallel_function_calling": true,
"supports_prompt_caching": true,
"supports_response_schema": true,
"supports_system_messages": true,
"supports_tool_choice": true
},
"deepseek/deepseek-coder": {
@ -10800,16 +10808,24 @@
"input_cost_per_token": 2.8e-07,
"input_cost_per_token_cache_hit": 2.8e-08,
"litellm_provider": "deepseek",
"max_input_tokens": 128000,
"max_output_tokens": 8192,
"max_tokens": 8192,
"max_input_tokens": 131072,
"max_output_tokens": 65536,
"max_tokens": 65536,
"mode": "chat",
"output_cost_per_token": 4.2e-07,
"source": "https://api-docs.deepseek.com/quick_start/pricing",
"supported_endpoints": [
"/v1/chat/completions"
],
"supports_assistant_prefill": true,
"supports_function_calling": true,
"supports_function_calling": false,
"supports_native_streaming": true,
"supports_parallel_function_calling": false,
"supports_prompt_caching": true,
"supports_reasoning": true,
"supports_tool_choice": true
"supports_response_schema": true,
"supports_system_messages": true,
"supports_tool_choice": false
},
"deepseek/deepseek-v3": {
"cache_creation_input_token_cost": 0.0,

View File

@ -12,7 +12,6 @@ from fastapi import APIRouter, Depends, HTTPException, Query
from litellm._logging import verbose_proxy_logger
from litellm.constants import MAX_POLICY_ESTIMATE_IMPACT_ROWS
from litellm.proxy._types import UserAPIKeyAuth
from litellm.proxy.auth.route_checks import RouteChecks
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
from litellm.proxy.policy_engine.attachment_registry import get_attachment_registry
from litellm.proxy.policy_engine.policy_registry import get_policy_registry

View File

@ -2506,6 +2506,16 @@ def _supports_factory(model: str, custom_llm_provider: Optional[str], key: str)
if model_info.get(key, False) is True:
return True
elif model_info.get(key) is None: # don't check if 'False' explicitly set
# Fallback: when the provider-prefixed entry (e.g.
# "deepseek/deepseek-chat") exists but is missing a capability
# field, check the bare model-name entry (e.g. "deepseek-chat")
# which may carry the complete metadata. See #20885.
bare_model_key = _get_model_cost_key(model)
if bare_model_key is not None:
bare_entry = litellm.model_cost.get(bare_model_key) or {}
if bare_entry.get(key, False) is True:
return True
supported_by_provider = _supports_provider_info_factory(
model, custom_llm_provider, key
)

View File

@ -10756,14 +10756,22 @@
"input_cost_per_token": 2.8e-07,
"input_cost_per_token_cache_hit": 2.8e-08,
"litellm_provider": "deepseek",
"max_input_tokens": 128000,
"max_input_tokens": 131072,
"max_output_tokens": 8192,
"max_tokens": 8192,
"mode": "chat",
"output_cost_per_token": 4.2e-07,
"source": "https://api-docs.deepseek.com/quick_start/pricing",
"supported_endpoints": [
"/v1/chat/completions"
],
"supports_assistant_prefill": true,
"supports_function_calling": true,
"supports_native_streaming": true,
"supports_parallel_function_calling": true,
"supports_prompt_caching": true,
"supports_response_schema": true,
"supports_system_messages": true,
"supports_tool_choice": true
},
"deepseek/deepseek-coder": {
@ -10800,16 +10808,24 @@
"input_cost_per_token": 2.8e-07,
"input_cost_per_token_cache_hit": 2.8e-08,
"litellm_provider": "deepseek",
"max_input_tokens": 128000,
"max_output_tokens": 8192,
"max_tokens": 8192,
"max_input_tokens": 131072,
"max_output_tokens": 65536,
"max_tokens": 65536,
"mode": "chat",
"output_cost_per_token": 4.2e-07,
"source": "https://api-docs.deepseek.com/quick_start/pricing",
"supported_endpoints": [
"/v1/chat/completions"
],
"supports_assistant_prefill": true,
"supports_function_calling": true,
"supports_function_calling": false,
"supports_native_streaming": true,
"supports_parallel_function_calling": false,
"supports_prompt_caching": true,
"supports_reasoning": true,
"supports_tool_choice": true
"supports_response_schema": true,
"supports_system_messages": true,
"supports_tool_choice": false
},
"deepseek/deepseek-v3": {
"cache_creation_input_token_cost": 0.0,

View File

@ -0,0 +1,180 @@
"""
Regression tests for #20885 ``supports_response_schema`` (and related
capability flags) must be consistent between the bare model-name entry
(e.g. ``deepseek-chat``) and the provider-prefixed entry
(e.g. ``deepseek/deepseek-chat``) in the model-cost map.
The bug caused ``supports_response_schema("deepseek/deepseek-chat")`` to
return ``False`` even though the canonical ``deepseek-chat`` entry has the
field set to ``True``.
"""
import json
import os
import sys
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm.utils import (
_supports_factory,
supports_response_schema,
)
# ---------------------------------------------------------------------------
# Data-level tests verify the JSON files are in sync
# ---------------------------------------------------------------------------
def _load_backup_json() -> dict:
"""Load the backup JSON directly from disk."""
backup_path = os.path.join(
os.path.dirname(litellm.__file__),
"model_prices_and_context_window_backup.json",
)
with open(backup_path, encoding="utf-8") as f:
return json.load(f)
class TestDeepSeekModelCostEntries:
"""Verify that provider-prefixed DeepSeek entries contain the same
capability flags as their bare-name counterparts in the JSON files."""
def test_deepseek_chat_supports_response_schema_in_backup(self):
data = _load_backup_json()
entry = data.get("deepseek/deepseek-chat", {})
assert entry.get("supports_response_schema") is True
def test_deepseek_reasoner_supports_response_schema_in_backup(self):
data = _load_backup_json()
entry = data.get("deepseek/deepseek-reasoner", {})
assert entry.get("supports_response_schema") is True
def test_deepseek_chat_supports_system_messages_in_backup(self):
data = _load_backup_json()
entry = data.get("deepseek/deepseek-chat", {})
assert entry.get("supports_system_messages") is True
def test_deepseek_reasoner_supports_system_messages_in_backup(self):
data = _load_backup_json()
entry = data.get("deepseek/deepseek-reasoner", {})
assert entry.get("supports_system_messages") is True
def test_deepseek_chat_max_input_tokens_matches_bare_in_backup(self):
data = _load_backup_json()
bare = data.get("deepseek-chat", {})
prefixed = data.get("deepseek/deepseek-chat", {})
assert prefixed.get("max_input_tokens") == bare.get("max_input_tokens")
def test_deepseek_reasoner_max_output_tokens_matches_bare_in_backup(self):
data = _load_backup_json()
bare = data.get("deepseek-reasoner", {})
prefixed = data.get("deepseek/deepseek-reasoner", {})
assert prefixed.get("max_output_tokens") == bare.get("max_output_tokens")
def test_main_json_deepseek_chat_supports_response_schema(self):
main_path = os.path.join(
os.path.dirname(os.path.dirname(litellm.__file__)),
"model_prices_and_context_window.json",
)
with open(main_path, encoding="utf-8") as f:
data = json.load(f)
entry = data.get("deepseek/deepseek-chat", {})
assert entry.get("supports_response_schema") is True
def test_main_json_deepseek_reasoner_supports_response_schema(self):
main_path = os.path.join(
os.path.dirname(os.path.dirname(litellm.__file__)),
"model_prices_and_context_window.json",
)
with open(main_path, encoding="utf-8") as f:
data = json.load(f)
entry = data.get("deepseek/deepseek-reasoner", {})
assert entry.get("supports_response_schema") is True
# ---------------------------------------------------------------------------
# API-level tests verify supports_response_schema returns True
# ---------------------------------------------------------------------------
class TestSupportsResponseSchemaDeepSeek:
"""All calling conventions for DeepSeek should return True for
``supports_response_schema``."""
def test_provider_slash_model(self):
assert supports_response_schema(model="deepseek/deepseek-chat") is True
def test_explicit_provider(self):
assert (
supports_response_schema(
model="deepseek-chat", custom_llm_provider="deepseek"
)
is True
)
def test_reasoner_provider_slash_model(self):
assert supports_response_schema(model="deepseek/deepseek-reasoner") is True
def test_reasoner_explicit_provider(self):
assert (
supports_response_schema(
model="deepseek-reasoner", custom_llm_provider="deepseek"
)
is True
)
# ---------------------------------------------------------------------------
# Fallback-logic test bare model entry used when prefixed is incomplete
# ---------------------------------------------------------------------------
class TestBareModelFallback:
"""When a provider-prefixed entry is missing a capability flag, the
``_supports_factory`` fallback should consult the bare model-name
entry in ``litellm.model_cost``."""
def test_fallback_uses_bare_entry(self):
"""Temporarily remove ``supports_response_schema`` from the prefixed
entry and verify the fallback still returns True."""
key = "deepseek/deepseek-chat"
original = litellm.model_cost.get(key, {}).get("supports_response_schema")
try:
# Simulate the pre-fix state: field missing from prefixed entry
if key in litellm.model_cost:
litellm.model_cost[key].pop("supports_response_schema", None)
result = _supports_factory(
model="deepseek-chat",
custom_llm_provider="deepseek",
key="supports_response_schema",
)
assert result is True
finally:
# Restore
if key in litellm.model_cost and original is not None:
litellm.model_cost[key]["supports_response_schema"] = original
def test_no_fallback_when_explicitly_false(self):
"""If the prefixed entry explicitly sets a capability to ``False``,
the fallback must NOT override it."""
key = "deepseek/deepseek-reasoner"
# After the data fix, deepseek/deepseek-reasoner has
# supports_function_calling=false (matching the bare entry).
# Explicitly set it to False to test the guard.
original = litellm.model_cost.get(key, {}).get("supports_function_calling")
try:
if key in litellm.model_cost:
litellm.model_cost[key]["supports_function_calling"] = False
result = _supports_factory(
model="deepseek-reasoner",
custom_llm_provider="deepseek",
key="supports_function_calling",
)
assert result is False
finally:
if key in litellm.model_cost and original is not None:
litellm.model_cost[key]["supports_function_calling"] = original