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.1"
= { = "1", = ["full"] }
= { = "0.12", = ["json", "multipart", "cookies"] }
= "1.0"
(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
Modules
client: Contains theAsyncChatbotstruct for managing sessions.enums: DefinesEndpoint,Headers, andModelenums.utils: Helpers likeload_cookiesandupload_file.error: CustomErrortypes.
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.
Contributing
PRs are welcome!
Please run cargo fmt and cargo clippy before submitting.
If you’re changing behavior, please document it in the PR.
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.