# Invalid credentials in Authorization header - HfApiModel

**URL:** <https://discuss.huggingface.co/t/invalid-credentials-in-authorization-header-hfapimodel/147158>\
**Category:** Course\
**Created:** [March 24, 2025, 9:12am UTC](https://discuss.huggingface.co/t/invalid-credentials-in-authorization-header-hfapimodel/147158 "2025-03-24T09:12:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DivyanshJain](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@DivyanshJain](https://discuss.huggingface.co/u/DivyanshJain)\
**Post date:** [March 24, 2025, 9:12am UTC](https://discuss.huggingface.co/t/invalid-credentials-in-authorization-header-hfapimodel/147158/1 "2025-03-24T09:12:25Z")

</div>

Dear Team,

I am currently enrolled in the Agents course and encountered an error while attempting to run the Smol\_Agents notebook. Specifically, I received an error when using `model=HfApiModel()` with my free Hugging Face API key.

Could you please assist me in resolving this issue?  
++++++++++++++++++++++++++++++++++++++++++++++++++  
**Error:**  
Error in generating model output:  
401 Client Error: Unauthorized for url:  
[router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions](http://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions) (Request ID:  
Root=1-67dfa1c6-189363a609d7874972942ec5;5bbc6b0b-6f48-455e-b448-e4d5fc570b68)

## Invalid credentials in Authorization header [Step 1: Duration 2.02 seconds]

HTTPError Traceback (most recent call last)  
/usr/local/lib/python3.11/dist-packages/huggingface\_hub/utils/\_http.py in hf\_raise\_for\_status(response, endpoint\_name)  
408 try:  
 → 409 response.raise\_for\_status()  
410 except HTTPError as e:

11 frames  
401 Client Error: Unauthorized for url: [https://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions](https://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions)

The above exception was the direct cause of the following exception:

AgentGenerationError Traceback (most recent call last)  
/usr/local/lib/python3.11/dist-packages/smolagents/agents.py in step(self, memory\_step)  
1200 memory\_step.model\_output = model\_output  
1201 except Exception as e:  
 → 1202 raise AgentGenerationError(f"Error in generating model output:\n{e}", self.logger) from e  
1203  
1204 self.logger.log\_markdown(

Invalid credentials in Authorization header  
++++++++++++++++++++++++++++++++++++++++++++++++

---

<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:** [March 24, 2025, 10:46am UTC](https://discuss.huggingface.co/t/invalid-credentials-in-authorization-header-hfapimodel/147158/2 "2025-03-24T10:46:54Z")

</div>

The following basic measures may help, but the Inference API is currently unstable and Qwen 2.5 Coder 32B is busy, so there is also the possibility of individual problems…  
I’ll bring it if I find something.

> [@Acces token dont work](https://discuss.huggingface.co/t/acces-token-dont-work/134346):
>
> i can login using cmd like i always get that my token is wrong but i create 3 tokens 3 were wrong i tried everything can someone help?

> [@401 Error: Invalid Credentials in Authorization Header (Flan-T5-Large Inference API)](https://discuss.huggingface.co/t/401-error-invalid-credentials-in-authorization-header-flan-t5-large-inference-api/143207):
>
> I have already done the following: white_check_mark Created an API token on Hugging Face white_check_mark Checked that my token has “Make calls to inference providers” permission white_check_mark Tried regenerating a new token and replacing it in my script white_check_mark Confirmed that my Hugging Face account is active and not restricted This is the error message i get: I have already done the following: This is the error message i get: import requests HF\_TOKEN = “JOUW\_NIEUWE\_A…

---

<div class="post-metadata">

**Author:** ![DivyanshJain](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@DivyanshJain](https://discuss.huggingface.co/u/DivyanshJain)\
**Post date:** [March 24, 2025, 11:10am UTC](https://discuss.huggingface.co/t/invalid-credentials-in-authorization-header-hfapimodel/147158/3 "2025-03-24T11:10:42Z")

</div>

Can you confirm if accessing Inference API requires Pro subscription or Free token will work?

---

<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:** [March 24, 2025, 11:46am UTC](https://discuss.huggingface.co/t/invalid-credentials-in-authorization-header-hfapimodel/147158/4 "2025-03-24T11:46:42Z")

</div>

I can’t try the Free token at the moment…

---

<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:** [March 24, 2025, 2:17pm UTC](https://discuss.huggingface.co/t/invalid-credentials-in-authorization-header-hfapimodel/147158/5 "2025-03-24T14:17:54Z")

</div>

The same problem was reported quite a lot in the agents course channel on HF Discord. It would be easier if the following method was still available…

from Discord:

> You can use [https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud/](https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud/) as model\_id (Qwen 2.5 Coder 32B)

---

<div class="post-metadata">

**Author:** ![MagicDash](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/magicdash/32/52196_2.png) [@MagicDash](https://discuss.huggingface.co/u/MagicDash)\
**Post date:** [August 6, 2025, 11:32pm UTC](https://discuss.huggingface.co/t/invalid-credentials-in-authorization-header-hfapimodel/147158/6 "2025-08-06T23:32:28Z")

</div>

huggingface is just sucks
