geminicli2api  by gzzhongqi

Gemini API proxy for OpenAI-compatible and native access

Created 4 months ago
293 stars

Top 90.0% on SourcePulse

GitHubView on GitHub
Project Summary

This project provides a FastAPI-based proxy server that exposes Google's Gemini API through both OpenAI-compatible and native Gemini API endpoints. It enables developers to leverage Google's free Gemini API quota using familiar OpenAI libraries or direct Gemini API calls, streamlining integration for applications already built around the OpenAI API standard.

How It Works

The core of the project is a FastAPI application acting as a reverse proxy. It intercepts requests intended for OpenAI or Gemini APIs and forwards them to the actual Google Gemini API endpoints. This abstraction layer allows for seamless integration, offering compatibility with existing OpenAI client libraries while enabling access to Gemini's capabilities, including multimodal inputs and advanced reasoning features.

Quick Start & Requirements

  • Primary Install/Run: Docker is the primary deployment method. Build the image using docker build -t geminicli2api . and run using docker run. Docker Compose configurations are also provided.
  • Prerequisites: Docker, environment variables for authentication and project configuration.
  • Environment Variables: GEMINI_AUTH_PASSWORD (required), and one of GEMINI_CREDENTIALS (JSON string), GOOGLE_APPLICATION_CREDENTIALS (file path), or GOOGLE_CLOUD_PROJECT/GEMINI_PROJECT_ID.
  • Ports: 8888 (default/compatibility) or 7860 (Hugging Face compatible).
  • Links: Hugging Face Spaces deployment is supported. Example Python code for OpenAI and native Gemini API usage is provided.

Highlighted Details

  • OpenAI Compatibility: Offers a drop-in replacement for OpenAI's chat completions API (/v1/chat/completions) and model listing (/v1/models).
  • Native Gemini API Proxy: Supports direct proxying to Gemini's native endpoints like /v1beta/models/{model}:generateContent.
  • Streaming Support: Real-time streaming responses are available for both API formats.
  • Multimodal Input: Accepts both text and image inputs.
  • Advanced Features: Supports Google Search grounding (-search model variants) and fine-grained control over Gemini's reasoning process (-nothinking, -maxthinking model variants).
  • Flexible Authentication: Multiple authentication methods are supported, including Bearer Token, Basic Auth, query parameters, and Google API keys.

Maintenance & Community

The project welcomes contributions via pull requests. No specific details regarding maintainers, community channels (like Discord/Slack), or a public roadmap are provided in the README.

Licensing & Compatibility

The project is released under the MIT License, which is permissive and generally allows for commercial use and integration into closed-source projects.

Limitations & Caveats

As a proxy, functionality and performance are dependent on the underlying Google Gemini API. Specific rate limits or API changes by Google may affect the proxy's operation. The project requires careful configuration of Google Cloud credentials or equivalent authentication methods. The README does not detail specific unsupported platforms or known bugs.

Health Check
Last Commit

3 weeks ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
4
Star History
57 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.