This directory contains comprehensive examples demonstrating all features of the gemini-rust library. Each example is a complete, runnable program that showcases specific functionality.
Run any example with:
GEMINI_API_KEY="your-api-key" cargo run --example <example_name>Get your API key from Google AI Studio.
| Example | Description |
|---|---|
basic_generation.rs |
Simple content generation - best starting point for beginners |
basic_streaming.rs |
Simple streaming responses - real-time content display |
simple.rs |
Basic text generation and function calling - comprehensive example |
advanced.rs |
Advanced content generation with comprehensive parameter configuration |
test_api.rs |
Simple API connectivity test |
| Example | Description |
|---|---|
streaming.rs |
Real-time streaming responses for interactive applications |
generation_config.rs |
Custom generation parameters (temperature, tokens, etc.) |
structured_response.rs |
Generate structured JSON output with schema validation |
gemini_pro_example.rs |
Using Gemini 2.5 Pro for advanced tasks |
| Example | Description |
|---|---|
tools.rs |
Custom function declarations and tool integration |
complex_function.rs |
Advanced function calling with OpenAPI schema support using schemars |
google_search.rs |
Google Search tool integration for real-time information |
google_search_with_functions.rs |
Combining Google Search with custom functions |
curl_google_search.rs |
Google Search functionality with cURL equivalent commands |
url_context.rs |
URL Context tool for analyzing web content |
| Example | Description |
|---|---|
thinking_basic.rs |
Basic thinking mode for step-by-step reasoning |
thinking_advanced.rs |
Advanced thinking capabilities with custom budgets |
thinking_curl_equivalent.rs |
Thinking mode with cURL command equivalents |
simple_thought_signature.rs |
Simple thought signature examples |
text_thought_signature_example.rs |
Text-based thought signature demonstrations |
thought_signature_example.rs |
Comprehensive thought signature usage |
| Example | Description |
|---|---|
gemini_3_code_execution.rs |
Code execution with Python and tool integration |
gemini_3_thinking_and_media.rs |
Thinking levels and media resolution for Gemini 3 Pro |
gemini_3_all_thinking_levels.rs |
Demonstrate all 5 thinking levels (Minimal, Low, Medium, High) with Gemini 3 Flash |
| Example | Description |
|---|---|
batch_generate.rs |
Batch content generation for multiple requests |
batch_embedding.rs |
Batch text embedding generation |
batch_list.rs |
List and manage batch operations with streaming |
batch_cancel.rs |
Cancel running batch operations |
batch_delete.rs |
Delete completed batch operations |
| Example | Description |
|---|---|
cache_basic.rs |
Cache system instructions and conversation history for cost optimization |
| Example | Description |
|---|---|
embedding.rs |
Generate text embeddings with various task types |
| Example | Description |
|---|---|
blob.rs |
Process images and binary data with base64 encoding |
mp4_describe.rs |
Analyze and describe video content |
| Example | Description |
|---|---|
simple_image_generation.rs |
Basic text-to-image generation |
image_generation.rs |
Advanced image generation with detailed prompts |
image_editing.rs |
Edit existing images with text prompts |
| Example | Description |
|---|---|
simple_speech_generation.rs |
Basic text-to-speech generation |
multi_speaker_tts.rs |
Multi-speaker text-to-speech dialogue generation |
| Example | Description |
|---|---|
files_lifecycle.rs |
Complete file management lifecycle (upload, list, get, delete) |
files_usage.rs |
Upload and use file in a request |
files_delete_all.rs |
Bulk delete all uploaded files |
| Example | Description |
|---|---|
custom_models.rs |
Configure different Gemini models (Flash, Pro, Lite, custom models) with all available options |
custom_base_url.rs |
Use custom API endpoints and configurations |
http_client_builder.rs |
Advanced HTTP client configuration with timeouts, proxies, and connection pooling |
tracing_telemetry.rs |
Comprehensive tracing and telemetry setup for observability and monitoring |
curl_equivalent.rs |
See equivalent cURL commands for API calls |
| Example | Description |
|---|---|
error_handling.rs |
Comprehensive error handling patterns and best practices |
Start with simple.rs to understand the basic API usage:
GEMINI_API_KEY="your-api-key" cargo run --example simpleFor real-time applications, use streaming:
GEMINI_API_KEY="your-api-key" cargo run --example streamingLearn how to integrate custom functions:
GEMINI_API_KEY="your-api-key" cargo run --example tools
GEMINI_API_KEY="your-api-key" cargo run --example complex_functionExplore Gemini 2.5's reasoning capabilities:
GEMINI_API_KEY="your-api-key" cargo run --example thinking_basic
GEMINI_API_KEY="your-api-key" cargo run --example thinking_advancedFor high-throughput applications:
GEMINI_API_KEY="your-api-key" cargo run --example batch_generateWork with multimodal content:
GEMINI_API_KEY="your-api-key" cargo run --example blob
GEMINI_API_KEY="your-api-key" cargo run --example image_generation- All examples include comprehensive error handling
- Examples demonstrate both async/await patterns and streaming
- Code includes detailed comments explaining each step
- Examples use environment variables for API keys (never hardcode credentials)
- Some examples require specific model capabilities (e.g., image generation requires image-enabled models)
When adding new examples:
- Follow the existing naming conventions
- Include comprehensive error handling
- Add detailed comments explaining the functionality
- Update this README.md with the new example
- Ensure the example runs successfully with
cargo run --example <name>
The examples directory includes sample media files for testing:
image-example.webp- Sample image for image processing examplessample.mp4- Sample video for video analysis examples
These files are used by various examples to demonstrate multimodal capabilities.