# Gemini on Vertex AI and Google AI now unified with the new Google Gen AI SDK

Author: [Mete Atamel](https://atamel.dev/) | Published: 2024-12-17 | Topics: GenAI, GoogleAI, VertexAI, Gemini, Google Cloud Platform | Canonical: https://atamel.dev/posts/2024/12-17_vertexai_googleai_united_with_new_genai_sdk/


If you've been working with Gemini, you've likely encountered the two separate client libraries for Gemini:
the Gemini library for Google AI vs. Vertex AI in Google Cloud. Even though the two libraries are quite similar, there are
slight differences that make the two libraries non-interchangeable.

I usually start my experiments in Google AI and when it is time to switch to Vertex AI on Google Cloud, I couldn't
simply copy and paste my code. I had to go through updating my Google AI libraries to Vertex AI libraries. It wasn't difficult
but it was quite annoying.

Thankfully, the release of the new [Google Gen AI SDK](https://cloud.google.com/vertex-ai/generative-ai/docs/sdks/overview)
addresses my biggest complaint about Gemini. This is the new unified library for Gemini 2.0 and it works against Google
AI and Vertex AI for Gemini 2.0 (and also Gemini 1.5).

![Gemini 2.0](/img/2024/gemini2_logo.png)

Let's go through a quick example to see how it works.

## Google AI

First, let's install the new Google Gen AI SDK:

```sh
pip install google-genai
```

Get an API key on Google AI and create a client with that API key:

```python
client = genai.Client(api_key='your-google-ai-api-key')
```

Generate some content:

```python
response = client.models.generate_content(
    model='gemini-2.0-flash-exp', contents='Why is sky blue?'
)
print(response.text)
```

So far, nothing out of the ordinary. However, let's now try talking to Gemini on Vertex AI.

## Vertex AI

For Vertex AI, you need a Google Cloud project and also pick a location for your Gen AI calls. 

You still create a client but this time, you pass in the `vertexai=True` flag. You also pass in your Google Cloud project
id and location:

```python
client = genai.Client(
    vertexai=True, project='your-google-cloud-project-id', location='us-central1'
)
```

The content generation is exactly the same:

```python
response = client.models.generate_content(
    model='gemini-2.0-flash-exp', contents='Why is sky blue?'
)
print(response.text)
```

Nice!

## Conclusion

As you've seen, it's quite easy now to talk to Gemini on Google AI or Vertex AI with the same library. It's just a matter
of configuring the client with the right parameters. If you want to try it out, I have a tutorial with full code along
with links for further reading:

* [Tutorial: Gemini2 on Google AI and Vertex AI with Google Gen AI SDK](https://github.com/meteatamel/genai-samples/tree/main/vertexai/gemini2/hello-world)
* [Google Gen AI SDKs](https://cloud.google.com/vertex-ai/generative-ai/docs/sdks/overview)
* [Google Gen AI SDK Python](https://googleapis.github.io/python-genai/)
* [Developer’s guide to getting started with Gemini 2.0 Flash on Vertex AI](https://medium.com/google-cloud/developers-guide-to-getting-started-with-gemini-2-0-flash-on-vertex-ai-6b4fe3c6899f)
