# gemini-api-proxy **Repository Path**: pythonxueba/gemini-api-proxy ## Basic Information - **Project Name**: gemini-api-proxy - **Description**: Gemini API 通用代理服务 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-01-07 - **Last Updated**: 2026-01-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AI API Proxy 多 AI 提供商 API 代理服务,支持 Gemini、Claude、ChatGPT 的所有 API 请求转发。 ## 特性 - 无差别转发所有 HTTP 方法 - **流式/非流式输出可选**(Gemini 默认流式) - **支持文件上传** - URL 参数传递 API Key - 零第三方 CORS 依赖 - 完美适配 PythonAnywhere ## 快速开始 ```bash # 安装依赖 pip install -r requirements.txt # 启动服务 python main.py ``` 服务将在 `http://0.0.0.0:5000` 启动。 ## PythonAnywhere 部署 1. 创建 `wsgi.py`: ```python from main import app ``` 2. 在 Web 面板设置: - WSGI 配置文件: `/path/to/project/wsgi.py` - Worker 类型: `Manual` 或 `Auto` - Working directory: `/path/to/project` 3. 安装依赖并重启应用 ## 使用示例 ### Gemini 直接使用官方 API 端点: ```bash # 流式输出(使用 streamGenerateContent + alt=sse) curl -X POST "http://localhost:5000/v1beta/models/gemini-2.0-flash:streamGenerateContent?alt=sse&key=AI..." \ -H "Content-Type: application/json" \ -d '{"contents":[{"parts":[{"text":"Hello"}]}]}' # 非流式输出(使用 generateContent) curl -X POST "http://localhost:5000/v1beta/models/gemini-2.0-flash:generateContent?key=AI..." \ -H "Content-Type: application/json" \ -d '{"contents":[{"parts":[{"text":"Hello"}]}]}' # 图像识别(流式) curl -X POST "http://localhost:5000/v1beta/models/gemini-2.0-flash:streamGenerateContent?alt=sse&key=AI..." \ -H "Content-Type: application/json" \ -d '{"contents":[{"parts":[{"text":"What do you see?"},{"inline_data":{"mime_type":"image/jpeg","data":"'"$(base64 -w 0 image.jpg)"'"}}]}]}' ``` ### Claude ```bash # 文本对话 curl -X POST "http://localhost:5000/anthropic/v1/messages?api_key=sk-ant-..." \ -H "Content-Type: application/json" \ -d '{"model":"claude-3-5-sonnet-20241022","max_tokens":1024,"messages":[{"role":"user","content":"Hello"}]}' # 图像识别 curl -X POST "http://localhost:5000/anthropic/v1/messages?api_key=sk-ant-..." \ -H "Content-Type: application/json" \ -d '{"model":"claude-3-5-sonnet-20241022","max_tokens":1024,"messages":[{"role":"user","content":[{"type":"text","text":"What do you see?"},{"type":"image","source":{"type":"base64","media_type":"image/jpeg","data":"'"$(base64 -w 0 image.jpg)"'"}}]}]}' ``` ### ChatGPT ```bash # 文本对话(流式) curl -X POST "http://localhost:5000/openai/chat/completions?api_key=sk-..." \ -H "Content-Type: application/json" \ -d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello"}]}' # 非流式输出 curl -X POST "http://localhost:5000/openai/chat/completions?api_key=sk-...&stream=false" \ -H "Content-Type: application/json" \ -d '{"model":"gpt-4o","messages":[{"role":"user","content":"Hello"}]}' # GPT-4 Vision curl -X POST "http://localhost:5000/openai/chat/completions?api_key=sk-..." \ -H "Content-Type: application/json" \ -d '{"model":"gpt-4o","messages":[{"role":"user","content":[{"type":"text","text":"What'\''s in this image?"},{"type":"image_url","image_url":{"url":"data:image/jpeg;base64,'"$(base64 -w 0 image.jpg)"'"}}]}],"max_tokens":300}' # 文件上传 curl -X POST "http://localhost:5000/openai/files?api_key=sk-..." \ -F "file=@document.pdf" \ -F "purpose=assistants" ``` ## 路由映射 | 提供商 | 支持路径 | |-------|---------| | Gemini | `/v1beta/*`, `/v1/*`, `/gemini/*` | | Claude | `/anthropic/*`, `/claude/*` | | ChatGPT | `/openai/*`, `/chatgpt/*` | ## API Key 参数 - Gemini: `key`, `gemini_key`, `google_key`, `api_key` - Claude: `api_key`, `claude_key`, `anthropic_key` - ChatGPT: `api_key`, `openai_key`, `chatgpt_key` ## 流式/非流式控制 通过 URL 参数 `stream` 控制输出方式(仅对 OpenAI 和 Claude 生效): | 参数值 | 含义 | |-------|------| | `true` / `1` / 不传 | 流式输出(默认) | | `false` / `0` | 非流式输出 | **Gemini**:直接使用官方端点,`streamGenerateContent?alt=sse` 流式,`generateContent` 非流式 **OpenAI**:请求体中自动添加 `"stream": true/false` **Claude**:请求体中自动添加 `"stream": true/false` ## 接口文档 - [Gemini API](https://ai.google.dev/gemini-api/docs) - [Claude API](https://docs.anthropic.com/) - [OpenAI API](https://platform.openai.com/docs)