Invalid user token when trying to used gated repo

Greetings everyone!

Yesterday Flux.1 repos started failing on me due to permissions errors. I requested access to the repos and it was granted.

I created two access tokens (One read, another finegrained). Both fails when using
“from huggingface_hub import login
login(token=“mytoken”)”

===== Application Startup at 2025-04-18 15:18:21 =====

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 409, in hf_raise_for_status
    response.raise_for_status()
  File "/usr/local/lib/python3.10/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 "/usr/local/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 1737, in whoami
    hf_raise_for_status(r)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 482, 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-68026d70-2fc01fa71c1b05fa675ead85;49fd364d-489b-4d34-8f3a-fdd25b2cbd6d)

Invalid credentials in Authorization header

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

Traceback (most recent call last):
  File "/home/user/app/app.py", line 12, in <module>
    login(token="[REDACTED]")
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_deprecation.py", line 101, in inner_f
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_deprecation.py", line 31, in inner_f
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/_login.py", line 126, in login
    _login(token, add_to_git_credential=add_to_git_credential)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/_login.py", line 404, in _login
    token_info = whoami(token)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 1750, in whoami
    raise HTTPError(error_message, request=e.request, response=e.response) from e
requests.exceptions.HTTPError: Invalid user token.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 409, in hf_raise_for_status
    response.raise_for_status()
  File "/usr/local/lib/python3.10/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 "/usr/local/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 1737, in whoami
    hf_raise_for_status(r)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 482, 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-68026d7b-0fb4003969dc68811495ef94;e6c2ca18-f70c-4163-840f-d0c55ff351b9)

Invalid credentials in Authorization header

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

Traceback (most recent call last):
  File "/home/user/app/app.py", line 12, in <module>
    login(token="[[REDACTED]]")
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_deprecation.py", line 101, in inner_f
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_deprecation.py", line 31, in inner_f
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/_login.py", line 126, in login
    _login(token, add_to_git_credential=add_to_git_credential)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/_login.py", line 404, in _login
    token_info = whoami(token)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 1750, in whoami
    raise HTTPError(error_message, request=e.request, response=e.response) from e
requests.exceptions.HTTPError: Invalid user token.
 
runtime error
Exit code: 1. Reason: us()
  File "/usr/local/lib/python3.10/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 "/usr/local/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 1737, in whoami
    hf_raise_for_status(r)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_http.py", line 482, 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-68026d70-2fc01fa71c1b05fa675ead85;49fd364d-489b-4d34-8f3a-fdd25b2cbd6d)

Invalid credentials in Authorization header

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

Traceback (most recent call last):
  File "/home/user/app/app.py", line 12, in <module>
    login(token="[redacted]flux")
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_deprecation.py", line 101, in inner_f
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_deprecation.py", line 31, in inner_f
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/_login.py", line 126, in login
    _login(token, add_to_git_credential=add_to_git_credential)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/_login.py", line 404, in _login
    token_info = whoami(token)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/huggingface_hub/hf_api.py", line 1750, in whoami
    raise HTTPError(error_message, request=e.request, response=e.response) from e
requests.exceptions.HTTPError: Invalid user token.

Any ideas what I’m doing wrong?
Thank you very much for your time.

1 Like

A token is required for dev, but not for schnell. Perhaps it will work without login()…

In any case, it seems likely that this is due to the Inference API construction work that has been going on for the past week…

I did notice that the other flux repos were working fine, it’s only the img2img, but I can’t find an alternative setup to Akjava (I cloned this repo months ago, and yesterday stopped working with the premission problems) Flux1 Schnell Img2img - a Hugging Face Space by Akjava.

I added the login part with the hope it would resolve, but no clue atm if I should just wait a couple of days.

1 Like

Without the login, I get

Cannot access gated repo for url https://huggingface.co/black-forest-labs/FLUX.1-schnell/resolve/main/model_index.json.
Access to model black-forest-labs/FLUX.1-schnell is restricted. You must have access to it and be authenticated to access it. Please log in.

Which is weird, because I can access the link (https://huggingface.co/black-forest-labs/FLUX.1-schnell/resolve/main/model_index.json) in the browser while logged in my hf account.

1 Like

Hmm… FLUX.1 schnell is gated NOW but accessible… It’s definitely a bug. @meganariley @pierric @Wauplin @michellehbn


1 Like

Jesus… It’s working now. I’m an idiot, I didn’t know I had to pass the HF_TOKEN as a space secret :clown_face:

Thanks a lot for your time in any case!

1 Like