Promise-first TypeScript client & CLI for Google Gemini web chat
Multi-turn chat · Imagen 3 image generation · Google Image search · Multimodal upload · Keepalive · Polished terminal UI
# Clone the repository
git clone https://github.com/0xp47/nimji.git
cd nimji
# Install dependencies and build
npm install
npm run buildnimji connects directly to Gemini web's private StreamGenerate endpoint using your browser session credentials. You need three values from DevTools (Network tab → click any StreamGenerate request):
| Variable | Description & Location |
|---|---|
COOKIES |
Cookie: request header — full SID=…; HSID=…; … string |
AT_TOKEN |
at= field in the POST body |
F_SID |
f.sid= query parameter in the request URL |
Save them into a .env file in the root directory:
COOKIES="SID=g.a000…"
AT_TOKEN="ADR5zap…"
F_SID="-934583118011521981"Note: Credentials expire when you log out of Gemini or Chrome rotates session tokens. Re-copy fresh values from DevTools if requests start failing.
Starts a continuous interactive terminal session with multi-turn conversation memory:
npm run chat
# or
npm startInside the interactive chat:
- Type text to chat normally with Gemini.
- /draw
<prompt>— Generate high-resolution images via Imagen 3 (saved to./images/generated/) - /search
<query>— Search Google for images (saved to./images/searched/) - /attach
<path>— Attach a local image file to inspect in your next prompt - /reset — Clear conversation memory
- /exit — Quit the session
Sends a single prompt or command, prints the result, and exits.
npm start "Explain async/await in JavaScript"
npm start "/draw a majestic golden dragon flying over mountains"
npm start "/search cute red panda in snowy forest"Attach a local image to your prompt. nimji uploads it via Google's resumable upload endpoint (push.clients6.google.com) and sends the contribution token to Gemini.
npm start "describe this photo" ./sunset.jpgSupported formats: png, jpg / jpeg, webp, gif, svg, bmp, tiff.
import { create } from "nimji";
const client = create({
COOKIES: process.env.COOKIES ?? "",
AT_TOKEN: process.env.AT_TOKEN ?? "",
F_SID: process.env.F_SID ?? "",
});
const res = await client.generate({ prompt: "hello" });
if (res.ok) {
console.log(res.value.text);
}
client.stopKeepalive();import { loadConfigFromEnv, createClient, uploadImageToGemini } from "nimji";
const config = loadConfigFromEnv();
const client = createClient(config);
// 1. Upload local image to Google resumable upload endpoint
const attachment = await uploadImageToGemini(config, "./photo.png");
// 2. Pass attachment inside prompt generate call
const res = await client.generate({
prompt: "What is in this image?",
imageAttachment: attachment,
});
if (res.ok) {
console.log(res.value.text);
}Creates a client taking flat env-style keys (COOKIES, AT_TOKEN, F_SID, etc.).
| Option | Type | Description |
|---|---|---|
prompt |
string |
User prompt message |
includeImages |
boolean? |
Include extracted image URLs (default true) |
saveImages |
boolean? |
Download and save images locally |
imageOutputDir |
string? |
Destination directory (default ./images/generated) |
imageAttachment |
ImageAttachment? |
Pre-uploaded image token from uploadImageToGemini |
nimji automatically loads configuration from:
process.env/.envfile./config.jsoncor./config.jsonin the current directory~/.nimji/config.jsoncor~/.nimji/config.json
| Variable | Description |
|---|---|
COOKIES |
Full browser session cookie string |
AT_TOKEN |
Anti-CSRF token from the POST body |
F_SID |
Session identifier from the URL query |
# Build TypeScript
npm run build
# Run unit test suite (155 tests)
npm test
# Format code
npm run formatMIT © 0xp47