Skip to content
Latchkey

Hugging Face "Token is required ... run huggingface-cli login" in CI

A hub operation was called with token=True (or one that implies auth) but no token is stored on the runner. Interactive huggingface-cli login cannot run in CI, so the fix is to set HF_TOKEN in the environment.

What this error means

The step fails with "LocalTokenNotFoundError: Token is required (token=True), but no token found. You need to provide a token or be logged in ... by running \"huggingface-cli login\"".

huggingface_hub
huggingface_hub.utils._errors.LocalTokenNotFoundError: Token is required (`token=True`),
but no token found. You need to provide a token or be logged in to Hugging Face with
`huggingface-cli login` or `huggingface_hub.login`.

Common causes

No cached login on the ephemeral runner

Each CI run starts clean with no ~/.cache/huggingface/token, so any call requiring auth has nothing to use.

An interactive login step that cannot prompt

huggingface-cli login expects a TTY prompt; in CI it either hangs or leaves no token.

How to fix it

Export HF_TOKEN in the environment

All HF libraries read HF_TOKEN automatically, so no login step is needed.

.github/workflows/ci.yml
env:
  HF_TOKEN: ${{ secrets.HF_TOKEN }}

Or log in non-interactively with the token

If a tool insists on a cached login, pass the token to the CLI so it writes the credential without a prompt.

Terminal
huggingface-cli login --token "$HF_TOKEN" --add-to-git-credential

How to prevent it

  • Prefer HF_TOKEN in the env over interactive login in CI.
  • Never rely on a cached login persisting between jobs.
  • Keep the token in secrets, never in the workflow file.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →