This sample demonstrates how to generate text from a multimodal prompt using the Gemini model. The prompt consists of three images and two text prompts. The model generates a text response that describes the images and the text prompts.

## Code sample

### C#


Before trying this sample, follow the C# setup instructions in the
[Vertex AI quickstart using
client libraries](https://docs.cloud.google.com/vertex-ai/docs/start/client-libraries).


For more information, see the
[Vertex AI C# API
reference documentation](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest).


To authenticate to Vertex AI, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).


    using https://docs.cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.html;
    using https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.html;
    using https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.html;
    using System.Net.Http;
    using System.Text;
    using System.Threading.Tasks;

    public class MultimodalMultiImage
    {
        public async Task<string> GenerateContent(
            string projectId = "your-project-id",
            string location = "us-central1",
            string publisher = "google",
            string model = "gemini-2.0-flash-001"
        )
        {
            var predictionServiceClient = new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.PredictionServiceClientBuilder.html
            {
                Endpoint = $"{location}-aiplatform.googleapis.com"
            }.Build();

            https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html colosseum = await ReadImageFileAsync(
                "https://storage.googleapis.com/cloud-samples-data/vertex-ai/llm/prompts/landmark1.png");

            https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html forbiddenCity = await ReadImageFileAsync(
                "https://storage.googleapis.com/cloud-samples-data/vertex-ai/llm/prompts/landmark2.png");

            https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html christRedeemer = await ReadImageFileAsync(
                "https://storage.googleapis.com/cloud-samples-data/vertex-ai/llm/prompts/landmark3.png");

            var generateContentRequest = new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.GenerateContentRequest.html
            {
                Model = $"projects/{projectId}/locations/{location}/publishers/{publisher}/models/{model}",
                Contents =
                {
                    new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Content.html
                    {
                        Role = "USER",
                        Parts =
                        {
                            new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Part.html { InlineData = new() { MimeType = "image/png", Data = colosseum }},
                            new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Part.html { Text = "city: Rome, Landmark: the Colosseum" },
                            new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Part.html { InlineData = new() { MimeType = "image/png", Data = forbiddenCity }},
                            new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Part.html { Text = "city: Beijing, Landmark: Forbidden City"},
                            new https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Part.html { InlineData = new() { MimeType = "image/png", Data = christRedeemer }}
                        }
                    }
                }
            };

            using PredictionServiceClient.StreamGenerateContentStream response = predictionServiceClient.StreamGenerateContent(generateContentRequest);

            StringBuilder fullText = new();

            AsyncResponseStream<GenerateContentResponse> responseStream = response.GetResponseStream();
            await foreach (https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.GenerateContentResponse.html responseItem in responseStream)
            {
                fullText.Append(responseItem.Candidates[0].https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Content.html.Parts[0].Text);
            }
            return fullText.ToString();
        }

        private static async Task<ByteString> ReadImageFileAsync(string url)
        {
            using HttpClient client = new();
            using var response = await client.GetAsync(url);
            byte[] imageBytes = await response.https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.AIPlatform.V1/latest/Google.Cloud.AIPlatform.V1.Content.html.ReadAsByteArrayAsync();
            return https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html.https://docs.cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html#Google_Protobuf_ByteString_CopyFrom_System_Byte___(imageBytes);
        }
    }

### Node.js


Before trying this sample, follow the Node.js setup instructions in the
[Vertex AI quickstart using
client libraries](https://docs.cloud.google.com/vertex-ai/docs/start/client-libraries).


For more information, see the
[Vertex AI Node.js API
reference documentation](https://docs.cloud.google.com/nodejs/docs/reference/aiplatform/latest).


To authenticate to Vertex AI, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    const {VertexAI} = require('https://docs.cloud.google.com/nodejs/docs/reference/vertexai/latest/overview.html');
    const axios = require('axios');

    async function getBase64(url) {
      const image = await axios.get(url, {responseType: 'arraybuffer'});
      return Buffer.from(image.https://docs.cloud.google.com/nodejs/docs/reference/vertexai/latest/vertexai/generativecontentblob.html).toString('base64');
    }

    /**
     * TODO(developer): Update these variables before running the sample.
     */
    async function sendMultiModalPromptWithImage(
      projectId = 'PROJECT_ID',
      location = 'us-central1',
      model = 'gemini-2.0-flash-001'
    ) {
      // For images, the SDK supports base64 strings
      const landmarkImage1 = await getBase64(
        'https://storage.googleapis.com/cloud-samples-data/vertex-ai/llm/prompts/landmark1.png'
      );
      const landmarkImage2 = await getBase64(
        'https://storage.googleapis.com/cloud-samples-data/vertex-ai/llm/prompts/landmark2.png'
      );
      const landmarkImage3 = await getBase64(
        'https://storage.googleapis.com/cloud-samples-data/vertex-ai/llm/prompts/landmark3.png'
      );

      // Initialize Vertex with your Cloud project and location
      const vertexAI = new https://docs.cloud.google.com/nodejs/docs/reference/vertexai/latest/vertexai/vertexai.html({project: projectId, location: location});

      const generativeVisionModel = vertexAI.https://docs.cloud.google.com/nodejs/docs/reference/vertexai/latest/vertexai/vertexai.html({
        model: model,
      });

      // Pass multimodal prompt
      const request = {
        contents: [
          {
            role: 'user',
            parts: [
              {
                inlineData: {
                  data: landmarkImage1,
                  mimeType: 'image/png',
                },
              },
              {
                text: 'city: Rome, Landmark: the Colosseum',
              },

              {
                inlineData: {
                  data: landmarkImage2,
                  mimeType: 'image/png',
                },
              },
              {
                text: 'city: Beijing, Landmark: Forbidden City',
              },
              {
                inlineData: {
                  data: landmarkImage3,
                  mimeType: 'image/png',
                },
              },
            ],
          },
        ],
      };

      // Create the response
      const response = await generativeVisionModel.generateContent(request);
      // Wait for the response to complete
      const aggregatedResponse = await response.response;
      // Select the text from the response
      const fullTextResponse =
        aggregatedResponse.https://docs.cloud.google.com/nodejs/docs/reference/vertexai/latest/vertexai/generatecontentresponse.html[0].https://docs.cloud.google.com/nodejs/docs/reference/vertexai/latest/vertexai/generatecontentcandidate.html.https://docs.cloud.google.com/nodejs/docs/reference/vertexai/latest/vertexai/content.html[0].text;

      console.log(fullTextResponse);
    }

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=generativeaionvertexai).