# Google automatic token generation

**URL:** <https://forum.weaviate.io/t/google-automatic-token-generation/3377>\
**Category:** Support\
**Created:** [August 16, 2024, 8:35pm UTC](https://forum.weaviate.io/t/google-automatic-token-generation/3377 "2024-08-16T20:35:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cobyboss](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/cobyboss/32/389_2.png) [@Cobyboss](https://forum.weaviate.io/u/Cobyboss)\
**Post date:** [August 16, 2024, 8:35pm UTC](https://forum.weaviate.io/t/google-automatic-token-generation/3377/1 "2024-08-16T20:35:20Z")

</div>

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:

```auto
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:

```auto
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

```auto
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?

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [August 19, 2024, 12:49pm UTC](https://forum.weaviate.io/t/google-automatic-token-generation/3377/2 "2024-08-19T12:49:42Z")

</div>

Hi @Cobyboss !!

This is the corresponding documentation:

> **[Google AI + Weaviate | Weaviate - Vector Database](https://weaviate.io/developers/weaviate/model-providers/google#vertex-ai)**
>
> Google AI offers a wide range of models for natural language processing and generation. Weaviate seamlessly integrates with Google AI Studio and Google Vertex AI APIs, allowing users to leverage Google AI's models directly within the Weaviate...

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?

---

<div class="post-metadata">

**Author:** ![Cobyboss](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/cobyboss/32/389_2.png) [@Cobyboss](https://forum.weaviate.io/u/Cobyboss)\
**Post date:** [August 19, 2024, 6:17pm UTC](https://forum.weaviate.io/t/google-automatic-token-generation/3377/3 "2024-08-19T18:17:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [August 19, 2024, 6:43pm UTC](https://forum.weaviate.io/t/google-automatic-token-generation/3377/4 "2024-08-19T18:43:56Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Cobyboss](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/cobyboss/32/389_2.png) [@Cobyboss](https://forum.weaviate.io/u/Cobyboss)\
**Post date:** [August 19, 2024, 8:10pm UTC](https://forum.weaviate.io/t/google-automatic-token-generation/3377/5 "2024-08-19T20:10:47Z")

</div>

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:

```auto
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [August 19, 2024, 8:52pm UTC](https://forum.weaviate.io/t/google-automatic-token-generation/3377/6 "2024-08-19T20:52:55Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Filipp\_Trigub](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/filipp_trigub/32/1429_2.png) [@Filipp\_Trigub](https://forum.weaviate.io/u/Filipp_Trigub)\
**Post date:** [September 3, 2024, 8:04am UTC](https://forum.weaviate.io/t/google-automatic-token-generation/3377/7 "2024-09-03T08:04:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Cobyboss](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/cobyboss/32/389_2.png) [@Cobyboss](https://forum.weaviate.io/u/Cobyboss)\
**Post date:** [September 16, 2024, 10:32pm UTC](https://forum.weaviate.io/t/google-automatic-token-generation/3377/8 "2024-09-16T22:32:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [September 18, 2024, 12:20pm UTC](https://forum.weaviate.io/t/google-automatic-token-generation/3377/9 "2024-09-18T12:20:42Z")

</div>

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:

> <https://github.com/weaviate/weaviate-python-client/issues/959>
>
> \*\*Problem\*\*:
> Weaviate users who use the Vertex AI integration must provide the O…Auth key for API authentication. 
> 
> But this key has a very short lifetime, and currently the user must semi manually refresh the key. Eg as shown here. https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/text2vec-palm#token-expiry-for-vertex-ai-users
> 
> \*\*Proposal\*\*
> 
> Extend the Weaviate Python client to perform token refresh in the background, with the user's credentials for example.

Please, leave your thumbs up 👍 there so we can prioritize it.

Thanks!
