# 401 Error when trying to upload model from local machine

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F401-error-when-trying-to-upload-model-from-local-machine%2F156020%3E%5C
**Category:** Beginners\
**Created:** [May 20, 2025, 11:24am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F401-error-when-trying-to-upload-model-from-local-machine%2F156020 "2025-05-20T11:24:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![LuuWee](https://avatars.discourse-cdn.com/v4/letter/l/4af34b/32.png) [@LuuWee](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FLuuWee)%5C
**Post date:** [May 20, 2025, 11:24am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F401-error-when-trying-to-upload-model-from-local-machine%2F156020%2F1 "2025-05-20T11:24:19Z")

</div>

Hello everyone,  
im currently training LLMs locally with the Unsloth framework. After training they provide a way to upload your model to the Huggingface Hub.

model.push\_to\_hub\_gguf(  
“LuuWee/modelspacename”, # Change hf to your username!  
tokenizer,  
quantization\_method = [“q4\_k\_m”, “q8\_0”, “q5\_k\_m”,],  
token = “hf\_access\_token”,  
)

For it to upload you need to add your username and an Accesstoken in the request. This worked for me when i trained in Google Colab. I tried the same thing in my local environment and i got this error.

HfHubHTTPError: 401 Client Error: Unauthorized for url: [https://huggingface.co/api/models/hf/model/preupload/main](https://huggingface.co/api/models/hf/model/preupload/main) (Request ID: Root=1-682c51bd-2d7e194c6c897da00154ebba;4a67b560-fee0-4368-a3e9-a018e79e904b)

Invalid credentials in Authorization header

I was able to login via the huggingface-cli with the same token and i could also do the login via python. But saving the model still throws this error.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [May 20, 2025, 2:11pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F401-error-when-trying-to-upload-model-from-local-machine%2F156020%2F2 "2025-05-20T14:11:44Z")

</div>

There doesn’t seem to be a specific issue on GitHub, so if it’s working on Colab, I think it’s a network problem. There are too many possible causes for a 401 error.

> [@401 unauthorized for create\_inference\_endpoint](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F401-unauthorized-for-create-inference-endpoint%2F85038)%3A
>
> Hello, I’m trying to create an inference endpoint with a custom docker image using the huggingface\_hub library because the web interface doesn’t allow environment variables to be set. I first log in with huggingface-cli login, then call create\_inference\_endpoint and get a 401 error, then I tried calling login() within the python script in case that would help and got an identical error, shown below. I’ve also tried creating a new access token with the same result, and upgraded huggingface\_hub …

> [@Error 401 Client Error: Unauthorized for url](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ferror-401-client-error-unauthorized-for-url%2F19714)%3A
>
> When using model card of my private speech recognition model with LM, I got this error: 401 Client Error: Unauthorized for url: [https://huggingface.co/api/models/taliai/tali-asr-with-lm/revision/main](https://huggingface.co/api/models/taliai/tali-asr-with-lm/revision/main) while the same model without lm works fine. Is there anything wrong on my model or model card or … Any help is appreciated.

> **[Issues · unslothai/unsloth](https://github.com/unslothai/unsloth/issues)**
>
> Finetune Qwen3, Llama 4, TTS, DeepSeek-R1 & Gemma 3 LLMs 2x faster with 70% less memory! 🦥 - Issues · unslothai/unsloth

---

<div class="post-metadata">

**Author:** ![koler](https://avatars.discourse-cdn.com/v4/letter/k/9fc348/32.png) [@koler](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fkoler)%5C
**Post date:** [June 17, 2025, 1:34pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F401-error-when-trying-to-upload-model-from-local-machine%2F156020%2F3 "2025-06-17T13:34:28Z")

</div>

huggingface\_hub.errors.HfHubHTTPError: 401 Client Error: Unauthorized for url: [/static-proxy?url=https%3A%2F%2Frouter.huggingface.co%2Ftogether%2Fv1%2Fchat%2Fcompletions%5D(https%3A%2F%2Frouter.huggingface.co%2Ftogether%2Fv1%2Fchat%2Fcompletions) (Request ID: Root=1-68516d9b-26e0213e41d8502a6ec3f259;7dcba0aa-b3ae-44b1-adfc-25eaf4b6dca7)

Invalid credentials in Authorization header

Getting this error any solution if any one knows??  
i Accept the license, try every thing but this is coming again and again.  
i try different models also

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [June 17, 2025, 2:55pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F401-error-when-trying-to-upload-model-from-local-machine%2F156020%2F4 "2025-06-17T14:55:33Z")

</div>

Hmm… If the above method does not work, how about this, for example?

> <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
> \`\`\`
