Authorization header is correct, but the token seems invalid

#67
by Srisowmya - opened

raise ValueError(f"Error raised by inference API: {response['error']}")
ValueError: Error raised by inference API: Authorization header is correct, but the token seems invalid raise ValueError(f"Error raised by inference API: {response['error']}")
ValueError: Error raised by inference API: Authorization header is correct, but the token seems invalid

i am getting this error. how to resolve it

Google org

hi @Srisowmya
Can you give more details on how you are running the model

Hi, I am running the model in python and connected it with nodejs using spawn child process. When I am running individual python file , output is displayed but While running nodejs file i am encountering this issue.

Google org

Are you correctly passing your HF token ? A script like this should work I think:

import requests
import os

# Use your personal token here
TOKEN = os.environ.get("API_TOKEN")

API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-xxl"
headers = {"Authorization": f"Bearer {TOKEN}"}

def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.json()
    
output = query({
    "inputs": "The answer to the universe is",
})

Yeah, I am passing correctly. I am passing inference endpoint, headers as well

Google org

can you try with a new HF token? perhaps your token has expired for some reason

@Srisowmya Have you found the reason for this? I get the same error message and have no explanation why. I have recreated and tested several tokens. Thanks!

hello , @Srisowmya . I had actually a similair problem. I tried some tests on postman and the same error occured. What solved it for me was to change the permissions of the token to reader. i was trying the requests using the third option.

I create new token and changed it into Reader but got the same error.

hi did anyone solve this issue

Google org

@sanju9 @Ammar-Azman can you make sure your tokens are valid?

yes token is valid and also tried with new token

error is like
BadRequestError: (Request ID: ISYlQUYmzovFGpb4-yDln)

Bad request:
Authorization header is correct, but the token seems invalid

I fixed the issue, though not sure if my problem was the same as yours
my problem is the API_TOKEN is not passed into headers correctly

Sign up or log in to comment