[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-72265":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":15,"forks30d":15,"starsTrendScore":19,"compositeScore":20,"rankGlobal":9,"rankLanguage":9,"license":9,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":21,"topics":24,"createdAt":9,"pushedAt":9,"updatedAt":25,"readmeContent":26,"aiSummary":27,"trendingCount":15,"starSnapshotCount":15,"syncStatus":16,"lastSyncTime":28,"discoverSource":29},72265,"claude-code-proxy","1rgs\u002Fclaude-code-proxy","1rgs","Run Claude Code on OpenAI models",null,"Python",3625,475,21,44,0,2,11,66,6,30.03,false,"main",true,[],"2026-06-12 02:03:00","# Anthropic API Proxy for Gemini & OpenAI Models 🔄\n\n**Use Anthropic clients (like Claude Code) with Gemini, OpenAI, or direct Anthropic backends.** 🤝\n\nA proxy server that lets you use Anthropic clients with Gemini, OpenAI, or Anthropic models themselves (a transparent proxy of sorts), all via LiteLLM. 🌉\n\n\n![Anthropic API Proxy](pic.png)\n\n## Quick Start ⚡\n\n### Prerequisites\n\n- OpenAI API key 🔑\n- Google AI Studio (Gemini) API key (if using Google provider) 🔑\n- Google Cloud Project with Vertex AI API enabled (if using Application Default Credentials for Gemini) ☁️\n- [uv](https:\u002F\u002Fgithub.com\u002Fastral-sh\u002Fuv) installed.\n\n### Setup 🛠️\n\n#### From source\n\n1. **Clone this repository**:\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002F1rgs\u002Fclaude-code-proxy.git\n   cd claude-code-proxy\n   ```\n\n2. **Install uv** (if you haven't already):\n   ```bash\n   curl -LsSf https:\u002F\u002Fastral.sh\u002Fuv\u002Finstall.sh | sh\n   ```\n   *(`uv` will handle dependencies based on `pyproject.toml` when you run the server)*\n\n3. **Configure Environment Variables**:\n   Copy the example environment file:\n   ```bash\n   cp .env.example .env\n   ```\n   Edit `.env` and fill in your API keys and model configurations:\n\n   *   `ANTHROPIC_API_KEY`: (Optional) Needed only if proxying *to* Anthropic models.\n   *   `OPENAI_API_KEY`: Your OpenAI API key (Required if using the default OpenAI preference or as fallback).\n   *   `GEMINI_API_KEY`: Your Google AI Studio (Gemini) API key (Required if `PREFERRED_PROVIDER=google` and `USE_VERTEX_AUTH=true`).\n   *   `USE_VERTEX_AUTH` (Optional): Set to `true` to use Application Default Credentials (ADC) will be used (no static API key required). Note: when USE_VERTEX_AUTH=true, you must configure `VERTEX_PROJECT` and `VERTEX_LOCATION`.\n   *   `VERTEX_PROJECT` (Optional): Your Google Cloud Project ID (Required if `PREFERRED_PROVIDER=google` and `USE_VERTEX_AUTH=true`).\n   *   `VERTEX_LOCATION` (Optional): The Google Cloud region for Vertex AI (e.g., `us-central1`) (Required if `PREFERRED_PROVIDER=google` and `USE_VERTEX_AUTH=true`).\n   *   `PREFERRED_PROVIDER` (Optional): Set to `openai` (default), `google`, or `anthropic`. This determines the primary backend for mapping `haiku`\u002F`sonnet`.\n   *   `BIG_MODEL` (Optional): The model to map `sonnet` requests to. Defaults to `gpt-4.1` (if `PREFERRED_PROVIDER=openai`) or `gemini-2.5-pro-preview-03-25`. Ignored when `PREFERRED_PROVIDER=anthropic`.\n   *   `SMALL_MODEL` (Optional): The model to map `haiku` requests to. Defaults to `gpt-4.1-mini` (if `PREFERRED_PROVIDER=openai`) or `gemini-2.0-flash`. Ignored when `PREFERRED_PROVIDER=anthropic`.\n\n   **Mapping Logic:**\n   - If `PREFERRED_PROVIDER=openai` (default), `haiku`\u002F`sonnet` map to `SMALL_MODEL`\u002F`BIG_MODEL` prefixed with `openai\u002F`.\n   - If `PREFERRED_PROVIDER=google`, `haiku`\u002F`sonnet` map to `SMALL_MODEL`\u002F`BIG_MODEL` prefixed with `gemini\u002F` *if* those models are in the server's known `GEMINI_MODELS` list (otherwise falls back to OpenAI mapping).\n   - If `PREFERRED_PROVIDER=anthropic`, `haiku`\u002F`sonnet` requests are passed directly to Anthropic with the `anthropic\u002F` prefix without remapping to different models.\n\n4. **Run the server**:\n   ```bash\n   uv run uvicorn server:app --host 0.0.0.0 --port 8082 --reload\n   ```\n   *(`--reload` is optional, for development)*\n\n#### Docker\n\nIf using docker, download the example environment file to `.env` and edit it as described above.\n```bash\ncurl -O .env https:\u002F\u002Fraw.githubusercontent.com\u002F1rgs\u002Fclaude-code-proxy\u002Frefs\u002Fheads\u002Fmain\u002F.env.example\n```\n\nThen, you can either start the container with [docker compose](https:\u002F\u002Fdocs.docker.com\u002Fcompose\u002F) (preferred):\n\n```yml\nservices:\n  proxy:\n    image: ghcr.io\u002F1rgs\u002Fclaude-code-proxy:latest\n    restart: unless-stopped\n    env_file: .env\n    ports:\n      - 8082:8082\n```\n\nOr with a command:\n\n```bash\ndocker run -d --env-file .env -p 8082:8082 ghcr.io\u002F1rgs\u002Fclaude-code-proxy:latest\n```\n\n### Using with Claude Code 🎮\n\n1. **Install Claude Code** (if you haven't already):\n   ```bash\n   npm install -g @anthropic-ai\u002Fclaude-code\n   ```\n\n2. **Connect to your proxy**:\n   ```bash\n   ANTHROPIC_BASE_URL=http:\u002F\u002Flocalhost:8082 claude\n   ```\n\n3. **That's it!** Your Claude Code client will now use the configured backend models (defaulting to Gemini) through the proxy. 🎯\n\n## Model Mapping 🗺️\n\nThe proxy automatically maps Claude models to either OpenAI or Gemini models based on the configured model:\n\n| Claude Model | Default Mapping | When BIG_MODEL\u002FSMALL_MODEL is a Gemini model |\n|--------------|--------------|---------------------------|\n| haiku | openai\u002Fgpt-4o-mini | gemini\u002F[model-name] |\n| sonnet | openai\u002Fgpt-4o | gemini\u002F[model-name] |\n\n### Supported Models\n\n#### OpenAI Models\nThe following OpenAI models are supported with automatic `openai\u002F` prefix handling:\n- o3-mini\n- o1\n- o1-mini\n- o1-pro\n- gpt-4.5-preview\n- gpt-4o\n- gpt-4o-audio-preview\n- chatgpt-4o-latest\n- gpt-4o-mini\n- gpt-4o-mini-audio-preview\n- gpt-4.1\n- gpt-4.1-mini\n\n#### Gemini Models\nThe following Gemini models are supported with automatic `gemini\u002F` prefix handling:\n- gemini-2.5-pro\n- gemini-2.5-flash\n\n### Model Prefix Handling\nThe proxy automatically adds the appropriate prefix to model names:\n- OpenAI models get the `openai\u002F` prefix\n- Gemini models get the `gemini\u002F` prefix\n- The BIG_MODEL and SMALL_MODEL will get the appropriate prefix based on whether they're in the OpenAI or Gemini model lists\n\nFor example:\n- `gpt-4o` becomes `openai\u002Fgpt-4o`\n- `gemini-2.5-pro-preview-03-25` becomes `gemini\u002Fgemini-2.5-pro-preview-03-25`\n- When BIG_MODEL is set to a Gemini model, Claude Sonnet will map to `gemini\u002F[model-name]`\n\n### Customizing Model Mapping\n\nControl the mapping using environment variables in your `.env` file or directly:\n\n**Example 1: Default (Use OpenAI)**\nNo changes needed in `.env` beyond API keys, or ensure:\n```dotenv\nOPENAI_API_KEY=\"your-openai-key\"\nGEMINI_API_KEY=\"your-google-key\" # Needed if PREFERRED_PROVIDER=google\n# PREFERRED_PROVIDER=\"openai\" # Optional, it's the default\n# BIG_MODEL=\"gpt-4.1\" # Optional, it's the default\n# SMALL_MODEL=\"gpt-4.1-mini\" # Optional, it's the default\n```\n\n**Example 2a: Prefer Google (using GEMINI_API_KEY)**\n```dotenv\nGEMINI_API_KEY=\"your-google-key\"\nOPENAI_API_KEY=\"your-openai-key\" # Needed for fallback\nPREFERRED_PROVIDER=\"google\"\n# BIG_MODEL=\"gemini-2.5-pro\" # Optional, it's the default for Google pref\n# SMALL_MODEL=\"gemini-2.5-flash\" # Optional, it's the default for Google pref\n```\n\n**Example 2b: Prefer Google (using Vertex AI with Application Default Credentials)**\n```dotenv\nOPENAI_API_KEY=\"your-openai-key\" # Needed for fallback\nPREFERRED_PROVIDER=\"google\"\nVERTEX_PROJECT=\"your-gcp-project-id\"\nVERTEX_LOCATION=\"us-central1\"\nUSE_VERTEX_AUTH=true\n# BIG_MODEL=\"gemini-2.5-pro\" # Optional, it's the default for Google pref\n# SMALL_MODEL=\"gemini-2.5-flash\" # Optional, it's the default for Google pref\n```\n\n**Example 3: Use Direct Anthropic (\"Just an Anthropic Proxy\" Mode)**\n```dotenv\nANTHROPIC_API_KEY=\"sk-ant-...\"\nPREFERRED_PROVIDER=\"anthropic\"\n# BIG_MODEL and SMALL_MODEL are ignored in this mode\n# haiku\u002Fsonnet requests are passed directly to Anthropic models\n```\n\n*Use case: This mode enables you to use the proxy infrastructure (for logging, middleware, request\u002Fresponse processing, etc.) while still using actual Anthropic models rather than being forced to remap to OpenAI or Gemini.*\n\n**Example 4: Use Specific OpenAI Models**\n```dotenv\nOPENAI_API_KEY=\"your-openai-key\"\nGEMINI_API_KEY=\"your-google-key\"\nPREFERRED_PROVIDER=\"openai\"\nBIG_MODEL=\"gpt-4o\" # Example specific model\nSMALL_MODEL=\"gpt-4o-mini\" # Example specific model\n```\n\n## How It Works 🧩\n\nThis proxy works by:\n\n1. **Receiving requests** in Anthropic's API format 📥\n2. **Translating** the requests to OpenAI format via LiteLLM 🔄\n3. **Sending** the translated request to OpenAI 📤\n4. **Converting** the response back to Anthropic format 🔄\n5. **Returning** the formatted response to the client ✅\n\nThe proxy handles both streaming and non-streaming responses, maintaining compatibility with all Claude clients. 🌊\n\n## Contributing 🤝\n\nContributions are welcome! Please feel free to submit a Pull Request. 🎁\n","该项目是一个代理服务器，允许用户使用Anthropic客户端（如Claude Code）与Gemini、OpenAI或直接Anthropic后端进行交互。核心功能是通过LiteLLM实现对不同AI模型的透明代理，支持配置环境变量来指定首选的服务提供商以及相应的API密钥和模型设置。技术上采用Python语言开发，并依赖于uv工具管理依赖关系。适用于需要灵活切换不同AI服务提供商但希望保持代码一致性的场景，比如在开发过程中比较不同AI模型性能或成本效益时。","2026-06-11 03:41:07","high_star"]