This page shows you how to send chat prompts to a Gemini model by using
the Google Cloud console, REST API, and supported SDKs. To learn how to add images and other media to your request, see
Image understanding. For a list of languages supported by Gemini, see
Language support. To explore
the generative AI models and APIs that are available on Vertex AI, go to
Model Garden in the Google Cloud console. If you're looking for a way to use Gemini directly from your mobile and
web apps, see the
Firebase AI Logic client SDKs for
Swift, Android, Web, Flutter, and Unity apps. For testing and iterating on chat prompts, we recommend using the
Google Cloud console. To send prompts programmatically to the model, you can use the
REST API, Google Gen AI SDK, Vertex AI SDK for Python, or one of the other supported libraries and
SDKs. You can use system instructions to steer the behavior of the model based on a
specific need or use case. For example, you can define a persona or role for a
chatbot that responds to customer service requests. For more information, see
the
system instructions code samples. You can use the Google Gen AI SDK to send requests if
you're using
Gemini 2.0 Flash. Here is a simple text generation example.
To learn more, see the
SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Learn how to install or update the Go.
To learn more, see the
SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
To learn more, see the
SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Learn how to install or update the Java.
To learn more, see the
SDK reference documentation.
Set environment variables to use the Gen AI SDK with Vertex AI:
Generate text
Python
Install
pip install --upgrade google-genai
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True
Go
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True
Node.js
Install
npm install @google/genai
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True
Java
# Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
# with appropriate values for your project.
export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
export GOOGLE_CLOUD_LOCATION=global
export GOOGLE_GENAI_USE_VERTEXAI=True
Streaming and non-streaming responses
You can choose whether the model generates streaming responses or non-streaming responses. For streaming responses, you receive each response as soon as its output token is generated. For non-streaming responses, you receive all responses after all of the output tokens are generated.
Here is a streaming text generation example.
Python
Before trying this sample, follow the Python setup instructions in the Vertex AI quickstart using client libraries. For more information, see the Vertex AI Python API reference documentation.
To authenticate to Vertex AI, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
What's next
Learn how to send multimodal prompt requests:
Learn about responsible AI best practices and Vertex AI's safety filters.