#gemini-api #sdk #gemini #client

gemini-client-api

Library to use Google Gemini API. Automatic context management, schema generation, function calling and more.

93 stable releases (6 major)

Uses new Rust 2024

7.4.5 Mar 10, 2026
7.1.3 Jan 31, 2026
6.5.2 Jan 30, 2026
5.8.1 Jan 25, 2026
0.1.1 Apr 8, 2025

#552 in Web programming

42 downloads per month
Used in pixie-anim

MIT license

88KB
2K SLoC

Gemini Client Library

A fast, flexible, and feature-rich Rust library for Google's Gemini API, featuring macros for automatic JSON schema generation and function calling. Supports all tools like Google search, maps, url etc.

Features

  • Automatic Context Management: Simple Session struct to handle conversation history.
  • Procedural Macros:
    • #[gemini_schema]: Generate JSON schemas directly from your Rust structs and enums.
    • #[gemini_function]: Turn Rust functions into Gemini-callable tools with minimal boilerplate.
    • execute_function_calls!: Seamlessly dispatch and handle multiple function calls requested by Gemini.
  • Multimodal Support: Built-in markdown parser for images and local files.
  • Advanced Capabilities: Code execution, PDF/document/audio reading, and "Thinking" mode support.
  • Context Caching: Efficiently manage and reuse large context windows.
  • Framework Agnostic: Modular design that works anywhere, including Actix, Axum, and WASM environments.

Basic Chat Example

use gemini_client_api::gemini::ask::Gemini;
use gemini_client_api::gemini::types::sessions::Session;

#[tokio::main]
async fn main() {
    let mut session = Session::new(10); // Keep last 10 messages
    let ai = Gemini::new(
        std::env::var("GEMINI_API_KEY").expect("GEMINI_API_KEY must be set"),
        "gemini-2.5-flash",
        None, // Optional system instruction
    );

    let response = ai.ask(session.ask("Hello, Gemini!")).await.unwrap();
    println!("Gemini: {}", response.get_chat().get_text_no_think("\n"));
}

Examples

  • Basic Chat: Simple request-response interaction.
  • Multimodal: Sending images and files to Gemini.
  • Streaming: Handling real-time chunks for a snappier UI experience.
  • Structured Output: Forcing Gemini to reply in a specific JSON format using #[gemini_schema].
  • Function Calling: Giving Gemini tools to interact with the real world using #[gemini_function].
  • Thinking Mode: Enabling Gemini's reasoning capabilities.
  • Context Caching: Creating and using cached content for large contexts.

For WASM environments, disable default features:

[dependencies]
gemini-client-api = { version = "...", default-features = false }

Change log

Dependencies

~3–20MB
~235K SLoC