Skip to content

[CLI] Add hf auth token command#4104

Merged
Wauplin merged 3 commits intomainfrom
cli-auth-token
Apr 15, 2026
Merged

[CLI] Add hf auth token command#4104
Wauplin merged 3 commits intomainfrom
cli-auth-token

Conversation

@Wauplin
Copy link
Copy Markdown
Contributor

@Wauplin Wauplin commented Apr 15, 2026

(related to internal private slack thread)

Adds hf auth token to print the current token to stdout. Handy for piping into other commands.

$ hf auth token
hf_xxx***
Hint: Run `hf auth whoami` to see which account this token belongs to.

You can pipe this output to make a cURL call

$ hf auth token | xargs -I {} curl -H "Authorization: Bearer {}" https://huggingface.co/api/settings/billing/usage

If not logged in, prints an error nudging to hf auth login and exits 1.

$ hf auth token
Error: Not logged in. Run `hf auth login` first.

🤖 Generated with Claude Code


Note: the plan in a future PR is to provide a hf api command similar to gh api to make authenticated calls to any endpoint on hf.co/ (would need a maybe a hf api schema to fetch https://huggingface.co/spaces/huggingface/openapi + hf api run ?). In any case, hf auth token will still be useful for instance to do export ANTHROPIC_AUTH_TOKEN="$(hf auth token)" in hf-claude cc @hanouticelina

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bot-ci-comment
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
if token is None:
out.error("Not logged in. Run `hf auth login` first.")
raise typer.Exit(code=1)
print(token)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left print since we want to print only the token, no matter the output mode

@Wauplin Wauplin requested a review from hanouticelina April 15, 2026 08:37
@Wauplin Wauplin marked this pull request as ready for review April 15, 2026 08:37
Copy link
Copy Markdown
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@Wauplin Wauplin merged commit 52e6adb into main Apr 15, 2026
20 of 21 checks passed
@Wauplin Wauplin deleted the cli-auth-token branch April 15, 2026 09:00
@julien-c
Copy link
Copy Markdown
Member

nice 👍

@huggingface-hub-bot
Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.11.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants