diff --git a/libs/community/langchain_community/embeddings/huggingface.py b/libs/community/langchain_community/embeddings/huggingface.py index 3c9cee3892..7eb175dfaf 100644 --- a/libs/community/langchain_community/embeddings/huggingface.py +++ b/libs/community/langchain_community/embeddings/huggingface.py @@ -311,6 +311,8 @@ class HuggingFaceInferenceAPIEmbeddings(BaseModel, Embeddings): """The name of the model to use for text embeddings.""" api_url: Optional[str] = None """Custom inference endpoint url. None for using default public url.""" + additional_headers: Dict[str, str] = {} + """Pass additional headers to the requests library if needed.""" @property def _api_url(self) -> str: @@ -327,7 +329,10 @@ class HuggingFaceInferenceAPIEmbeddings(BaseModel, Embeddings): @property def _headers(self) -> dict: - return {"Authorization": f"Bearer {self.api_key.get_secret_value()}"} + return { + "Authorization": f"Bearer {self.api_key.get_secret_value()}", + **self.additional_headers, + } def embed_documents(self, texts: List[str]) -> List[List[float]]: """Get the embeddings for a list of texts.