18 releases (7 stable)

Uses new Rust 2024

2.0.1 Jul 21, 2026
2.0.0 Jun 11, 2025
1.4.0 Jun 11, 2025
1.1.0 Mar 19, 2025
0.4.2 Nov 15, 2024

#31 in #gemini-api

Download history 26/week @ 2026-07-28 23/week @ 2026-08-04 51/week @ 2026-08-11 21/week @ 2026-08-18 12/week @ 2026-08-25 16/week @ 2026-09-01 45/week @ 2026-09-08 15/week @ 2026-09-15 13/week @ 2026-09-22 30/week @ 2026-09-29 17/week @ 2026-10-06 16/week @ 2026-10-13 13/week @ 2026-10-20 15/week @ 2026-10-27 16/week @ 2026-11-03 35/week @ 2026-11-10

80 downloads per month
Used in whathaveidone

MIT license

1.5MB
995 lines

STILL A WIP

A library to use Google Gemini's API directly in Rust! Made because the current options weren't very capable and didn't support 100% of the official API.

Example

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!(
        "{}",
        gemini_rs::chat("gemini-2.0-flash")
            .send_message("Explain how AI works")
            .await?
    );
    Ok(())
}

lib.rs:

A Rust client library for Google's Gemini AI models.

Overview

This library provides a fully-featured client for interacting with Google's Gemini AI models, supporting all major API features including:

  • Text generation and chat conversations
  • JSON-structured outputs
  • Function calling
  • Safety settings and content filtering
  • System instructions
  • Model configuration (temperature, tokens, etc.)

Authentication

The client requires a Gemini API key which can be provided in two ways:

  • Environment variable: GEMINI_API_KEY
  • Programmatically: Client::new(api_key)

Basic Usage

#[tokio::main]
async fn main() -> gemini_rs::Result<()> {
    // Simple chat interaction
    let response = gemini_rs::chat("gemini-2.0-flash")
        .send_message("What is Rust's ownership model?")
        .await?;
    println!("{}", response);

    Ok(())
}

Advanced Features

The library supports advanced Gemini features through the Client and Chat types:

  • Model management (client().models())
  • Custom generation settings (chat.config_mut())
  • Safety settings (chat.safety_settings())
  • System instructions (chat.system_instruction())
  • Conversation history management (chat.history_mut())

Dependencies

~7–15MB
~241K SLoC