the API endpoint POST /v1/list-corpora returns a 401.
I have tried this with both an API key and OAUTH key and get the same “JWT Token failed to authenticate” message. I have used the API key successfully with the query gRPC so I know it is correct.
Am I missing something on my end or does my account need special permission to get this endpoint?
Just quickly (this is unrelated to the error you’re seeing) but Content-Typ should read Content-Type. Also, you’ll want to double check that you have a valid string for filter and pageKey in the payload object (or just drop these; they can be empty) and presumably you want some non-zero number for numResults as well.
In terms of authentication/authorization, as you note there are 2 types that Vectara supports: API key and OAuth. We haven’t enabled API key authentication for administrative actions (such as listing corpora), so for this particular API, you’ll need to use OAuth. When using OAuth tokens, you’ll need Authorization: Bearer <token>. The token you use there/that the OAuth service returns is a JWT token which should start with the characters ey if you look at it. e.g. your Authorization header should look something like Authorization: Bearer eyJ....
(If/when you use API keys for other APIs like adding content to a corpus or searching, you’ll want to drop the Authorization header entirely and instead have an x-api-key header.)
One other point is that you have to make sure that the identity you are authenticating as (the App Client or the API Key) needs to have proper permissions.
For list-corpora to work, the App Client should have at least CORPUS_ADMIN/COR role.
For query to work, the App Client should have at least QRY role on that corpus, and the Api Key should have that corpus added to it when you create the key.
Got it working. It was a combination of not having the right formate for the Authorization header and missing the right permissions on the API key like @justin mentioned below.
ey-oauth-key-from-session is the key returned from POST /oauth2/token in the ‘access_token’ property starting with ‘ey’ as pointed out above. This logic works just fine if I use ("Authorization": "user-api-key")
The returned error I get is:
<_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = "API Key is invalid."
debug_error_string = "{"created":"@1680040543.856658000","description":"Error received from peer ipv4:52.25.172.92:443","file":"src/core/lib/surface/call.cc","file_line":967,"grpc_message":"API Key is invalid.","grpc_status":16}"
>
In your example code, you are calling a query API and the authentication mechanism you are using is API Key as indicated by this line: ("x-api-key", "ey-oauth-key-from-session")])**
However, you are passing it an OAuth key instead of an API Key.
An API Key starts with zqt_ or zwt_
You can get your API key from Vectara console by logging in and going to Api Keys
Could it be the proto files Im using are out of date?
I pulled these from the github proto repo back on march 9th and I see new versions have been uploaded.
I think I misread your original question a little bit.
For gRPC, you don’t need to pass Authorization as part of metadata.
You need to pass access_token as credentials