Which token does huggingface_hub use when several are available, and how do I stop a pipeline sending my token everywhere?
Problem. A batch job authenticates with an unintended (e.g. write-scope) token or leaks it. Conditions. Scripts, containers, CI. Method. Order: a token passed as token= to a call; HF_TOKEN environment variable, which overrides the stored token; the token stored by hf auth login at $HF_HOME/token (or HF_TOKEN_PATH). Once logged in, all Hub requests, even ones needing no auth, send the token; set HF_HUB_DISABLE_IMPLICIT_TOKEN=1 to stop that. Use one token per app/machine so one can be revoked alone. Failure modes. Hardcoding the token in code or notebooks; reusing a write token for a read-only download. Limitations. Docs state the precedence of env over stored token; the exact rank of an explicit token= argument versus HF_TOKEN is not stated in these excerpts. Version/date: huggingface_hub docs main branch fetched 2026-10-24 (stamp per bibliography); behaviour may differ in older releases.
Structured fields
{
"citations": [
{
"url": "https://huggingface.co/docs/huggingface_hub/main/en/package_reference/environment_variables.md",
"note": "HF_TOKEN; Authentication; Authentication; Best practices; researcher reasoning"
},
{
"url": "https://huggingface.co/docs/huggingface_hub/main/en/quick-start.md",
"note": "HF_TOKEN; Authentication; Authentication; Best practices; researcher reasoning"
},
{
"url": "https://huggingface.co/docs/hub/security-tokens.md",
"note": "HF_TOKEN; Authentication; Authentication; Best practices; researcher reasoning"
}
]
}Evidence claims
- [sourced_fact] Problem. A batch job authenticates with an unintended (e.g. write-scope) token or leaks it. Conditions. Scripts, containers, CI. Method. Order: a token passed as token= to a call; HF_TOKEN environment variable, which overrides the stored token; the token stored by hf auth login at $HF_HOME/token (or HF_TOKEN_PATH). Once logged in, all Hub requests, even ones needing no auth, send the token; set HF_HUB_DISABLE_IMPLICIT_TOKEN=1 to stop that. Use one token per app/machine so one can be revoked alone. Failure modes. Hardcoding the token in code or notebooks; reusing a write token for a read-only download. Limitations. Docs state the precedence of env over stored token; the exact rank of an explicit token= argument versus HF_TOKEN is not stated in these excerpts. Version/date: huggingface_hub docs main branch fetched 2026-10-24 (stamp per bibliography); behaviour may differ in older releases. · locator: HF_TOKEN; Authentication; Authentication; Best practices; researcher reasoning source
Rights
| component | license | hosting | redistribution | modification | training | Evidence and notes |
|---|---|---|---|---|---|---|
| documentation | unknown | permitted | permitted | unknown | unknown | Applies to this original summary only, not to the cited sources. |