I am currently encountering an issue while attempting to use the Hugging Face Inference API with access tokens. Despite following all documentation and testing multiple configurations, I am consistently receiving a 401 Unauthorized error when calling the /models endpoint.
Here is a summary of the steps I have taken to troubleshoot this issue:
I generated both read-only and fine-grained tokens from my account settings.
I ensured the tokens include permissions for:
Making calls to the serverless Inference API.
Making calls to Inference Endpoints.
I verified that my network settings allow the API to be reached, as confirmed by successful TLS handshakes.
I tested the tokens using both curl and Python, specifically targeting:
Thanks for the details. It looks like this, but the strange thing is that there shouldn’t be a problem even if you don’t specify it in particular, and it doesn’t look like an SSL error from the message content…
Adding a header “Connection: close” to your CURL command should solve the problem:
curl -v -H “Connection: close” https://example.com
[quote=“John6666, post:4, topic:128643”]
message
[/quote] Hi John, really appreciate you looking into this, I tried incorporating your suggestion but unfortunately I get the same error, HTTP/2 400, invalid token.
I generated both read-only and fine-grained tokens from my account settings. But I always get invalid token at the HF end.
All seems correct, but somehow HF says the token is invalid.
It’s true that there are advantages for those who subscribe to the paid plan, but I don’t think that’s the case here. If it’s because you’re a free member, I think you’d get a different error rather than a 401 error…
There’s nothing wrong with it. I’ll hide some of it, but it’s generally like this. Windows CMD.
Incidentally, the result was exactly the same even if I used my own token.
Host api-inference.huggingface.co:443 was resolved.
* Trying 35.171.117.73:443...
* Connected to api-inference.huggingface.co (35.171.117.73) port 443
* schannel: disabled automatic use of client certificate
* ALPN: curl offers http/1.1
* using HTTP/1.x
> GET /models HTTP/1.1
> Host: api-inference.huggingface.co
> User-Agent: curl/8.9.1
> Accept: */*
> Authorization: Bearer hf_*******
> Connection: close
>
* Request completely sent off
* schannel: server close notification received (close_notify)
< HTTP/1.1 401 Unauthorized
< Date: Tue, 03 Dec 2024 07:41:39 GMT
< Content-Length: 0
< Connection: close
< access-control-allow-credentials: true
< x-request-id: ********
< vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers
<
* shutting down connection #0
* schannel: shutting down SSL/TLS connection with api-inference.huggingface.co port 443