gemini_rust/lib.rs
1//! # gemini-rust
2//!
3//! A Rust client library for Google's Gemini API.
4//!
5//! ## Crate Organization
6//!
7//! This crate is organized into domain-specific modules that align with the Gemini API's
8//! capabilities:
9//!
10//! - **`interactions`** - Interactions API (recommended) — unified interface for models and agents
11//! - **`generation`** - Legacy `generateContent` API (deprecated, still available)
12//! - **`embedding`** - Text embedding generation for semantic analysis
13//! - **`batch`** - Batch processing for multiple requests
14//! - **`files`** - File upload and management
15//! - **`cache`** - Content caching for reusable contexts
16//! - **`safety`** - Content moderation and safety settings
17//! - **`tools`** - Function calling and tool integration
18//! - **`file_search`** - Retrieval augmented generation (RAG)
19//! - **`models`** - Core primitive types shared across modules
20//! - **`prelude`** - Convenient re-exports of commonly used types
21//!
22//! ## Quick Start
23//!
24//! For most use cases, import from the prelude:
25//!
26//! ```rust
27//! use gemini_rust::prelude::*;
28//! ```
29//!
30//! For more specialized types, import them directly from the crate root or their
31//! respective modules.
32//!
33//! ### Interactions API (Recommended)
34//!
35//! The Interactions API is the simplest and best way to use Gemini models and agents:
36//!
37//! ```no_run
38//! # use gemini_rust::prelude::*;
39//! # async fn example(client: &Gemini) -> Result<(), Box<dyn std::error::Error>> {
40//! let interaction = client.create_interaction()
41//! .with_model("gemini-2.5-flash")
42//! .with_text("Hello, world!")
43//! .execute()
44//! .await?;
45//!
46//! println!("{}", interaction.output_text());
47//! # Ok(())
48//! # }
49//! ```
50
51pub mod client;
52mod models;
53
54/// Convenient re-exports of commonly used types
55pub mod prelude;
56
57/// Batch processing for multiple generation requests
58pub mod batch;
59
60/// Content caching for reusable contexts and system instructions
61pub mod cache;
62
63/// Common utilities and serialization helpers
64pub mod common;
65
66/// Text embedding generation for semantic analysis
67pub mod embedding;
68
69/// File upload and management
70pub mod files;
71
72/// Content generation including text, images, and audio
73pub mod generation;
74
75/// Interactions API — the modern interface for Gemini models and agents
76pub mod interactions;
77
78/// Content moderation and safety settings
79pub mod safety;
80
81/// Function calling and tool integration
82pub mod tools;
83
84/// File search for retrieval augmented generation (RAG)
85pub mod file_search;
86
87#[cfg(test)]
88mod tests;
89
90// ========== Core Types ==========
91// These are the fundamental types used throughout the API
92
93/// The main client error type
94pub use client::Error as ClientError;
95/// The main Gemini API client
96pub use client::Gemini;
97/// Builder for creating a new Gemini client
98pub use client::GeminiBuilder;
99/// Type alias for streaming generation responses
100pub use client::GenerationStream;
101/// Available Gemini models
102pub use client::Model;
103
104/// Core primitive types for building requests and parsing responses
105pub use models::{Blob, Content, FileData, Message, Modality, Part, Role};
106
107// ========== Content Generation ==========
108// Types for generating text, images, and audio content
109#[allow(deprecated)]
110pub use generation::{
111 builder::ContentBuilder, model::BlockReason, model::Candidate, model::CitationMetadata,
112 model::CitationSource, model::CountTokensResponse, model::FinishReason,
113 model::GenerateContentRequest, model::GenerationConfig, model::GenerationResponse,
114 model::GroundingChunk, model::GroundingMetadata, model::GroundingSegment,
115 model::GroundingSupport, model::MapsGroundingChunk, model::MediaResolution,
116 model::MediaResolutionLevel, model::MultiSpeakerVoiceConfig, model::PrebuiltVoiceConfig,
117 model::PromptFeedback, model::PromptTokenDetails, model::SpeakerVoiceConfig,
118 model::SpeechConfig, model::ThinkingConfig, model::ThinkingLevel, model::UsageMetadata,
119 model::VoiceConfig, model::WebGroundingChunk,
120};
121
122// ========== Interactions API ==========
123// Types for the Interactions API — the modern interface for Gemini models and agents
124
125pub use interactions::model::*;
126pub use interactions::{
127 InteractionBuilder, InteractionEvent, InteractionHandle, InteractionStream, StepDeltaData,
128};
129
130// ========== Text Embeddings ==========
131// Types for generating and working with text embeddings
132
133pub use embedding::{
134 builder::EmbedBuilder, model::BatchContentEmbeddingResponse, model::BatchEmbedContentsRequest,
135 model::ContentEmbedding, model::ContentEmbeddingResponse, model::EmbedContentRequest,
136 model::TaskType,
137};
138
139// ========== Safety & Content Filtering ==========
140// Types for content moderation and safety settings
141
142pub use safety::model::{
143 HarmBlockThreshold, HarmCategory, HarmProbability, SafetyRating, SafetySetting,
144};
145
146// ========== Function Calling & Tools ==========
147// Types for integrating external tools and function calling
148
149pub use tools::model::{
150 CodeExecutionConfig, CodeExecutionOutcome, CodeExecutionResult, CodeLanguage, ExecutableCode,
151 FunctionCall, FunctionCallingConfig, FunctionCallingMode, FunctionDeclaration,
152 FunctionResponse, GoogleMapsConfig, LatLng, RetrievalConfig, Tool, ToolConfig,
153};
154
155// ========== Batch Processing ==========
156// Types for processing multiple requests in batch operations
157
158pub use batch::{
159 builder::BatchBuilder, handle::BatchGenerationResponseItem, handle::BatchHandle,
160 handle::BatchHandle as Batch, handle::BatchStatus, handle::Error as BatchHandleError,
161 model::BatchConfig, model::BatchGenerateContentRequest, model::BatchOperation,
162 model::BatchStats, model::IndividualRequestError, model::RequestMetadata, Error as BatchError,
163};
164
165// ========== File Management ==========
166// Types for uploading and managing files
167
168pub use files::{
169 builder::FileBuilder, handle::FileHandle, model::File, model::FileState, Error as FilesError,
170};
171
172// ========== Content Caching ==========
173// Types for caching contexts and system instructions
174
175pub use cache::{
176 builder::CacheBuilder, handle::CachedContentHandle, model::CacheExpirationRequest,
177 model::CacheExpirationResponse, model::CachedContent, model::CreateCachedContentRequest,
178};
179
180// ========== File Search ==========
181// Types for file search and retrieval augmented generation (RAG)
182
183pub use file_search::{
184 model::ChunkingConfig, model::CustomMetadata, model::CustomMetadataValue, model::Document,
185 model::DocumentState, model::FileSearchStore, model::Operation, model::OperationResult,
186 model::Status, model::StringList, model::WhiteSpaceConfig, DocumentBuilder, DocumentHandle,
187 FileSearchStoreBuilder, FileSearchStoreHandle, ImportBuilder, OperationHandle, UploadBuilder,
188};