# Persistent 401 Unauthorized Error with All API Tokens

**URL:** <https://discuss.huggingface.co/t/persistent-401-unauthorized-error-with-all-api-tokens/169233>\
**Category:** Beginners\
**Created:** [October 17, 2025, 6:11am UTC](https://discuss.huggingface.co/t/persistent-401-unauthorized-error-with-all-api-tokens/169233 "2025-10-17T06:11:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alhasan88](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/alhasan88/32/54840_2.png) [@alhasan88](https://discuss.huggingface.co/u/alhasan88)\
**Post date:** [October 17, 2025, 6:11am UTC](https://discuss.huggingface.co/t/persistent-401-unauthorized-error-with-all-api-tokens/169233/1 "2025-10-17T06:11:58Z")

</div>

also I made a write access token in my hugging face account it give me error 401 authentication error

test code

import os

from huggingface\_hub import InferenceClient

# Paste your Hugging Face token here

hf\_token = “hf\_lZqRHmjNhKpkuCTHvUpeyCGWokUiPXzSEs”

# Initialize the client with your token

client = InferenceClient(token=hf\_token)

completion = client.chat.completions.create(

```
model="deepseek-ai/DeepSeek-V3-0324",

messages=\[

```

{

“role”: “user”,

“content”: “How many 'G’s in ‘huggingface’?”

}

],

)

# The expected answer is two 'G’s.

print(completion.choices[0].message.content)

output:

```auto
---------------------------------------------------------------------------

```

```auto
HTTPError Traceback (most recent call last)

```

```auto
/usr/local/lib/python3.12/dist-packages/huggingface_hub/utils/_http.py in hf_raise_for_status(response, endpoint_name)
    406 try:
--> 407 response.raise_for_status()
    408 except HTTPError as e:

```

* * *

7 frames

* * *

```auto
HTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/api/models/deepseek-ai/DeepSeek-V3-0324?expand=inferenceProviderMapping

```

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

```

```auto
HfHubHTTPError Traceback (most recent call last)

```

```auto
/usr/local/lib/python3.12/dist-packages/huggingface_hub/utils/_http.py in hf_raise_for_status(response, endpoint_name)
    478 # Convert `HTTPError` into a `HfHubHTTPError` to display request information
    479 # as well (request id and/or server error message)
--> 480 raise _format(HfHubHTTPError, str(e), response) from e
    481 
    482 

```

```auto
HfHubHTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/api/models/deepseek-ai/DeepSeek-V3-0324?expand=inferenceProviderMapping (Request ID: Root=1-68f1dae6-45587e2f70b800b13e53e74a;0b23f450-0491-4f8a-80b5-1c6d593c1b81)

Invalid credentials in Authorization header

```
