Skip to content

Conversation

@TroyHernandez
Copy link

Summary

  • Add HF_TOKEN as the primary environment variable for authentication (it's the standard used by HuggingFace CLI and Python libraries)
  • Provide helpful error messages for gated repos and auth failures

Changes

  1. HF_TOKEN support: Check HF_TOKEN first, then fall back to HUGGING_FACE_HUB_TOKEN and HUGGINGFACE_HUB_TOKEN

  2. Better error messages:

    • GatedRepo (403): Instructs user to visit the model page and accept the license
    • Unauthorized (401): Instructs user to set HF_TOKEN and provides link to token settings
    • Other errors: Shows the error message from HuggingFace API

Example error output

Before:

Error: Distant resource does not seem to be on huggingface.co (missing commit header).

After:

Error: Access denied to gated repository.
ℹ This model requires accepting a license agreement.
ℹ Visit <https://huggingface.co/google/gemma-3-12b-it> to accept the terms.
ℹ Make sure you are logged in with the account that owns your HF_TOKEN.

Testing

Tested with google/gemma-3-12b-it (a gated model requiring license acceptance).

TroyHernandez and others added 2 commits January 14, 2026 18:35
HF_TOKEN is the standard environment variable used by HuggingFace CLI
and Python libraries. Check it first before falling back to the longer
HUGGING_FACE_HUB_TOKEN and HUGGINGFACE_HUB_TOKEN variants.

This fixes authentication for gated repos when users have HF_TOKEN
set in their .Renviron or environment.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When accessing gated repos without proper authorization, provide
clear instructions:
- GatedRepo error: Link to the model page to accept terms
- 401 Unauthorized: Instructions to set HF_TOKEN
- Other errors: Show the error message from HuggingFace

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant