AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

HuggingFaceEndpointEmbeddings Missing Bill_to/Additional_headers Support

The replacement HuggingFaceEndpointEmbeddings class in langchain-huggingface does not expose parameters to pass billing headers (e.g., X-HF-Bill-To) or custom headers to the underlying InferenceClient, causing 401 Unauthorized errors for users relying on organization-level billing. This capability was available in the deprecated HuggingFaceInferenceAPIEmbeddings.

highConfidence 95%HuggingfaceAffected V1.2.2

Origin Analysis

HuggingFaceEndpointEmbeddings initializes an internal huggingface_hub.InferenceClient without forwarding bill_to and additional_headers parameters, despite the InferenceClient constructor supporting both. This omission prevents users from setting required billing headers for org-scoped inference tokens.
1. Install langchain-huggingface 1.2.2. 2. Create a fine-grained Hugging Face token with 'Make calls to Inference Providers on behalf of the selected organizations'. 3. Instantiate HuggingFaceEndpointEmbeddings with model='sentence-transformers/all-mpnet-base-v2' and the token. 4. Call embed_query('test'). 5. Observe 401 Unauthorized because the required X-HF-Bill-To header is not sent.

Fixing Code Block

Edge Case Audit

This monkey patch depends on the internal structure of the class (e.g., existence of self.model and self.huggingfacehub_api_token attributes and the original __init__ creating self.client). It may break if the internal implementation changes in future releases. It also recreates the client after the base initialization, potentially discarding other client options that the original __init__ may have set (e.g., timeout, proxies). To roll back, simply remove the patch or restart the Python process if the patch was applied globally.

Ecosystem Topology