gemini-chat-api is an async Rust client for the same Gemini web chat endpoints used by the browser UI. It authenticates with Gemini cookies, sends text prompts, optionally uploads image bytes, and keeps conversation metadata so follow-up messages continue the same thread.
[!IMPORTANT] This crate talks to Gemini's web endpoints, not the official Google Gemini API. Endpoint behavior can change without notice, and valid browser cookies are required.
Features
- Async-first client built on
tokioandreqwest. - Cookie-based authentication with
__Secure-1PSIDand__Secure-1PSIDTS. - Stateful conversations across multiple
askcalls. - Optional image upload support for multimodal prompts.
- Selectable Gemini model headers, including Flash, Pro, and thinking variants.
- Proxy and timeout configuration through the client constructor.
- JSON save/load helpers for conversation state.
Installation
Add the crate to your Cargo.toml:
[]
= "0.1.5"
= { = "1", = ["full"] }
Authentication
Export the required cookies from an authenticated Gemini browser session at gemini.google.com:
Save them as cookies.json, then load them with load_cookies.
[!CAUTION] Treat
cookies.jsonlike a password. Do not commit it or share it.
Quick Start
use ;
async
Run the included interactive example:
Image Input
Pass image bytes as the second argument to ask:
use ;
async
Conversation State
AsyncChatbot keeps the latest conversation IDs internally, so follow-up prompts continue the same Gemini thread:
let first = chatbot.ask.await?;
let second = chatbot.ask.await?;
chatbot.reset;
let fresh = chatbot.ask.await?;
You can also persist and restore conversations:
chatbot.save_conversation.await?;
let loaded = chatbot.load_conversation.await?;
Models
Use Model::default() for the endpoint default, or select a specific model:
use Model;
let model = G3_0Pro;
Available variants include:
Model::G2_0FlashModel::G2_0FlashThinkingModel::G2_5FlashModel::G2_5ProModel::G2_0ExpAdvancedModel::G2_5ExpAdvancedModel::G3_0ProModel::G3_0FlashModel::G3_0Thinking
Acknowledgements
This crate is a Rust port inspired by OEvortex/Gemini-Chat-API.