Invalid credentials in Authorization header... Please help

John6666
Tue, 22 Jul 2025 09:57:22 +0000

Hmm… I think this is how you can check the validity of the token itself.

from dotenv import load_dotenv
import os

load_dotenv()
print("Loaded token:", os.getenv("HUGGINGFACEHUB_API_TOKEN"))

from huggingface_hub import HfApi
api = HfApi()
print(api.whoami(os.getenv("HUGGINGFACEHUB_API_TOKEN")))

If the tokens itself are fine, then it’s probably a version issue or a bug with the LangChain or other libraries.
If the tokens aren’t working, then it’s probably something with your network environment or Hugging Face’s server.