Saturday, April 23, 2022

[SOLVED] Hugging face whoami endpoint returns unauthorized

Issue

Can't make /whoami endpoint of hugging face API work. I'm using curl and pass a token that I've got from the UI in the Authorization header.

$ curl https://huggingface.co/api/whoami -H "Authorization: Bearer <token>"
> { "error": "Unauthorized" }

At the same time I can use the same token to get private models

$ curl https://huggingface.co/api/models/private/model -H "Authorization: Bearer <token>"
> {"id": "private/model", "modelId": "private/model", ...}

Is there something I do wrong?


Solution

Thanks for raising this!

The endpoint was updated to whoami-v2, it seems we missed updating that doc page. Here is a working example

curl https://huggingface.co/api/whoami-v2 -H "Authorization: Bearer your_token"

Note that we also have a Python library with a whoami method you can use if that's useful. https://github.com/huggingface/huggingface_hub/tree/main/src/huggingface_hub



Answered By - osanseviero
Answer Checked By - Cary Denson (WPSolving Admin)