Gemini Chat API (Rust)
This Rust crate provides an unofficial client for interacting with Google's internal Gemini API, built using reqwest for efficient and authenticated HTTP requests.
Features
- Asynchronous: Built on
tokioandreqwestfor 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:
[]
= "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.
- Go to https://gemini.google.com/app
- Open your browser's developer tools (F12).
- Go to the "Application" (or "Storage") tab.
- Under "Cookies" -> "https://gemini.google.com", find the
__Secure-1PSIDand__Secure-1PSIDTScookies. - Create a JSON file (e.g.,
cookies.json) with the following format:
Quick Start
use ;
use Error;
async
Documentation
For detailed API documentation, visit docs.rs/gemini-chat-api.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/cool-feature) - Commit your changes (
git commit -m 'Add some cool feature') - Push to the branch (
git push origin feature/cool-feature) - Open a Pull Request
Acknowledgements
This project is a Rust port of the Python Gemini-Chat-API by 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:
License
This project is licensed under the MIT License; see the license file for details.