BerriAI/litellm · error · ValueError

litellm_router_instance is not set

Error message

litellm_router_instance is not set

What it means

Guard in the LiteLLM semantic-router encoder: encode was called before a litellm_router_instance was injected, so there is no router through which to run the embedding model.

Source

Thrown at litellm/router_strategy/auto_router/litellm_encoder.py:113

        return clamped

    def __call__(self, docs: list[Any], **kwargs) -> list[list[float]]:
        """Encode a list of text documents into embeddings using LiteLLM.

        :param docs: List of text documents to encode.
        :return: List of embeddings for each document."""
        return self.encode_queries(docs, **kwargs)

    async def acall(self, docs: list[Any], **kwargs) -> list[list[float]]:
        """Encode a list of documents into embeddings using LiteLLM asynchronously.

        :param docs: List of documents to encode.
        :return: List of embeddings for each document."""
        return await self.aencode_queries(docs, **kwargs)

    def encode_queries(self, docs: list[str], **kwargs) -> list[list[float]]:
        if self.litellm_router_instance is None:
            raise ValueError("litellm_router_instance is not set")
        try:
            embeds: Final = self.litellm_router_instance.embedding(
                input=self._clamp(docs), model=self.model_name, **kwargs
            )
            return litellm_to_list(embeds)
        except Exception as e:
            raise ValueError(f"{self.type.capitalize()} API call failed. Error: {e}") from e

    def encode_documents(self, docs: list[str], **kwargs) -> list[list[float]]:
        if self.litellm_router_instance is None:
            raise ValueError("litellm_router_instance is not set")
        try:
            embeds: Final = self.litellm_router_instance.embedding(
                input=self._clamp(docs), model=self.model_name, **kwargs
            )
            return litellm_to_list(embeds)
        except Exception as e:
            raise ValueError(f"{self.type.capitalize()} API call failed. Error: {e}") from e

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set litellm_router_instance on the encoder before use.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/router_strategy/auto_router/litellm_encoder.py:113 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/719cc777d244180f. Report an issue: GitHub.