Skip to main content

Crate genai_rs

Crate genai_rs 

Source
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(genai_rs::DEFAULT_MODEL)
        .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 (_ => ...)
  • Unknown variants: 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

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::GoogleMapsResultItem;
pub use content::GoogleSearchResultItem;
pub use content::Place;
pub use content::Resolution;
pub use content::ReviewSnippet;
pub use content::UrlContextResultItem;
pub use steps::FunctionResultPayload;
pub use steps::Step;
pub use steps::StepDelta;
pub use steps::StepError;
pub use request::AgentConfig;
pub use request::AntigravityConfig;
pub use request::DeepResearchConfig;
pub use request::DynamicConfig;
pub use request::GenerationConfig;
pub use request::ImageAspectRatio;
pub use request::ImageConfig;
pub use request::ImageSize;
pub use request::InteractionInput;
pub use request::InteractionRequest;
pub use request::Role;
pub use request::ServiceTier;
pub use request::SpeechConfig;
pub use request::ThinkingLevel;
pub use request::ThinkingSummaries;
pub use request::TranscriptionConfig;
pub use request::TurnContent;
pub use request::VideoConfig;
pub use request::VideoTask;
pub use request::Visualization;
pub use response_format::ResponseDelivery;
pub use response_format::ResponseFormat;
pub use response_format::ResponseFormatSpec;
pub use environment::AllowlistEntry;
pub use environment::EnvironmentSource;
pub use environment::EnvironmentSpec;
pub use environment::NetworkConfig;
pub use environment::RemoteEnvironment;
pub use environment::SourceType;
pub use triggers::Trigger;
pub use triggers::TriggerCreateParams;
pub use triggers::TriggerExecution;
pub use triggers::TriggerExecutionListResponse;
pub use triggers::TriggerExecutionStatus;
pub use triggers::TriggerListResponse;
pub use triggers::TriggerStatus;
pub use triggers::TriggerUpdate;
pub use environments::CreateEnvironmentRequest;
pub use environments::Environment;
pub use environments::EnvironmentListResponse;
pub use environments::EnvironmentStatus;
pub use safety::HarmCategory;
pub use safety::SafetyMethod;
pub use safety::SafetySetting;
pub use safety::SafetyThreshold;
pub use agents::Agent;
pub use agents::AgentListResponse;
pub use webhooks::RevocationBehavior;
pub use webhooks::RotateSigningSecretResponse;
pub use webhooks::SigningSecret;
pub use webhooks::Webhook;
pub use webhooks::WebhookConfig;
pub use webhooks::WebhookEvent;
pub use webhooks::WebhookListResponse;
pub use webhooks::WebhookState;
pub use webhooks::WebhookUpdate;
pub use response::AudioInfo;
pub use response::CodeExecutionCallInfo;
pub use response::CodeExecutionResultInfo;
pub use response::FunctionCallInfo;
pub use response::FunctionResultInfo;
pub use response::GoogleMapsResultInfo;
pub use response::GroundingToolCount;
pub use response::ImageInfo;
pub use response::InteractionResponse;
pub use response::InteractionStatus;
pub use response::ModalityTokens;
pub use response::OwnedFunctionCallInfo;
pub use response::StepSummary;
pub use response::UrlContextResultInfo;
pub use response::UsageMetadata;
pub use tools::AllowedTools;
pub use tools::ComputerUseConfig;
pub use tools::ExaAiSearchConfig;
pub use tools::FileSearchConfig;
pub use tools::FunctionCallingMode;
pub use tools::FunctionDeclaration;
pub use tools::FunctionDeclarationBuilder;
pub use tools::FunctionParameters;
pub use tools::GoogleMapsConfig;
pub use tools::GoogleSearchConfig;
pub use tools::HybridSearchConfig;
pub use tools::McpServerConfig;
pub use tools::ParallelAiSearchConfig;
pub use tools::RagFilter;
pub use tools::RagRanking;
pub use tools::RagResource;
pub use tools::RagRetrievalConfig;
pub use tools::RagStoreConfig;
pub use tools::RetrievalConfig;
pub use tools::RetrievalType;
pub use tools::SearchType;
pub use tools::Tool;
pub use tools::ToolChoice;
pub use tools::VertexAiSearchConfig;
pub use wire_streaming::InteractionStreamEvent;
pub use wire_streaming::StreamChunk;
pub use wire_streaming::StreamEvent;
pub use wire_streaming::StreamMetadata;
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§

agents
Agent resource types for the /v1beta/agents API.
antigravity
Native client for Google’s Antigravity localharness agent runtime.
client
content
Content types for the Interactions API.
environment
Environment types for the environment request field and the Agents resource’s base_environment.
environments
Environments resource (/v1beta/environments).
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.
response_format
Typed response_format union for interaction requests.
safety
Safety settings for interaction requests.
steps
Step types for the Interactions API (revision 2026-05-20).
streaming
Streaming types for automatic function calling.
tools
triggers
Triggers resource (/v1beta/triggers) — server-side scheduled interactions.
webhooks
Webhook types for the /v1beta/webhooks resource and the per-request webhook_config field.
wire
Wire-level inspection of HTTP traffic.
wire_streaming
Streaming types for SSE responses (API revision 2026-05-20).

Structs§

FileError
Error information for failed file operations.
FileMetadata
Represents an uploaded file in the Files API.
ListFilesResponse
Response from listing files.
ResumableUpload
Handle to a resumable upload session.
VideoMetadata
Metadata for video files.

Enums§

FileState
Processing state of an uploaded file.

Constants§

DEFAULT_CHUNK_SIZE
Default chunk size for chunked uploads (8 MB).
DEFAULT_IMAGE_MODEL
The model to use for image generation.
DEFAULT_MODEL
The model this crate is developed and verified against.
DEFAULT_TTS_MODEL
The model to use for text-to-speech.
INLINE_VIDEO_MODEL
A model that accepts inline (base64) video bytes, which DEFAULT_MODEL does not.
MINIMAL_THINKING_MODEL
A model that supports ThinkingLevel::Minimal, which DEFAULT_MODEL does not.