I am generating API tokens, but they are only 34 characters long after hf_ instead of 40. Example: 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. This causes a 401 Unauthorized error in the API. Can you verify or regenerate a valid token? Thank you very much.
Je génère des tokens API, mais ils ne font que 34 caractères après hf_ au lieu de 40. Exemple : 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. Cela cause une erreur 401 Unauthorized dans l’API. Pouvez-vous vérifier ou régénérer un token valide ?
Merci cordialement
1 Like
I’ve never seen tokens of anything other than the typical length, but the token length seems to be variable.
Anyway, you can check the token status using the following methods, so try one of them.
from huggingface_hub import HfApi
api = HfApi()
me = api.whoami(token="hf_xxx") # raises on invalid tokens
print(me)
Or
# prints 200 if valid, 401 if not
curl -s -o /dev/null -w "%{http_code}\n" https://huggingface.co/api/whoami-v2 \
-H "Authorization: Bearer $HF_TOKEN"
Thanks John6666 4 your message, the meaning of my message is HOW to HAVE a valid token ? Because all the tokens I have are invalid thank you
1 Like