gemini-web2api  by Sophomoresty

Google Gemini as an OpenAI-compatible API

Created 2 weeks ago

New!

1,693 stars

Top 24.6% on SourcePulse

GitHubView on GitHub
Project Summary

This project provides an OpenAI-compatible API endpoint for Google Gemini, enabling developers to leverage Gemini's capabilities through familiar OpenAI SDKs and tools. It offers a zero-authentication, zero-cost solution, acting as a local proxy to bridge the gap between OpenAI's API format and Gemini's web interface, making advanced AI models accessible without direct integration complexities.

How It Works

The core of this project is a reverse-engineered proxy that intercepts and translates requests between the OpenAI API format and Google Gemini's internal web streaming protocol (StreamGenerateContent). It manipulates specific fields within Gemini's request payload, derived from analyzing the Gemini web application's JavaScript, to control model selection and features. This approach allows it to function as a drop-in replacement for OpenAI API calls, routing them to Gemini's backend.

Quick Start & Requirements

  • Primary install / run command: python gemini_web2api.py
  • Non-default prerequisites and dependencies: Python 3.8+ (stdlib only), network access to gemini.google.com (proxy/VPN may be required).
  • Estimated setup time or resource footprint: Minimal, as it's a single Python file with no external dependencies.
  • Relevant pages: No specific quick-start or demo links provided beyond the command-line execution.

Highlighted Details

  • OpenAI-compatible API endpoints (/v1/chat/completions, /v1/models).
  • Supports multiple Gemini models including Flash, Flash Thinking (up to 20k+ chars), Pro, Auto, and Lite.
  • Full function calling support in OpenAI format.
  • Adjustable "thinking depth" via @think=N suffix.
  • Built-in internet search capabilities inherited from Gemini.
  • SSE streaming support for responses.
  • Optional API key authentication.

Maintenance & Community

The project acknowledges contributions from "GenericAgent" and inspiration from the "linux.do community". No specific links to community channels, roadmaps, or active maintainer information are provided in the README.

Licensing & Compatibility

  • License type: MIT License.
  • Compatibility notes: Permissive MIT license allows for commercial use and integration into closed-source applications.

Limitations & Caveats

Image and multimodal input are not supported due to Gemini's reliance on proprietary RPC protocols. The "Pro" model requires a specific cookie for actual routing; otherwise, it defaults to the Flash model. Conversations are single-turn, with multi-turn context simulated by re-sending history. Users may encounter rate limiting from Google for high-frequency requests.

Health Check
Last Commit

6 days ago

Responsiveness

Inactive

Pull Requests (30d)
14
Issues (30d)
19
Star History
1,714 stars in the last 15 days

Explore Similar Projects

Feedback? Help us improve.