gemini-proxy-panel is a proxy service deployed on Cloudflare Workers. It can forward requests formatted for the OpenAI API to the Google Gemini Pro API, allowing applications developed for OpenAI to seamlessly switch to or leverage the capabilities of Gemini models.
- OpenAI to Gemini Proxy: Seamlessly translates OpenAI Chat API requests into Gemini Pro API requests.
- Multi-API Key Rotation: Supports configuring multiple Gemini API keys and automatically rotates through them to distribute request load and circumvent rate limits.
- Quota and Usage Management: Monitor the usage of each Gemini API key through an intuitive management interface.
- Key Management: Centrally manage multiple Gemini API keys and Worker API keys (used to access this proxy service) within the management panel.
- Model Configuration: Define and manage the Gemini models supported by this proxy in the management panel.
- Intuitive Management Interface: Provides a Web UI (
/loginor/admin) to view API usage statistics and configure settings. - One-Click Deployment: Supports quick deployment to the Cloudflare Workers platform via the "Deploy to Cloudflare" button.
- Click the
button above.
- Follow the prompts from Cloudflare to complete the deployment process, authorizing access to your GitHub repository.
- After deployment, you will need to perform the necessary configurations.
- Clone this repository:
git clone https://github.com/dreamhartley/gemini-proxy-panel.git cd gemini-proxy-panel - Install dependencies:
npm install
- Log in to Wrangler:
npx wrangler login
- (Optional) Modify the
nameandaccount_idin thewrangler.tomlfile. - Deploy:
npx wrangler deploy
Regardless of the deployment method used, you need to perform the following configurations in the Cloudflare dashboard after the initial deployment:
-
Create KV Namespaces:
- In the Cloudflare dashboard, navigate to "Workers & Pages" -> "KV".
- Create two KV Namespaces:
GEMINI_KEYS_KVWORKER_CONFIG_KV
- Note down their Namespace IDs.
-
Bind KV Namespaces to Worker:
- Navigate to your deployed Worker (located under "Workers & Pages").
- Go to the Worker's "Settings" -> "Variables".
- In the "KV Namespace Bindings" section, add two bindings:
- Variable name:
GEMINI_KEYS_KV, KV Namespace: Select theGEMINI_KEYS_KVyou just created. - Variable name:
WORKER_CONFIG_KV, KV Namespace: Select theWORKER_CONFIG_KVyou just created.
- Variable name:
- Click "Save".
-
Set Environment Variables:
- In the same Worker's "Settings" -> "Variables" page.
- In the "Environment Variables" section, add the following variables (click "Encrypt" to encrypt them for added security):
ADMIN_PASSWORD: Set a secure password to log in to the management panel.SESSION_SECRET_KEY: Set a long and random string for session management. You can use a password generator to generate a strong random string (e.g., at least 32 characters).
- Click "Save".
-
Redeploy (If Necessary): If the Worker fails to automatically acquire the latest bindings and environment variables, you may need to manually trigger a new deployment (e.g., via Wrangler
npx wrangler deployor by updating the code in the Cloudflare dashboard and clicking "Deploy").
- Access the
/loginor/adminpath of your Worker URL (e.g.,https://your-worker-name.your-subdomain.workers.dev/login). - Log in using the
ADMIN_PASSWORDyou set. - In the management panel, you can:
- Add and manage your Gemini API keys.
- Add and manage API keys used to access this Worker proxy (Worker API Keys).
- Set global quotas for Pro and Flash series models.
- View usage statistics for each Gemini API key.
- Configure supported Gemini models.
- Point the API endpoint of your application (originally configured to call the OpenAI API) to your deployed Worker URL (e.g.,
https://your-worker-name.your-subdomain.workers.dev). - Ensure that your application includes valid authentication information when sending requests. This is usually done by carrying the "Worker API Key" configured in the management panel in the
Authorizationrequest header:Authorization: Bearer <your_worker_api_key> - Send requests compatible with the OpenAI Chat Completions API. The Worker will convert them into Gemini API requests and return the formatted response.
- KV Namespaces (Must Be Bound):
GEMINI_KEYS_KV: Stores Gemini API keys and their usage.WORKER_CONFIG_KV: Stores Worker configurations, such as Worker API keys, supported models, etc.
- Environment Variables (Must Be Set):
ADMIN_PASSWORD: The login password for the management panel.SESSION_SECRET_KEY: The key used to protect user session security.