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

  1. 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
  2. If the model is gated/private, set HUGGINGFACE_API_KEY so the Hub returns the mapping
  3. 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
  4. 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

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


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)