gemini-rust
A comprehensive Rust client library for Google's Gemini 2.5 API.
✨ Features
- 🚀 Complete Gemini 2.5 API Implementation - Full support for all Gemini API endpoints
- 🛠️ Function Calling & Tools - Custom functions and Google Search integration
- 📦 Batch Processing - Efficient batch content generation and embedding
- 🔄 Streaming Responses - Real-time streaming of generated content
- 🧠 Thinking Mode - Support for Gemini 2.5 thinking capabilities
- 🖼️ Multimodal Support - Images and binary data processing
- 📊 Text Embeddings - Advanced embedding generation with multiple task types
- ⚙️ Highly Configurable - Custom models, endpoints, and generation parameters
- 🔒 Type Safe - Comprehensive type definitions with full
serde
support - ⚡ Async/Await - Built on
tokio
for high-performance async operations
📦 Installation
Add this to your Cargo.toml
:
[]
= "1.2.1"
🚀 Quick Start
Basic Content Generation
use Gemini;
async
Streaming Responses
use Gemini;
use StreamExt;
async
🛠️ Advanced Features
Function Calling
use ;
async
Google Search Tool
use ;
async
Thinking Mode (Gemini 2.5)
use Gemini;
async
Text Embeddings
use ;
async
Batch Processing
use ;
async
Image Processing
use ;
async
Generation Configuration
use ;
async
🔧 Configuration
Custom Models
use Gemini;
// Use Gemini 2.5 Flash (default)
let client = new;
// Use Gemini 2.5 Pro for advanced tasks
let client = pro;
// Use specific model
let client = with_model;
Custom Base URL
use Gemini;
// Custom endpoint
let client = with_base_url;
// Custom model and endpoint
let client = with_model_and_base_url;
📚 Examples
The repository includes comprehensive examples:
Example | Description |
---|---|
simple.rs |
Basic text generation and function calling |
advanced.rs |
Advanced content generation with all parameters |
streaming.rs |
Real-time streaming responses |
tools.rs |
Custom function declarations |
google_search.rs |
Google Search integration |
google_search_with_functions.rs |
Google Search with custom functions |
thinking_basic.rs |
Gemini 2.5 thinking mode (basic) |
thinking_advanced.rs |
Gemini 2.5 thinking mode (advanced) |
batch_generate.rs |
Batch content generation |
batch_cancel.rs |
Batch operation cancellation |
batch_delete.rs |
Batch operation deletion |
batch_list.rs |
Batch operation listing with streaming |
batch_embedding.rs |
Batch text embedding generation |
embedding.rs |
Text embedding generation |
blob.rs |
Image and binary data processing |
structured_response.rs |
Structured JSON output |
generation_config.rs |
Custom generation parameters |
custom_base_url.rs |
Using a custom API endpoint |
curl_equivalent.rs |
Equivalent cURL commands for API calls |
Run an example:
GEMINI_API_KEY="your-api-key"
🔑 API Key Setup
Get your API key from Google AI Studio and set it as an environment variable:
🚦 Supported Models
- Gemini 2.5 Flash - Fast, efficient model (default)
- Gemini 2.5 Pro - Advanced model with thinking capabilities
- Gemini 1.5 Flash - Previous generation fast model
- Gemini 1.5 Pro - Previous generation advanced model
- Text Embedding 004 - Latest embedding model
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Google for providing the Gemini API
- The Rust community for excellent async and HTTP libraries
- All contributors who have helped improve this library