André Cipriani Bandarra c4acf465ba Add rustdoc comments to all public items
Document all public structs, enums, traits, functions, fields, and
variants across the library. Adds crate-level documentation with a
usage example, module-level docs, and API reference links where
applicable. Also fixes four bare URL warnings in existing doc comments.
2026-01-31 06:59:08 +00:00
2026-01-30 19:01:00 +00:00
2026-01-29 20:14:49 +00:00
2026-01-29 20:14:49 +00:00
2026-01-30 18:59:27 +00:00

google-genai

A Rust client library for the Google Generative AI API.

Building

To build the library, run the following command:

cargo build --release

Running Examples

The project includes several examples in the examples directory. To run an example, you'll first need to set up your environment with your Gemini API key.

  1. Create a .env file in the root of the project:

    GEMINI_API_KEY=your_api_key_here
    
  2. Run an example using cargo run:

    cargo run --example generate-content
    

Usage

To use this library in your own Rust application, add it as a dependency in your Cargo.toml file:

[dependencies]
google-genai = "0.1.0" # Or the latest version

Here is a basic example of how to use the GeminiClient to generate content:

use std::env;
use google_genai::prelude::{Content, GeminiClient, GenerateContentRequest, Role};

async fn run() -> Result<(), Box<dyn std::error::Error>> {
    // Get the API key from the environment.
    let api_key = env::var("GEMINI_API_KEY")?;

    // Create a new GeminiClient.
    let gemini_client = GeminiClient::new(api_key);

    // Build a prompt with a single user message.
    let prompt = vec![
        Content::builder()
            .role(Role::User)
            .add_text_part("What is the airspeed of an unladen swallow?")
            .build(),
    ];

    // Create the content generation request.
    let request = GenerateContentRequest::builder().contents(prompt).build();

    // Call the API to generate content.
    let response = gemini_client
        .generate_content(&request, "gemini-3-pro-preview")
        .await?;

    // Print the response.
    println!("Response: {:?}", response.candidates[0].get_text().unwrap());
    
    Ok(())
}
Description
No description provided
Readme 268 KiB
Languages
Rust 100%