In this guide, you send a text prompt request and a multimodal prompt and image
request to the Vertex AI Gemini API and view the responses.

## Prerequisites

To complete this guide, you must have a Google Cloud project with the
Vertex AI API enabled. Follow the
[Vertex AI setup guide](https://docs.cloud.google.com/vertex-ai/docs/start/cloud-environment)
to complete these steps.

## Add the Vertex AI client library as a dependency

The Vertex AI client library includes many features. To speed up
compilation, enable only the features that you need:

```bash
cargo add google-cloud-aiplatform-v1 --no-default-features --features prediction-service
```

## Send a prompt to the Vertex AI Gemini API

1. Initialize the client using the default settings:


   ```rust
   let client = PredictionService::builder().build().await?;
   ```

   <br />

2. Build the model name. This example receives the project ID as an argument,
   uses a fixed location (`global`), and sets the model to a specific version of
   Gemini. If you run this function in your own code, pass the project
   ID (without any `projects/` prefix) of the project that you selected in the
   prerequisites:


   ```rust
   const MODEL: &str = "gemini-3.8-flash";
   let model = format!("projects/{project_id}/locations/global/publishers/google/models/{MODEL}");
   ```

   <br />

3. Send the request:


   ```rust
   let response = client
       .generate_content()
       .set_model(&model)
       .set_contents([Content::new()
           .set_role("user")
           .set_parts([Part::new().set_text(
               "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?",
           )])])
       .send()
       .await;
   ```

   <br />

4. Print the response. You can use the `:#?` format specifier to format the
   nested response objects:


   ```rust
   println!("RESPONSE = {response:#?}");
   ```

   <br />

### Text prompt: complete code

```rust
use google_cloud_aiplatform_v1::client::PredictionService;
use google_cloud_aiplatform_v1::model::{Content, Part};

pub async fn sample(project_id: &str) -> anyhow::Result<()> {
    let client = PredictionService::builder().build().await?;

    const MODEL: &str = "gemini-3.8-flash";
    let model = format!("projects/{project_id}/locations/global/publishers/google/models/{MODEL}");

    let response = client
        .generate_content()
        .set_model(&model)
        .set_contents([Content::new()
            .set_role("user")
            .set_parts([Part::new().set_text(
                "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?",
            )])])
        .send()
        .await;
    println!("RESPONSE = {response:#?}");

    Ok(())
}
```

## Send a prompt and an image to the Vertex AI Gemini API

1. Initialize the client using the default settings:


   ```rust
   let client = PredictionService::builder().build().await?;
   ```

   <br />

2. Build the model name:


   ```rust
   const MODEL: &str = "gemini-3.8-flash";
   let model = format!("projects/{project_id}/locations/global/publishers/google/models/{MODEL}");
   ```

   <br />

3. Create the image part of the request:


   ```rust
   Part::new().set_file_data(
       FileData::new()
           .set_mime_type("image/jpeg")
           .set_file_uri("gs://generativeai-downloads/images/scones.jpg"),
   ),
   ```

   <br />

4. Create the text prompt part of the request:


   ```rust
   Part::new().set_text("Describe this picture."),
   ```

   <br />

5. Send the full request:


   ```rust
   let response = client
       .generate_content()
       .set_model(&model)
       .set_contents([Content::new().set_role("user").set_parts([
           Part::new().set_file_data(
               FileData::new()
                   .set_mime_type("image/jpeg")
                   .set_file_uri("gs://generativeai-downloads/images/scones.jpg"),
           ),
           Part::new().set_text("Describe this picture."),
       ])])
       .send()
       .await;
   ```

   <br />

6. Print the full response:


   ```rust
   println!("RESPONSE = {response:#?}");
   ```

   <br />

### Prompt and image: complete code

```rust
use google_cloud_aiplatform_v1::client::PredictionService;
use google_cloud_aiplatform_v1::model::{Content, FileData, Part};

pub async fn sample(project_id: &str) -> anyhow::Result<()> {
    let client = PredictionService::builder().build().await?;

    const MODEL: &str = "gemini-3.8-flash";
    let model = format!("projects/{project_id}/locations/global/publishers/google/models/{MODEL}");

    let response = client
        .generate_content()
        .set_model(&model)
        .set_contents([Content::new().set_role("user").set_parts([
            Part::new().set_file_data(
                FileData::new()
                    .set_mime_type("image/jpeg")
                    .set_file_uri("gs://generativeai-downloads/images/scones.jpg"),
            ),
            Part::new().set_text("Describe this picture."),
        ])])
        .send()
        .await;
    println!("RESPONSE = {response:#?}");

    Ok(())
}
```