# Hugging face api key error

**URL:** <https://discuss.huggingface.co/t/hugging-face-api-key-error/163270>\
**Category:** Beginners\
**Created:** [July 16, 2025, 11:07am UTC](https://discuss.huggingface.co/t/hugging-face-api-key-error/163270 "2025-07-16T11:07:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neha642](https://avatars.discourse-cdn.com/v4/letter/n/ee59a6/32.png) [@Neha642](https://discuss.huggingface.co/u/Neha642)\
**Post date:** [July 16, 2025, 11:07am UTC](https://discuss.huggingface.co/t/hugging-face-api-key-error/163270/1 "2025-07-16T11:07:15Z")

</div>

File “D:\Langchain Models\venv\Lib\site-packages\huggingface\_hub\utils\_deprecation.py”, line 101, in inner\_f  
return f(\*args, \*\*kwargs)  
File “D:\Langchain Models\venv\Lib\site-packages\huggingface\_hub\utils\_deprecation.py”, line 31, in inner\_f  
return f(\*args, \*\*kwargs)  
File “D:\Langchain Models\venv\Lib\site-packages\huggingface\_hub\_login.py”, line 130, in login  
interpreter\_login(new\_session=new\_session)  
~~~~~~~~~~~~~~~~~ ^^^^^^^^^^^^^^^^^^^^^^^^^  
File “D:\Langchain Models\venv\Lib\site-packages\huggingface\_hub\utils\_deprecation.py”, line 101, in inner\_f  
return f(\*args, \*\*kwargs)  
File “D:\Langchain Models\venv\Lib\site-packages\huggingface\_hub\utils\_deprecation.py”, line 31, in inner\_f  
return f(\*args, \*\*kwargs)  
File “D:\Langchain Models\venv\Lib\site-packages\huggingface\_hub\_login.py”, line 290, in interpreter\_login  
\_login(token=token, add\_to\_git\_credential=add\_to\_git\_credential)  
~~~~~~ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “D:\Langchain Models\venv\Lib\site-packages\huggingface\_hub\_login.py”, line 404, in \_login  
token\_info = whoami(token)  
File “D:\Langchain Models\venv\Lib\site-packages\huggingface\_hub\utils\_validators.py”, line 114, in \_inner\_fn  
return fn(\*args, \*\*kwargs)  
File “D:\Langchain Models\venv\Lib\site-packages\huggingface\_hub\hf\_api.py”, line 1788, in whoami  
raise HTTPError(error\_message, request=e.request, response=e.response) from e  
requests.exceptions.HTTPError: Invalid user token.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [July 16, 2025, 11:33am UTC](https://discuss.huggingface.co/t/hugging-face-api-key-error/163270/2 "2025-07-16T11:33:00Z")

</div>

There are various errors that may occur when passing tokens, and various ways to deal with them. Try various methods.

> <https://github.com/huggingface/huggingface_hub/issues/2765>
>
> \### Describe the bug
> 
> Firstly I apologize if it's really basic or trivial, but I… don't seem to understand how to login
> I'm trying to login with the huggingface-cli login and it keeps giving me the following
> 
> \`\`\`
> huggingface-cli login --token \<THE\_TOKEN\>
> The token has not been saved to the git credentials helper. Pass \`add\_to\_git\_credential=True\` in this function directly or \`--add-to-git-credential\` if using via \`huggingface-cli\` if you want to set the git credential as well.
> Traceback (most recent call last):
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface\_hub/utils/\_http.py", line 406, in hf\_raise\_for\_status
> response.raise\_for\_status()
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/requests/models.py", line 1024, in raise\_for\_status
> raise HTTPError(http\_error\_msg, response=self)
> requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/api/whoami-v2
> 
> The above exception was the direct cause of the following exception:
> 
> Traceback (most recent call last):
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface\_hub/hf\_api.py", line 1633, in whoami
> hf\_raise\_for\_status(r)
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface\_hub/utils/\_http.py", line 477, in hf\_raise\_for\_status
> raise \_format(HfHubHTTPError, str(e), response) from e
> huggingface\_hub.errors.HfHubHTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/api/whoami-v2 (Request ID: Root=1-678e5498-0b3b190044e69e0613e6cff6;d4ef20db-e33b-42cc-ac5c-5643c9e9b530)
> 
> Invalid username or password.
> 
> The above exception was the direct cause of the following exception:
> 
> Traceback (most recent call last):
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/bin/huggingface-cli", line 8, in \<module\>
> sys.exit(main())
> ^^^^^^
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface\_hub/commands/huggingface\_cli.py", line 57, in main
> service.run()
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface\_hub/commands/user.py", line 153, in run
> login(
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface\_hub/utils/\_deprecation.py", line 101, in inner\_f
> return f(\*args, \*\*kwargs)
> ^^^^^^^^^^^^^^^^^^
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface\_hub/utils/\_deprecation.py", line 31, in inner\_f
> return f(\*args, \*\*kwargs)
> ^^^^^^^^^^^^^^^^^^
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface\_hub/\_login.py", line 126, in login
> \_login(token, add\_to\_git\_credential=add\_to\_git\_credential)
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface\_hub/\_login.py", line 404, in \_login
> token\_info = whoami(token)
> ^^^^^^^^^^^^^
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface\_hub/utils/\_validators.py", line 114, in \_inner\_fn
> return fn(\*args, \*\*kwargs)
> ^^^^^^^^^^^^^^^^^^^
> File "/home/appsinacup/AlexStuff/ComfyUI/imgaienv/lib/python3.12/site-packages/huggingface\_hub/hf\_api.py", line 1635, in whoami
> raise HTTPError(
> requests.exceptions.HTTPError: Invalid user token. If you didn't pass a user token, make sure you are properly logged in by executing \`huggingface-cli login\`, and if you did pass a user token, double-check it's correct.
> \`\`\`
> 
> 
> also the token seems to work when testing it with 
> 
> \`\`\`
> curl -i https://huggingface.co/api/whoami-v2 \\
> -H "Authorization: Bearer \<THE TOKEN\>"
> HTTP/2 200
> content-type: application/json; charset=utf-8
> content-length: 382
> date: Mon, 20 Jan 2025 14:08:15 GMT
> x-powered-by: huggingface-moon
> cross-origin-opener-policy: same-origin
> referrer-policy: strict-origin-when-cross-origin
> x-request-id: Root=1-678e58cf-35223b3a7ca3d73215320b2d
> access-control-allow-origin: https://huggingface.co
> vary: Origin
> access-control-expose-headers: X-Repo-Commit,X-Request-Id,X-Error-Code,X-Error-Message,X-Total-Count,ETag,Link,Accept-Ranges,Content-Range,X-Xet-Access-Token,X-Xet-Token-Expiration,X-Xet-Refresh-Route,X-Xet-Cas-Url,X-Xet-Hash
> etag: W/"17e-uXTz1hbj/22y/TAql9VBBdqElGo"
> x-cache: Miss from cloudfront
> via: 1.1 e76c434a546615d1c8c0e096c588e7d4.cloudfront.net (CloudFront)
> x-amz-cf-pop: OTP50-P2
> x-amz-cf-id: 4T2TKFmHXP4ma4JeDw0sy4znD0ocV6p9kuv31krBlI0z4kSYbEGaaQ==
> 
> {"type":"user","id":"63dcf661f37111482522cda7","name":"propolys","fullname":"Alex","email":"alexander\_00012@yahoo.com","emailVerified":true,"canPay":false,"periodEnd":null,"isPro":false,"avatarUrl":"/avatars/eb4ec70ff9803cb66fab23117ff45b02.svg","orgs":\[\],"auth":{"type":"access\_token","accessToken":{"displayName":"Comfyread","role":"read","createdAt":"2025-01-20T13:02:07.690Z"}}}
> \`\`\`
> 
> Thank you for any help, and sorry again if it's a noob question
> 
> \### Reproduction
> 
> \_No response\_
> 
> \### Logs
> 
> \`\`\`shell
> 
> \`\`\`
> 
> \### System info
> 
> \`\`\`shell
> \- huggingface\_hub version: 0.27.1
> \- Platform: Linux-6.8.0-51-generic-aarch64-with-glibc2.39
> \- Python version: 3.12.3
> \- Running in iPython ?: No
> \- Running in notebook ?: No
> \- Running in Google Colab ?: No
> \- Running in Google Colab Enterprise ?: No
> \- Token path ?: /home/appsinacup/.cache/huggingface/token
> \- Has saved token ?: False
> \- Configured git credential helpers:
> \- FastAI: N/A
> \- Tensorflow: N/A
> \- Torch: 2.6.0.dev20241224+cu126
> \- Jinja2: 3.1.3
> \- Graphviz: N/A
> \- keras: N/A
> \- Pydot: 3.0.3
> \- Pillow: 11.1.0
> \- hf\_transfer: N/A
> \- gradio: N/A
> \- tensorboard: N/A
> \- numpy: 1.26.4
> \- pydantic: 2.10.3
> \- aiohttp: 3.11.10
> \- ENDPOINT: https://huggingface.co
> \- HF\_HUB\_CACHE: /home/appsinacup/.cache/huggingface/hub
> \- HF\_ASSETS\_CACHE: /home/appsinacup/.cache/huggingface/assets
> \- HF\_TOKEN\_PATH: /home/appsinacup/.cache/huggingface/token
> \- HF\_STORED\_TOKENS\_PATH: /home/appsinacup/.cache/huggingface/stored\_tokens
> \- HF\_HUB\_OFFLINE: False
> \- HF\_HUB\_DISABLE\_TELEMETRY: False
> \- HF\_HUB\_DISABLE\_PROGRESS\_BARS: None
> \- HF\_HUB\_DISABLE\_SYMLINKS\_WARNING: False
> \- HF\_HUB\_DISABLE\_EXPERIMENTAL\_WARNING: False
> \- HF\_HUB\_DISABLE\_IMPLICIT\_TOKEN: False
> \- HF\_HUB\_ENABLE\_HF\_TRANSFER: False
> \- HF\_HUB\_ETAG\_TIMEOUT: 10
> \- HF\_HUB\_DOWNLOAD\_TIMEOUT: 10
> \`\`\`
