CLI tool for interacting with Google Gemini using browser session cookies (reverse-engineered web API).
Note: This project reverse-engineers Gemini's web interface. It may break if Google changes their API.
Instead of using the official Gemini API (which requires API keys), twin:
- Extracts your session cookies from Safari/Chrome/Firefox
- Uses those cookies to authenticate with Gemini's web interface
- Sends requests to the same API endpoints the web app uses
git clone https://github.com/kyupark/twin
cd twin
bun install
bun run build:binary
# Or run directly with bun
bun run dev --helpYou must be logged into gemini.google.com in one of these browsers:
- Safari (macOS)
- Chrome
- Firefox
./twin test-auth./twin chat "What is the capital of France?"./twin replREPL commands:
/new- Start a new conversation/help- Show helpexit- Exit the REPL
--psid <token> Google __Secure-1PSID cookie value (manual override)
--cookie-source <source> Browser to read cookies from (safari, chrome, firefox)
--chrome-profile <name> Chrome profile name
--firefox-profile <name> Firefox profile name
--timeout <ms> Request timeout in milliseconds
-v, --verbose Enable verbose output
Instead of browser cookies, you can provide credentials via environment variables:
export GEMINI_PSID="your_psid_cookie_value"
./twin chat "Hello"Google uses several cookies for session management:
| Cookie | Purpose |
|---|---|
__Secure-1PSID |
Main session ID (required) |
__Secure-1PSIDTS |
Session timestamp |
__Secure-1PSIDCC |
Session control |
The tool extracts these from your browser and uses them to make authenticated requests.
- May break at any time - Google can change their API without notice
- Session expiration - Cookies expire, you'll need to re-login periodically
- Rate limits - Subject to whatever rate limits Google applies to web users
- No official support - This is not an officially supported method
| Feature | twin (cookies) | Official Gemini API |
|---|---|---|
| Setup | Login to browser | Get API key |
| Cost | Free (uses your account) | Free tier available |
| Stability | May break | Stable |
| Rate limits | Unknown | Documented |
| Support | None | Official |
twin/
├── src/
│ ├── cli.ts # CLI entry point
│ ├── cli/
│ │ └── program.ts # Commander setup
│ ├── commands/
│ │ ├── chat.ts # Single message command
│ │ ├── repl.ts # Interactive REPL
│ │ └── test-auth.ts # Auth testing
│ └── lib/
│ ├── cookies.ts # Cookie extraction
│ ├── gemini-client.ts # API client
│ └── gemini-client-types.ts
├── package.json
└── README.md
Inspired by bird - a similar tool for Twitter/X.
MIT