#community-help

Debugging Typesense API Key Error

TLDR James is getting an error related to the x-typesense-api-key header in their Typesense project. Harrison suggests passing the API key in the HTTP header, and Jason advises checking the key via curl and possibly closing a duplicate Typesense server.

Powered by Struct AI
white_check_mark1
Jan 26, 2022 (20 months ago)
James
Photo of md5-d506a013dfd4f2398dde554c30ffbdde
James
12:42 PM
Hello everyone, i keeo getting this error "Error: Request failed with HTTP code 401 | Server said: Forbidden - a valid x-typesense-api-key header must be sent" anyone got any idea on how to fix it?
Harrison
Photo of md5-43a35158b04c9c49110114370dbeae06
Harrison
12:45 PM
Are you passing the x-typesense-api-key header with your api key?
James
Photo of md5-d506a013dfd4f2398dde554c30ffbdde
James
12:47 PM
how do you mean?
white_check_mark1
Harrison
Photo of md5-43a35158b04c9c49110114370dbeae06
Harrison
12:48 PM
when you send a request
12:48
Harrison
12:48 PM
you need to pass a HTTP header which contains the API key that you start typesense with
James
Photo of md5-d506a013dfd4f2398dde554c30ffbdde
James
01:29 PM
this is my first time with typesense so a little more info or example will help out please
Harrison
Photo of md5-43a35158b04c9c49110114370dbeae06
James
Photo of md5-d506a013dfd4f2398dde554c30ffbdde
James
01:42 PM
So the thing is that I am using typensese to search my db but whenever i try to run the code I get this error
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
02:06 PM
Could you make an API call to the metrics endpoint using curl and your API key to double check that it works fine: https://typesense.org/docs/0.22.1/api/cluster-operations.html#cluster-metrics
02:06
Jason
02:06 PM
Also how did you create your API key?
James
Photo of md5-d506a013dfd4f2398dde554c30ffbdde
James
02:23 PM
export TYPESENSE_API_KEY=xyz
mkdir /tmp/typesense-data
./typesense-server --data-dir=/tmp/typesense-data --api-key=$TYPESENSE_API_KEY --enable-cors and this is the output
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:12 PM
It looks like you already have another Typesense server listening on 8108
03:13
Jason
03:13 PM
If you do ps aux | grep typesense it will show you the process ID
03:13
Jason
03:13 PM
And then you want to kill it with kill <process id>