A lightweight FastAPI server that exposes an Anthropic-style /v1/messages API backed by Google's Gemini web interface. This allows you to use Gemini models with any tool that supports the Anthropic API format (like Claude Code, Cursor, Continue.dev, etc.).
- Anthropic-Compatible API: Use Gemini with tools expecting Anthropic's API format
- Asynchronous & Fast: Built with FastAPI and Uvicorn for high performance
- No Official API Key Required: Uses your browser cookies instead of paid API credits
- Streaming Support: Full SSE (Server-Sent Events) streaming responses
- Multiple Models: Supports
gemini-3-flashandgemini-3-pro - Simple Configuration: Easy cookie-based authentication
- Lightweight: Minimal dependencies
- Python 3.8+
- A Google account with access to Gemini
- Chrome/Firefox browser to extract cookies
git clone https://github.com/IMApurbo/gemini_server
cd gemini-serverpip install -r requirements.txtOr install directly:
pip install fastapi uvicorn gemini-webapi python-multipartThe server requires two cookies to authenticate with Gemini:
-
Open gemini.google.com in Chrome/Firefox
-
Log in to your Google account
-
Open Developer Tools:
- Chrome:
F12or right-click β Inspect - Firefox:
F12or right-click β Inspect Element
- Chrome:
-
Find the cookies:
Chrome:
- Go to the Application tab
- Click Cookies β
https://gemini.google.com - Look for
__Secure-1PSIDand__Secure-1PSIDTS
Firefox:
- Go to the Storage tab
- Click Cookies β
https://gemini.google.com - Look for
__Secure-1PSIDand__Secure-1PSIDTS
-
Copy the full value of each cookie (they're long strings)
On first run, the server will prompt you for the cookies:
python server.pyIt will ask:
Gemini cookie '__Secure-1PSID' is not set in config.json.
Enter __Secure-1PSID: [paste your cookie here]
Gemini cookie '__Secure-1PSIDTS' is not set in config.json.
Enter __Secure-1PSIDTS: [paste your cookie here]
You can also create a config.json file manually:
{
"secure_1psid": "YOUR_1PSID_VALUE",
"secure_1psidts": "YOUR_1PSIDTS_VALUE"
}You can customize the server using environment variables:
export SERVER_HOST="0.0.0.0" # Default: 0.0.0.0
export SERVER_PORT="8765" # Default: 8765python server.pyYou should see output like:
Starting Anthropic-style server...
INFO: Started server process [12345]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8765
curl http://localhost:8765/Response:
{
"status": "ok",
"message": "Gemini-server Anthropic-style server is running."
}If Claude Code supports custom API endpoints, add this to your configuration:
{
"api": {
"base_url": "http://localhost:8765",
"api_key": "dummy-key"
}
}export ANTHROPIC_API_URL="http://localhost:8765/v1/messages"
export ANTHROPIC_API_KEY="dummy-key"When running Claude Code, specify the endpoint:
claude --api-url http://localhost:8765 --api-key dummy-keyHealth check endpoint.
List available models.
Response:
{
"data": [
{"id": "gemini-3-flash", "object": "model"},
{"id": "gemini-3-pro", "object": "model"}
]
}Send a message to Gemini.
Request:
{
"model": "gemini-3-flash",
"messages": [
{"role": "user", "content": "Hello, how are you?"}
],
"system": "You are a helpful assistant.",
"stream": false
}Response (non-streaming):
{
"id": "msg_abc123def456",
"type": "message",
"role": "assistant",
"model": "gemini-3-flash",
"content": [
{
"type": "text",
"text": "Hello! I'm doing well, thank you for asking..."
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 12,
"output_tokens": 25
}
}curl -X POST http://localhost:8765/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-flash",
"messages": [
{"role": "user", "content": "What is the capital of France?"}
]
}'curl -X POST http://localhost:8765/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3-flash",
"messages": [
{"role": "user", "content": "Tell me a short story"}
],
"stream": true
}'import requests
response = requests.post(
"http://localhost:8765/v1/messages",
json={
"model": "gemini-3-flash",
"messages": [
{"role": "user", "content": "Explain quantum computing in simple terms"}
]
}
)
print(response.json()["content"][0]["text"])If you see errors like:
RuntimeError: Could not find SNlM0e token - your cookies are likely invalid or expired
Your cookies have expired. Simply get fresh cookies from Gemini and update config.json.
- Stay logged into Google in your browser
- Visit gemini.google.com occasionally
- The free tier has usage limits, so use judiciously
If the server isn't accessible:
- Check if it's running:
ps aux | grep server.py - Check the port:
netstat -tulpn | grep 8765 - Try changing the port:
export SERVER_PORT=8766
Gemini has usage limits. If you hit them, you'll receive errors. Wait a few minutes and try again.
- Local Network: The server binds to
0.0.0.0by default, making it accessible on your network - No Authentication: The server doesn't implement API key validation
- Cookie Storage: Your cookies are stored in plaintext in
config.json - Recommendations:
- Use a firewall to restrict access
- Change
HOSTto127.0.0.1for local-only access - Don't expose the server to the public internet
βββββββββββββββ HTTP Request ββββββββββββββββββββ
β Client β ββββββββββββββββββ> β FastAPI App β
β (Claude Codeβ /v1/messages β (server.py) β
β Cursor, β β β
β etc.) β ββββββββββ¬ββββββββββ
βββββββββββββββ β
βΌ
ββββββββββββββββββββ
β GeminiClient β
β (gemini_webapi) β
ββββββββββ¬ββββββββββ
β
βΌ
ββββββββββββββββββββ
β Gemini Web β
β (gemini.google) β
ββββββββββββββββββββ
- fastapi: Web framework
- uvicorn: ASGI server
- gemini-webapi: Gemini web client
- python-multipart: Form data parsing
Contributions are welcome! Please feel free to submit issues and pull requests.
MIT License - feel free to use this for any purpose.
- Claude Code: Use Gemini as a replacement for Claude
- Cursor IDE: Use Gemini with Cursor's AI features
- Continue.dev: Use Gemini with Continue's coding assistant
- Custom Tools: Any tool that supports Anthropic's API format
- Testing: Test Gemini without paying for API credits
- Development: Develop applications with Gemini's capabilities
If you encounter issues:
- Check the troubleshooting section
- Verify your cookies are correct
- Check the logs for error messages
- Open an issue on GitHub
To completely remove the server:
# Remove the directory
rm -rf gemini-server
# Or if using pip
pip uninstall fastapi uvicorn gemini-webapiHappy Coding! π