Google automatic token generation

I noticed that you guys aded automatic token generation with Google. Currently, I have to do gcloud auth print-access-token to get the token, but I wanted to use the automatic token generation that has been included in the documentation.

My original code:

vertex_key ="some key"
headers = {
    "X-Palm-Api-Key": vertex_key,
}

client = weaviate.connect_to_weaviate_cloud(
    cluster_url=weaviate_url,                       # `weaviate_url`: your Weaviate URL
    auth_credentials=Auth.api_key(weaviate_key),      # `weaviate_key`: your Weaviate API key
    headers=headers
)

My new code:

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = json_file_path
os.environ['USE_GOOGLE_AUTH'] = 'true'

client = weaviate.connect_to_weaviate_cloud(
    cluster_url=weaviate_url,                       # `weaviate_url`: your Weaviate URL
    auth_credentials=Auth.api_key(weaviate_key),      # `weaviate_key`: your Weaviate API key
)

I just assumed we could remove the headers since it should automatically be generating a key. However, I get

ErrorObject(message="WeaviateInsertManyAllFailedError('Every object failed during insertion. Here is the set of all errors: Google API Key: no api key found neither in request header: X-Palm-Api-Key or X-Google-Api-Key or X-Google-Vertex-Api-Key or X-Google-Studio-Api-Key nor in environment variable under PALM_APIKEY or GOOGLE_APIKEY')

How do I implement automatic token generation properly?

Hi @Cobyboss !!

This is the corresponding documentation:

Note that it was added in versions:
From Weaviate versions 1.24.16 , 1.25.3 and 1.26 .

What is the server version you are using?

I was trying to follow the documentation from that link and made changes as I showed in my code earlier, but I could not get it to work. I am using 1.25.10

Hi!

As I understand, those settings as well as the credentials json must set on the server side, not on the client side.

Once you do that on the server side, the client can be initialized without the credentials.

Let me know if this helps.

Thanks!

I’m pretty sure I have set up the necessary steps on the server side and have the credentials json file set up. I assumed that I no longer need to pass the headers when connecting to the weaviate cloud since the json file should set it up for me which is why my new code is:

client = weaviate.connect_to_weaviate_cloud(
    cluster_url=weaviate_url,                       # `weaviate_url`: your Weaviate URL
    auth_credentials=Auth.api_key(weaviate_key),      # `weaviate_key`: your Weaviate API key
    # headers=headers
)

However, the error I get seems to indicate that I still need to either pass in the header or add an extra environment variable:

no api key found neither in request header: X-Palm-Api-Key or X-Google-Api-Key or X-Google-Vertex-Api-Key or X-Google-Studio-Api-Key nor in environment variable under PALM_APIKEY or GOOGLE_APIKEY'

My question is basically do I need to set the api key in the request header or in PALM_APIKEY or GOOGLE_APIKEY if I followed the steps in the documentation and already set USE_GOOGLE_AUTH to ‘true’ and have the json file?

Hi @Cobyboss !

As I never used this feature myself, I will take some time to try reproducing this myself and possibly escalating with out team.

I’ll be back with more info.
Thanks!

1 Like

I am facing a similar issue.

All versions match, Oauth2 json file is created and the env var pointing to it is set in my local env. USE_GOOGLE_AUTH is also set.

It is not clear to me, what it means to make serverside changes here. My cluster does not seem to allow uploading the cred file.

What am I missing?

EDIT: this option is only for self-hosted servers, right?

Any updates? I’ve done a workaround solution in the meantime but would appreciate a better solution.

HI!

This feature is only available to be set on the server side as of now. and Not on the client side.

We do have a feature request to add this feature to the client side too:

Please, leave your thumbs up :+1: there so we can prioritize it.

Thanks!