Expand description
§genai-rs
A Rust client library for Google’s Generative AI (Gemini) API using the Interactions API.
§Quick Start
use genai_rs::Client;
#[tokio::main]
async fn main() -> Result<(), genai_rs::GenaiError> {
let client = Client::new(
std::env::var("GEMINI_API_KEY").expect("GEMINI_API_KEY not set")
);
let response = client
.interaction()
.with_model("gemini-3-flash-preview")
.with_text("Hello, Gemini!")
.create()
.await?;
println!("{}", response.as_text().unwrap_or("No response"));
Ok(())
}§Features
- Fluent Builder API: Chain methods for readable request construction
- Streaming: Real-time response streaming with
create_stream() - Function Calling: Automatic function discovery and execution via macros
- Built-in Tools: Google Search, Code Execution, URL Context
- Multimodal: Images, audio, video, and document inputs
- Thinking Mode: Access model reasoning with configurable levels
§API Stability & Forward Compatibility
This library is designed for forward compatibility with evolving APIs:
#[non_exhaustive]enums: Match statements require wildcard arms (_ => ...)Unknownvariants: Unrecognized API types are captured, not rejected- Graceful degradation: New API features won’t break existing code
When Google adds new features, your code continues to work. Unknown content types
and tools are preserved for inspection via helper methods like has_unknown().
§Module Organization
Client: Main entry point for API interactionsInteractionBuilder: Fluent builder for configuring requestsinteractions_api: Helper functions for constructing contentfunction_calling: Function registration and execution
Re-exports§
pub use errors::GenaiError;pub use content::Annotation;pub use content::CodeExecutionLanguage;pub use content::Content;pub use content::FileSearchResultItem;pub use content::GoogleSearchResultItem;pub use content::Resolution;pub use content::UrlContextResultItem;pub use request::AgentConfig;pub use request::DeepResearchConfig;pub use request::DynamicConfig;pub use request::GenerationConfig;pub use request::InteractionInput;pub use request::InteractionRequest;pub use request::Role;pub use request::SpeechConfig;pub use request::ThinkingLevel;pub use request::ThinkingSummaries;pub use request::Turn;pub use request::TurnContent;pub use response::AudioInfo;pub use response::CodeExecutionCallInfo;pub use response::CodeExecutionResultInfo;pub use response::ContentSummary;pub use response::FunctionCallInfo;pub use response::FunctionResultInfo;pub use response::GroundingChunk;pub use response::GroundingMetadata;pub use response::ImageInfo;pub use response::InteractionResponse;pub use response::InteractionStatus;pub use response::ModalityTokens;pub use response::OwnedFunctionCallInfo;pub use response::UrlContextMetadata;pub use response::UrlContextResultInfo;pub use response::UrlMetadataEntry;pub use response::UrlRetrievalStatus;pub use response::UsageMetadata;pub use response::WebSource;pub use tools::FunctionCallingMode;pub use tools::FunctionDeclaration;pub use tools::FunctionDeclarationBuilder;pub use tools::FunctionParameters;pub use tools::Tool;pub use wire_streaming::InteractionStreamEvent;pub use wire_streaming::StreamChunk;pub use wire_streaming::StreamEvent;pub use client::Client;pub use client::ClientBuilder;pub use request_builder::ConversationBuilder;pub use request_builder::InteractionBuilder;pub use function_calling::CallableFunction;pub use function_calling::FunctionError;pub use function_calling::ToolService;pub use streaming::AutoFunctionResult;pub use streaming::AutoFunctionResultAccumulator;pub use streaming::AutoFunctionStreamChunk;pub use streaming::AutoFunctionStreamEvent;pub use streaming::FunctionExecutionResult;pub use streaming::PendingFunctionCall;pub use multimodal::audio_from_file;pub use multimodal::audio_from_file_with_mime;pub use multimodal::detect_mime_type;pub use multimodal::document_from_file;pub use multimodal::document_from_file_with_mime;pub use multimodal::image_from_file;pub use multimodal::image_from_file_with_mime;pub use multimodal::video_from_file;pub use multimodal::video_from_file_with_mime;
Modules§
- client
- content
- Core content types for the Interactions API.
- errors
- function_
calling - interactions_
api - multimodal
- Multimodal content utilities for file loading and MIME type detection.
- request
- Request types for creating interactions.
- request_
builder - response
- Response types for the Interactions API.
- streaming
- Streaming types for automatic function calling.
- tools
- wire_
streaming - Streaming types for SSE responses.
Structs§
- File
Error - Error information for failed file operations.
- File
Metadata - Represents an uploaded file in the Files API.
- List
Files Response - Response from listing files.
- Resumable
Upload - Handle to a resumable upload session.
- Video
Metadata - Metadata for video files.
Enums§
- File
State - Processing state of an uploaded file.
Constants§
- DEFAULT_
CHUNK_ SIZE - Default chunk size for chunked uploads (8 MB).