<p align="center">
<img src="assets/hero-banner.png" alt="hero pane" width="980">
</p>
<p align="center">
<a href="https://crates.io/crates/gemini-chat-api"><img src="https://img.shields.io/badge/crates.io-gemini--chat--api-F59E0B?style=for-the-badge&logo=rust&logoColor=white" alt="Crates.io"></a>
<a href="https://docs.rs/gemini-chat-api"><img src="https://img.shields.io/badge/docs.rs-gemini--chat--api-3B82F6?style=for-the-badge&logo=readthedocs&logoColor=white" alt="Documentation"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-8B5CF6?style=for-the-badge" alt="MIT License"></a>
<a href="https://github.com/woldp001/guerrillamail-client-rs/pulls"><img src="https://img.shields.io/badge/PRs-Welcome-22C55E?style=for-the-badge" alt="PRs Welcome"></a>
</p>
<p align="center">
<a href="#features">Features</a> · <a href="#installation">Installation</a> · <a href="#usage">Usage</a> · <a href="#quick-start">Quick Start</a> · <a href="#documentation">Documentation</a> · <a href="#contributing">Contributing</a> · <a href="#acknowledgements">Acknowledgements</a> · <a href="#support">Support</a> · <a href="#license">License</a>
</p>
---
## Features
- **Asynchronous**: Built on `tokio` and `reqwest` for non-blocking I/O.
- **Conversation Management**: Maintains chat history and context.
- **File & Image Uploads**: Support for sending images and files in prompts.
- **Multiple Models**: Support for Gemini 2.0 Flash, 2.5 Pro, and others.
- **Auto-Rotation**: Automatically rotates cookies to keep the session alive.
- **Browser Impersonation**: Mimics Chrome headers to ensure successful authentication.
> **Note**: Image generation and downloading features from the Python library are **not** supported in this Rust port. This client focuses on chat and text interaction.
## Installation
Add the following to your `Cargo.toml`:
```toml
[dependencies]
gemini-chat-api = "0.1.4"
```
(Or path dependency if working locally)
## Usage
### Prerequisites
You need to obtain your `__Secure-1PSID` and `__Secure-1PSIDTS` cookies from Google Gemini.
1. Go to [https://gemini.google.com/app](https://gemini.google.com/app)
2. Open your browser's developer tools (F12).
3. Go to the "Application" (or "Storage") tab.
4. Under "Cookies" -> "https://gemini.google.com", find the `__Secure-1PSID` and `__Secure-1PSIDTS` cookies.
5. Create a JSON file (e.g., `cookies.json`) with the following format:
```json
[
{
"name": "__Secure-1PSID",
"value": "YOUR_VALUE_HERE"
},
{
"name": "__Secure-1PSIDTS",
"value": "YOUR_VALUE_HERE"
}
]
```
### Quick Start
```rust
use gemini_chat_api::{utils::load_cookies, AsyncChatbot, Model};
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Load cookies from file
let (secure_1psid, secure_1psidts) = load_cookies("cookies.json")?;
println!("Cookies loaded successfully.");
// Initialize chatbot with 30s timeout
let mut chatbot = AsyncChatbot::new(
&secure_1psid,
&secure_1psidts,
Model::G2_5Pro,
None, // No proxy
30, // Timeout in seconds
)
.await?;
println!("Chatbot initialized.");
// Ask a question
println!("Sending message: 'Hello from Rust example!'");
let response = chatbot.ask("Hello from Rust example!", None).await?;
println!("--------------------------------------------------");
println!("Gemini Response:");
println!("{}", response.content);
println!("--------------------------------------------------");
Ok(())
}
```
## Documentation
For detailed API documentation, visit [docs.rs/gemini-chat-api](https://docs.rs/gemini-chat-api).
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/cool-feature`)
3. Commit your changes (`git commit -m 'Add some cool feature'`)
4. Push to the branch (`git push origin feature/cool-feature`)
5. Open a Pull Request
## Acknowledgements
This project is a Rust port of the [Python Gemini-Chat-API](https://github.com/OEvortex/Gemini-Chat-API) by [OEvortex](https://github.com/OEvortex). Special thanks to the original author for their work on reverse-engineering the Gemini API.
## Support
If this crate saves you time or helps your work, support is appreciated:
[](https://ko-fi.com/11philip22)
## License
This project is licensed under the MIT License; see the [license](https://opensource.org/licenses/MIT) for details.