| Crates.io | gemini-chat-api |
| lib.rs | gemini-chat-api |
| version | 0.1.0 |
| created_at | 2026-01-11 18:41:54.212167+00 |
| updated_at | 2026-01-11 18:41:54.212167+00 |
| description | Async Rust client for Google's internal Gemini Chat API |
| homepage | |
| repository | https://github.com/11philip22/gemini-chat-api-rs |
| max_upload_size | |
| id | 2036192 |
| size | 85,667 |
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.
tokio and reqwest for non-blocking I/O.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.
Add the following to your Cargo.toml:
[dependencies]
gemini-chat-api = { git = "https://git.woldtech.nl/woldtech/gemini-chat-api-rs.git" }
tokio = { version = "1", features = ["full"] }
reqwest = { version = "0.12", features = ["json", "multipart", "cookies"] }
serde_json = "1.0"
(Or path dependency if working locally)
You need to obtain your __Secure-1PSID and __Secure-1PSIDTS cookies from Google Gemini.
__Secure-1PSID and __Secure-1PSIDTS cookies.cookies.json) with the following format:[
{
"name": "__Secure-1PSID",
"value": "YOUR_VALUE_HERE"
},
{
"name": "__Secure-1PSIDTS",
"value": "YOUR_VALUE_HERE"
}
]
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(())
}
client: Contains the AsyncChatbot struct for managing sessions.enums: Defines Endpoint, Headers, and Model enums.utils: Helpers like load_cookies and upload_file.error: Custom Error types.This project is licensed under the MIT License - see the LICENSE file for details.