{"id":28992415,"url":"https://github.com/fuergaosi233/claude-code-proxy","last_synced_at":"2025-10-08T09:37:45.422Z","repository":{"id":300616366,"uuid":"1006634318","full_name":"fuergaosi233/claude-code-proxy","owner":"fuergaosi233","description":"Claude Code to OpenAI API Proxy","archived":false,"fork":false,"pushed_at":"2025-06-22T18:08:27.000Z","size":759,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-22T18:46:57.073Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fuergaosi233.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-22T17:31:28.000Z","updated_at":"2025-06-22T18:42:40.000Z","dependencies_parsed_at":"2025-06-22T18:46:59.973Z","dependency_job_id":"0aa89fe5-8001-4412-8668-d4e687bbcc89","html_url":"https://github.com/fuergaosi233/claude-code-proxy","commit_stats":null,"previous_names":["fuergaosi233/claude-code-proxy"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fuergaosi233/claude-code-proxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuergaosi233%2Fclaude-code-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuergaosi233%2Fclaude-code-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuergaosi233%2Fclaude-code-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuergaosi233%2Fclaude-code-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fuergaosi233","download_url":"https://codeload.github.com/fuergaosi233/claude-code-proxy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuergaosi233%2Fclaude-code-proxy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261789322,"owners_count":23209783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-25T02:10:50.268Z","updated_at":"2025-10-08T09:37:45.416Z","avatar_url":"https://github.com/fuergaosi233.png","language":"Python","funding_links":[],"categories":["Python","Proxies \u0026 Model Integrations","Openai","代理与API工具","AI应用","Proxy \u0026 Customization"],"sub_categories":[],"readme":"# Claude Code Proxy\n\nA proxy server that enables **Claude Code** to work with OpenAI-compatible API providers. Convert Claude API requests to OpenAI API calls, allowing you to use various LLM providers through the Claude Code CLI.\n\n![Claude Code Proxy](demo.png)\n\n## Features\n\n- **Full Claude API Compatibility**: Complete `/v1/messages` endpoint support\n- **Multiple Provider Support**: OpenAI, Azure OpenAI, local models (Ollama), and any OpenAI-compatible API\n- **Smart Model Mapping**: Configure BIG and SMALL models via environment variables\n- **Function Calling**: Complete tool use support with proper conversion\n- **Streaming Responses**: Real-time SSE streaming support\n- **Image Support**: Base64 encoded image input\n- **Error Handling**: Comprehensive error handling and logging\n\n## Quick Start\n\n### 1. Install Dependencies\n\n```bash\n# Using UV (recommended)\nuv sync\n\n# Or using pip\npip install -r requirements.txt\n```\n\n### 2. Configure\n\n```bash\ncp .env.example .env\n# Edit .env and add your API configuration\n# Note: Environment variables are automatically loaded from .env file\n```\n\n### 3. Start Server\n\n```bash\n# Direct run\npython start_proxy.py\n\n# Or with UV\nuv run claude-code-proxy\n\n# Or with docker compose\ndocker compose up -d\n```\n\n### 4. Use with Claude Code\n\n```bash\n# If ANTHROPIC_API_KEY is not set in the proxy:\nANTHROPIC_BASE_URL=http://localhost:8082 ANTHROPIC_API_KEY=\"any-value\" claude\n\n# If ANTHROPIC_API_KEY is set in the proxy:\nANTHROPIC_BASE_URL=http://localhost:8082 ANTHROPIC_API_KEY=\"exact-matching-key\" claude\n```\n\n## Configuration\n\nThe application automatically loads environment variables from a `.env` file in the project root using `python-dotenv`. You can also set environment variables directly in your shell.\n\n### Environment Variables\n\n**Required:**\n\n- `OPENAI_API_KEY` - Your API key for the target provider\n\n**Security:**\n\n- `ANTHROPIC_API_KEY` - Expected Anthropic API key for client validation\n  - If set, clients must provide this exact API key to access the proxy\n  - If not set, any API key will be accepted\n\n**Model Configuration:**\n\n- `BIG_MODEL` - Model for Claude opus requests (default: `gpt-4o`)\n- `MIDDLE_MODEL` - Model for Claude opus requests (default: `gpt-4o`)\n- `SMALL_MODEL` - Model for Claude haiku requests (default: `gpt-4o-mini`)\n\n**API Configuration:**\n\n- `OPENAI_BASE_URL` - API base URL (default: `https://api.openai.com/v1`)\n\n**Server Settings:**\n\n- `HOST` - Server host (default: `0.0.0.0`)\n- `PORT` - Server port (default: `8082`)\n- `LOG_LEVEL` - Logging level (default: `WARNING`)\n\n**Performance:**\n\n- `MAX_TOKENS_LIMIT` - Token limit (default: `4096`)\n- `REQUEST_TIMEOUT` - Request timeout in seconds (default: `90`)\n\n### Model Mapping\n\nThe proxy maps Claude model requests to your configured models:\n\n| Claude Request                 | Mapped To     | Environment Variable   |\n| ------------------------------ | ------------- | ---------------------- |\n| Models with \"haiku\"            | `SMALL_MODEL` | Default: `gpt-4o-mini` |\n| Models with \"sonnet\"           | `MIDDLE_MODEL`| Default: `BIG_MODEL`   |\n| Models with \"opus\"             | `BIG_MODEL`   | Default: `gpt-4o`      |\n\n### Provider Examples\n\n#### OpenAI\n\n```bash\nOPENAI_API_KEY=\"sk-your-openai-key\"\nOPENAI_BASE_URL=\"https://api.openai.com/v1\"\nBIG_MODEL=\"gpt-4o\"\nMIDDLE_MODEL=\"gpt-4o\"\nSMALL_MODEL=\"gpt-4o-mini\"\n```\n\n#### Azure OpenAI\n\n```bash\nOPENAI_API_KEY=\"your-azure-key\"\nOPENAI_BASE_URL=\"https://your-resource.openai.azure.com/openai/deployments/your-deployment\"\nBIG_MODEL=\"gpt-4\"\nMIDDLE_MODEL=\"gpt-4\"\nSMALL_MODEL=\"gpt-35-turbo\"\n```\n\n#### Local Models (Ollama)\n\n```bash\nOPENAI_API_KEY=\"dummy-key\"  # Required but can be dummy\nOPENAI_BASE_URL=\"http://localhost:11434/v1\"\nBIG_MODEL=\"llama3.1:70b\"\nMIDDLE_MODEL=\"llama3.1:70b\"\nSMALL_MODEL=\"llama3.1:8b\"\n```\n\n#### Other Providers\n\nAny OpenAI-compatible API can be used by setting the appropriate `OPENAI_BASE_URL`.\n\n## Usage Examples\n\n### Basic Chat\n\n```python\nimport httpx\n\nresponse = httpx.post(\n    \"http://localhost:8082/v1/messages\",\n    json={\n        \"model\": \"claude-3-5-sonnet-20241022\",  # Maps to MIDDLE_MODEL\n        \"max_tokens\": 100,\n        \"messages\": [\n            {\"role\": \"user\", \"content\": \"Hello!\"}\n        ]\n    }\n)\n```\n\n## Integration with Claude Code\n\nThis proxy is designed to work seamlessly with Claude Code CLI:\n\n```bash\n# Start the proxy\npython start_proxy.py\n\n# Use Claude Code with the proxy\nANTHROPIC_BASE_URL=http://localhost:8082 claude\n\n# Or set permanently\nexport ANTHROPIC_BASE_URL=http://localhost:8082\nclaude\n```\n\n## Testing\n\nTest the proxy functionality:\n\n```bash\n# Run comprehensive tests\npython src/test_claude_to_openai.py\n```\n\n## Development\n\n### Using UV\n\n```bash\n# Install dependencies\nuv sync\n\n# Run server\nuv run claude-code-proxy\n\n# Format code\nuv run black src/\nuv run isort src/\n\n# Type checking\nuv run mypy src/\n```\n\n### Project Structure\n\n```\nclaude-code-proxy/\n├── src/\n│   ├── main.py  # Main server\n│   ├── test_claude_to_openai.py    # Tests\n│   └── [other modules...]\n├── start_proxy.py                  # Startup script\n├── .env.example                    # Config template\n└── README.md                       # This file\n```\n\n## Performance\n\n- **Async/await** for high concurrency\n- **Connection pooling** for efficiency\n- **Streaming support** for real-time responses\n- **Configurable timeouts** and retries\n- **Smart error handling** with detailed logging\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuergaosi233%2Fclaude-code-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuergaosi233%2Fclaude-code-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuergaosi233%2Fclaude-code-proxy/lists"}