Tried literally everything. Tried changing Api keys (Used Read, Write, Finegrained - with permissions). Tried changing models (TinyLlama, MetaLlama2, Deepseek)… Looked for other community posts… TRIED EVERTHING… Still ending with “Invalid credentials in Authorization header”
This is my original code:
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
from dotenv import load_dotenv
import os
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.
This is my simple “go-to” snippet for when a Space is acting up. Should provide all the context you need to make a somewhat better-informed next step… you can either come back a later time and hope it fixes itself, or continue trying to debug with more awareness on your immediate environment.