Gemini Chat API (Rust)
This Rust crate provides an unofficial client for interacting with Google's internal Gemini API. It is a port of the Python gemini-chat-api and is 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:
[]
= { = "https://git.woldtech.nl/woldtech/gemini-chat-api-rs.git" }
= { = "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.
License
This project is licensed under the MIT License - see the LICENSE file for details.