Gemini Proxy is a powerful, open-source toolkit for managing and proxying requests to Google's Gemini API. It provides a robust set of features for developers and organizations to monitor, control, and scale their usage of the Gemini API.
π Getting Started
βοΈ Configuration & Usage
π Deployment
π§ Technical Details
π Community & Links
Gemini Proxy is a comprehensive solution that allows you to:
- π Manage API Keys: Securely store and rotate multiple Google Gemini API keys.
- β‘ Load Balance: Distribute requests across multiple API keys for optimal performance.
- π Monitor Usage: Track API usage, costs, and performance metrics.
- π‘οΈ Control Access: Manage proxy keys and access permissions.
- π Log Requests: Detailed logging of all API requests and responses.
- π Deploy Anywhere: Support for multiple deployment platforms.
- Secure storage of multiple Google Gemini API keys.
- Intelligent key rotation and load balancing.
- Usage tracking and analytics per key.
- Enable/disable keys without downtime.
- Automatic request distribution across API keys.
- Built-in retry mechanisms with exponential backoff.
- Request caching and optimization.
- Support for streaming responses.
- Real-time request logging and analytics.
- Performance metrics and cost tracking.
- Error monitoring and alerting.
- Usage dashboards and reports.
- Proxy API key management.
- Request authentication and authorization.
- Rate limiting and abuse prevention.
- Secure environment variable handling.
- Next.js Fullstack App (Recommended)
- Standalone Node.js API Server
- Vercel Edge Functions
- Cloudflare Workers
- Appwrite Functions
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher)
- pnpm (v10 or higher)
- Git
- A Google AI Studio account for Gemini API keys.
- A Supabase account for database and authentication.
The fastest way to get started is by deploying the Next.js web application:
# 1. Clone the repository
git clone https://github.com/lehuygiang28/gemini-proxy.git
cd gemini-proxy
# 2. Install dependencies
pnpm install
# 3. Configure environment
cp apps/web/.env.example apps/web/.env.local
# Edit apps/web/.env.development with your values
# 4. Start development server
cd apps/web
pnpm devFor manual setup, please refer to the apps/web/README.md.
| Variable | Description |
|---|---|
SUPABASE_URL |
Your Supabase project URL. |
SUPABASE_SERVICE_ROLE_KEY |
Your Supabase service role key. |
| Variable | Description | Default |
|---|---|---|
GOOGLE_GEMINI_API_BASE_URL |
Gemini API base URL. | https://generativelanguage.googleapis.com/ |
GOOGLE_OPENAI_API_BASE_URL |
OpenAI-compatible API base URL. | https://generativelanguage.googleapis.com/v1beta/openai/ |
PROXY_MAX_RETRIES |
Maximum retry attempts. | -1 |
PROXY_LOGGING_ENABLED |
Enable request logging. | true |
PROXY_LOG_LEVEL |
Logging level. | info |
PROXY_LOADBALANCE_STRATEGY |
Proxy load balance strategy. (round_robin or sticky_until_error) |
round_robin |
import { GoogleGenAI } from '@google/genai';
const genAi = new GoogleGenAI({
apiKey: 'your_proxy_api_key',
httpOptions: {
baseUrl: 'https://your-proxy-endpoint/api/gproxy/gemini',
},
});import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: 'your_proxy_api_key',
baseURL: 'https://your-proxy-endpoint/api/gproxy/openai',
});import { generateText } from 'ai';
import { createGoogleGenerativeAI } from '@ai-sdk/google';
const google = createGoogleGenerativeAI({
apiKey: 'gproxy_test_12345',
baseURL: 'https://your-proxy-endpoint/api/gproxy/gemini/v1beta',
});- β Complete Solution: Web interface + API proxy in one deployment.
- β User-Friendly Dashboard: Built-in UI for managing API keys, proxy keys, and monitoring.
- β Fastest Setup: Single deployment with all features.
- β Lightweight: Minimal resource usage, API-only service.
- β Customizable: Full control over deployment.
- β Scalable: Can be deployed anywhere.
- β Global CDN: Deploy to edge locations worldwide.
- β Low Latency: Fastest response times.
- β Auto-scaling: Handles traffic spikes automatically.
- π― Next.js Web App: Full-stack solution with a web dashboard.
- β‘ Standalone API Server: Lightweight Node.js API server.
- π Vercel Edge Functions: Serverless edge functions on Vercel.
- π Cloudflare Workers: Edge computing on Cloudflare's network.
- π§ Appwrite Functions: Serverless functions on Appwrite.
- π οΈ CLI Tools: Command-line tools for management.
Your App --> Gemini Proxy --> Google Gemini API
|
v
Supabase (Database)gemini-proxy/
βββ apps/
β βββ web/ # Next.js web application (Recommended)
β βββ api/ # Standalone Node.js API server
βββ packages/
β βββ core/ # Core business logic
β βββ cli/ # Command-line tools
β βββ ... # Other packages
βββ README.md# 1. Clone the repository
git clone https://github.com/lehuygiang28/gemini-proxy.git
cd gemini-proxy
# 2. Install dependencies
pnpm install
# 3. Start development servers
pnpm devWe welcome contributions! Please see our Contributing Guide for more details.
This project is licensed under the MIT License. See the LICENSE file for details.
- π Documentation: GitHub Wiki
- π Report an Issue: GitHub Issues
- π¬ Discussions: GitHub Discussions
Made with β€οΈ by lehuygiang28