# HuggingFaceEndpoint denies the token

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhuggingfaceendpoint-denies-the-token%2F103823%3E%5C
**Category:** Beginners\
**Created:** [August 24, 2024, 4:51pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhuggingfaceendpoint-denies-the-token%2F103823 "2024-08-24T16:51:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kapi3](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@Kapi3](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FKapi3)%5C
**Post date:** [August 24, 2024, 4:51pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhuggingfaceendpoint-denies-the-token%2F103823%2F1 "2024-08-24T16:51:30Z")

</div>

I have validated the token with the  
**huggingface\_hub.login(“xxx”)** (this works: Login successful)  
**strong textrepoid=“meta-llama/Meta-Llama-3.1-8B”**  
\***HuggingFaceEndpoint (repo\_id=repoid, token=“xxx”)**  
I get the error  
Could not authenticate with huggingface\_hub. Please check your API token. (type=value\_error)

I have tried multiple times with new tokens.

---

<div class="post-metadata">

**Author:** ![mahmutc](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mahmutc/32/64626_2.png) [@mahmutc](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmahmutc)%5C
**Post date:** [August 26, 2024, 7:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhuggingfaceendpoint-denies-the-token%2F103823%2F2 "2024-08-26T07:56:29Z")

</div>

hi @Kapi3  
It seems you use langchain. I don’t know whether this might help or not:

> <https://github.com/langchain-ai/langchain/issues/23808>
>
> \### Checked other resources
> 
> \- \[X\] I added a very descriptive title to this issu…e.
> \- \[X\] I searched the LangChain documentation with the integrated search.
> \- \[X\] I used the GitHub search to find a similar question and didn't find it.
> \- \[X\] I am sure that this is a bug in LangChain rather than my code.
> \- \[X\] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
> 
> \### Example Code
> 
> \`\`\`python
> from langchain\_community.llms import HuggingFaceEndpoint
> llm = HuggingFaceEndpoint(endpoint\_url="https://mixtral.ai.me", huggingfacehub\_api\_token=\<token\>)
> 
> \### Error Message and Stack Trace (if applicable)
> 
> (can't paste because this issue is from an airgapped environment)
> 
> \`\`\`
> File /usr/local/lib/python3.10/dist-packages/pydantic/v1/main.py:341, in BaseModel.\_\_init\_\_
> 
> ValidationError: 1 validation error for HuggingFaceEndpoint
> \_\_root\_\_
> Could not authenticate with huggingface\_hub. Please check your API token. (type=value\_error)
> \`\`\`
> 
> \### Description
> 
> I am trying to use HuggingFaceEndpoint in order to query my locally hosted mixtral. I have a proxy before the proxy that accepts Bearer API tokens. The tokens and API works in other places (e.g. postman) but not with langchain. 
> 
> \### System Info
> 
> langchain==0.2.6
> langchain-community==0.0.38
> langchain-core==0.1.52
> langchain-text-splitters==0.2.2
> 
> platform: Ubuntu 22.04
> 
> Python version: 3.10.12
> 
> The runtime is actually Nvidia's Pytorch container from the NGC catalog, tag 24.01. 
> The environment is airgapped, and we go through a pipeline in order to bring in new library versions.

If not please share your script and library version.

---

<div class="post-metadata">

**Author:** ![sebps](https://avatars.discourse-cdn.com/v4/letter/s/74df32/32.png) [@sebps](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsebps)%5C
**Post date:** [April 21, 2025, 12:12pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhuggingfaceendpoint-denies-the-token%2F103823%2F3 "2025-04-21T12:12:44Z")

</div>

- I faced the same problem while running a langchain based project with langgraph cli command “langgraph dev”
- After debugging I got an error raised at “langchain\_huggingface/llms/huggingface\_endpoint.py(211)” with some explanations and recommendations
- the root problem was : “Blocking call to socket.socket.connect Heads up! LangGraph dev identified a synchronous blocking call in your code. When running in an ASGI web server, blocking calls can degrade performance for everyone since they tie up the event loop.”
- Following the recommendation for dev environment I ran the following command : “langgraph dev --allow-blocking”
- This solved the problem in dev
- For production, the recommendation is to set env variable BG\_JOB\_ISOLATED\_LOOPS=true
