BerriAI/litellm · error · ValueError
No provider mapping found for model
Error message
No provider mapping found for model {model} What it means
_fetch_inference_provider_mapping() GETs https://huggingface.co/api/models/<model> with expand=inferenceProviderMapping; if the returned JSON has no 'inferenceProviderMapping' key, it raises ValueError('No provider mapping found for model <model>'). That means the Hub knows the repo but exposes no inference providers for it — the model cannot be called via HF serverless routing through this code path.
Solutions
- Verify the repo is a model with inference providers: open the model page and check the Inference Providers section, or curl the API URL above
- If the model is gated/private, set HUGGINGFACE_API_KEY so the Hub returns the mapping
- Choose a model that lists inference providers, or deploy it yourself and pass api_base (an Inference Endpoint / TEI / TGI URL) to skip Hub routing
- Double-check the model id spelling (owner/repo)
Example fix
# before
litellm.completion(model="hf/some-org/model-without-providers", messages=msgs)
# after — self-host and pass api_base to bypass Hub routing
litellm.completion(
model="hf/some-org/model-without-providers",
api_base="https://xxxx.endpoints.huggingface.cloud/v1",
messages=msgs,
) Defensive patterns
Strategy: validation
Validate before calling
import httpx, os
def hf_has_inference(model_id: str) -> bool:
headers = {"Authorization": f"Bearer {os.getenv('HUGGINGFACE_API_KEY', '')}"} if os.getenv("HUGGINGFACE_API_KEY") else {}
r = httpx.get(
f"https://huggingface.co/api/models/{model_id}",
params={"expand": ["inferenceProviderMapping"]}, headers=headers,
)
return r.status_code == 200 and r.json().get("inferenceProviderMapping") is not None Prevention
- Curate an allowlist of known-good hf model ids instead of accepting arbitrary user-supplied ids
- Set HUGGINGFACE_API_KEY so gated/private models resolve their mapping
- For models without serverless providers, deploy an endpoint and call it with api_base
When it happens
Trigger: Requesting an 'hf/...' model that is not available for serverless inference: non-generative repos (datasets, spaces, demos), gated/private models your token cannot expand, or models with all providers disabled.
Common situations: Using a repository id that is a Space or dataset rather than a model; a brand-new model whose provider rollout has not happened; private/gated model without HUGGINGFACE_API_KEY set; renaming/deletion of the repo.
Related errors
- Failed to fetch provider mapping
- {error_str}
- Invalid task_type= . Expected one of=
- reranker requires 2+ sentences
- sentence-similarity requires 2+ sentences
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/9a6d5b751e6d6d9d.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/huggingface/common_utils.py:88
Raises:
ValueError: If no provider mapping is found
HuggingFaceError: If the API request fails
"""
headers = {"Accept": "application/json"}
if os.getenv("HUGGINGFACE_API_KEY"):
headers["Authorization"] = f"Bearer {os.getenv('HUGGINGFACE_API_KEY')}"
path: Final = f"{HF_HUB_URL}/api/models/{model}"
params: Final = {"expand": ["inferenceProviderMapping"]}
try:
response: Final = httpx.get(path, headers=headers, params=params)
response.raise_for_status()
provider_mapping: Final = response.json().get("inferenceProviderMapping")
if provider_mapping is None:
raise ValueError(f"No provider mapping found for model {model}")
return provider_mapping
except httpx.HTTPError as e:
if hasattr(e, "response"):
status_code = getattr(e.response, "status_code", 500)
headers = getattr(e.response, "headers", {})
else:
status_code = 500
headers = {}
raise HuggingFaceError(
message=f"Failed to fetch provider mapping: {e}",
status_code=status_code,
headers=headers,
)
View on GitHub (pinned to 77b7c6c40c)