gemini-apits
v1.11.1
Published
TypeScript wrapper for Google Gemini web app
Downloads
100
Readme
Gemini API TypeScript
This is a TypeScript wrapper for the Google Gemini web app (formerly Bard). It allows you to interact with Gemini programmatically.
Installation
npm installUsage
Initialization
You need __Secure-1PSID and __Secure-1PSIDTS cookies from your browser (logged into gemini.google.com).
How to get cookies
- Go to https://gemini.google.com/ and log in with your Google account.
- Press
F12or right-click and select "Inspect" to open Developer Tools. - Go to the Application tab (Chrome/Edge) or Storage tab (Firefox).
- Expand Cookies in the left sidebar and select
https://gemini.google.com. - Find the row with Name
__Secure-1PSIDand copy its Value. - Find the row with Name
__Secure-1PSIDTSand copy its Value.
import { GeminiClient } from "./client";
const secure1psid = "YOUR___Secure-1PSID";
const secure1psidts = "YOUR___Secure-1PSIDTS";
async function main() {
const client = new GeminiClient(secure1psid, secure1psidts);
await client.init({ verbose: true });
const response = await client.generateContent("Hello, how are you?");
console.log(response.text);
}
main();Chat Session
const chat = client.startChat();
const response1 = await chat.sendMessage("Tell me a joke");
console.log(response1.text);
const response2 = await chat.sendMessage("Explain it");
console.log(response2.text);Image Generation
const response = await client.generateContent("Generate an image of a cat");
console.log(response.images);File Upload
const response = await client.generateContent("Describe this image", ["path/to/image.jpg"]);
console.log(response.text);Proxies
You can use a proxy by passing the proxy argument to the constructor.
const client = new GeminiClient(secure1psid, secure1psidts, "http://user:pass@host:port");Disclaimer
This is an unofficial API and is not affiliated with Google. Use it at your own risk.
