{"slug": "claudegate-use-openrouter-models-0x-alpha-deepseek-in-claude-code-cli", "title": "ClaudeGate – Use OpenRouter Models (0x Alpha, DeepSeek) in Claude Code CLI", "summary": "ClaudeGate, a new open-source local API gateway, enables Claude Code CLI and Anthropic SDK applications to use any AI model, including free and frontier models from OpenRouter, DeepSeek, and others, by translating Anthropic's Messages API into OpenAI-compatible Chat Completions. The tool features zero-crash SSE streaming, multi-provider failover, PII sanitization, and support for 24+ provider presets, with a 10-minute keep-alive timeout.", "body_md": "**High-Performance Universal Bridge connecting Claude Code CLI & Anthropic SDKs to ANY AI Model.**\n\n*Zero-crash streaming, multi-provider failover, chain-of-thought sanitization, PII redactor, and 24+ provider presets.*\n\n[📌 1. Project Overview](#-1-project-overview)[📸 2. Live Demo & Terminal Previews](#-2-live-demo--terminal-previews)[✨ 3. Features](#-3-features)[🛠️ 4. Tech Stack](#%EF%B8%8F-4-tech-stack)[🏗️ 5. Architecture](#%EF%B8%8F-5-architecture)[📁 6. Project Structure](#-6-project-structure)[⚙️ 7. Installation and Setup](#%EF%B8%8F-7-installation-and-setup)[🚀 8. Usage & User Flow](#-8-usage--user-flow)[🧪 9. Testing & Diagnostics](#-9-testing--diagnostics)[🔒 10. Security & Privacy Safeguards](#-10-security--privacy-safeguards)[💡 11. Engineering Decisions](#-11-engineering-decisions)[🔮 12. Limitations and Future Improvements](#-12-limitations-and-future-improvements)[🤝 13. Contributing & Code of Conduct](#-13-contributing--code-of-conduct)[📄 14. License](#-14-license)\n\n[Claude Code CLI](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview) is one of the most capable agentic coding tools available today. However, it is natively locked to Anthropic's commercial cloud endpoints.\n\n**ClaudeGate** is a lightweight, high-throughput, and secure local API gateway that bridges Anthropic's Messages API protocol (`/v1/messages`\n\nand `/v1/messages/count_tokens`\n\n) into standard OpenAI-compatible Chat Completions.\n\nWith ClaudeGate, developers can power Claude Code CLI, Cursor, and Anthropic SDK applications using:\n\n- 🆓\n**Free & Frontier AI Cloud Models**: Stealth Ox Alpha, OpenRouter (Claude Opus 5 / Sonnet 5 / Haiku 4.5), OpenAI (GPT-5.6 Sol / Terra / Luna), DeepSeek (V4-Pro & V4-Flash), Google Gemini (3.1 Pro / 3.7 Flash / 3.5 Flash-Lite), Alibaba Qwen (Qwen3.8-Max / Qwen3.7-Plus / Qwen3.8-27B), Moonshot Kimi (K3 2.8T & K2.7 Code), Meta (Muse Spark 1.2 & Muse Glimmer), Z.ai GLM (GLM-5.3 & GLM-5-Turbo), MiniMax (M3 & M2.7), Cohere (Command A+ / A / R7B), Mistral (Large 3 / Medium 3.5 / Small 4), Perplexity (Sonar Reasoning Pro). - 🔒\n**100% Private Local Offline Models**: Ollama, LM Studio, vLLM (DeepSeek V4-Pro quantized, Qwen3.6-35B-A3B, Muse Glimmer - zero data leaves your machine). - 🧠\n**Next-Gen Model Mapping**: Seamlessly routes all Claude versions (Claude 3.5, 3.7, 4.x, 4.5, 5.x, Fable, Mythos) to your configured`BIG_MODEL`\n\n,`MIDDLE_MODEL`\n\n, and`SMALL_MODEL`\n\ntiers or passes through direct model slugs. - 🏢\n**Enterprise Private Deployments**: Azure OpenAI Service, AWS Amazon Q (via Kiro Bridge), Meta Muse Spark.\n\nClaudeGate in active operation, translating Claude Code CLI tool calls, bash commands, and streaming tokens in real-time:\n\n- ⚡\n**Zero-Crash SSE Streaming**: Translates raw OpenAI chunk streams into Anthropic Server-Sent Events (`content_block_start`\n\n,`content_block_delta`\n\n,`message_delta`\n\n,`message_stop`\n\n). Mid-stream disconnects and upstream errors are caught gracefully without crashing Starlette/ASGI. - 🔄\n**Automatic Multi-Provider Failover**: Seamlessly fails over from primary upstream to backup providers (e.g. OpenRouter$\\rightarrow$ Groq$\\rightarrow$ local Ollama) on transient`503`\n\n,`429`\n\n, or timeout errors without dropping the active client session. - 🛡️\n**PII & Secret Sanitizer**: Intercepts outgoing prompts and automatically scrubs AWS keys, GitHub PATs, OpenAI tokens, and SSH private keys before requests leave your computer (`SANITIZE_SECRETS=true`\n\n). - 🛠️\n**Full Bi-directional Tool / Function Calling**: Seamlessly translates Claude Code file-system operations, terminal commands, and search tools into OpenAI function calls and vice versa. - 🧹\n**Chain-of-Thought /**: Cleanses internal reasoning tokens and`<thinking>`\n\nSanitizer`<thinking>`\n\nblocks from conversation history so multi-turn reasoning models (like DeepSeek R1/V4) never trigger`400 Bad Request`\n\nerrors on follow-up turns. - ⏳\n**Extended 10-Minute Keep-Alive**: Tuned TCP socket lifespan (`timeout_keep_alive=600`\n\n) to prevent Node.js`ECONNRESET`\n\ndrops during prolonged user typing pauses. - 🎛️\n**Universal CLI Tooling**: Interactive setup wizard (`--setup`\n\n), live connectivity diagnostic (`--test`\n\n), and 24+ instant preset switches (`--preset <name>`\n\n). - 🐳\n**Docker & Compose Ready**: Run as a standalone daemon container with health-check monitoring.\n\n**Backend Framework**:[FastAPI](https://fastapi.tiangolo.com/)(High-performance async ASGI web framework)** ASGI Server**:[Uvicorn](https://www.uvicorn.org/)(Configured with custom socket keep-alives and signal handling)** Data Validation & Schemas**:[Pydantic v2](https://docs.pydantic.dev/)(Strict type serialization for Anthropic & OpenAI payloads)** HTTP Clients**:[httpx](https://www.python-httpx.org/)&[openai-python](https://github.com/openai/openai-python)(Async connection pooling and streaming response parsing)**Security & Crypto**: Python`hmac`\n\n(Constant-time token authentication) and Regex Token Redaction Engine**Containerization**: Docker & Docker Compose (Multi-stage Python slim base image)\n\nClaudeGate sits transparently between Claude Code CLI and your chosen AI model provider:\n\n```\nflowchart LR\n    A[\"Claude Code CLI\\nor Anthropic SDK\"] -- \"POST /v1/messages\\n(Anthropic Schema)\" --> B[\"ClaudeGate Gateway\\n(FastAPI / Port 8082)\"]\n    \n    subgraph CoreEngine [\"ClaudeGate Core Engine\"]\n        B --> C[\"Constant-Time Auth & IP Validator\"]\n        C --> D[\"Request Sanitizer\\n(PII & Credential Redaction)\"]\n        D --> E[\"Protocol Converter\\n(Tools, Messages, System Prompts)\"]\n        E --> F[\"Upstream Client & Failover Controller\"]\n    end\n    \n    subgraph Upstream [\"Upstream AI Providers\"]\n        F -- \"Primary Request\" --> G[\"Primary Provider\\n(OpenRouter / DeepSeek / Gemini)\"]\n        F -. \"Auto Failover on 503/429\" .-> H[\"Backup Provider\\n(Groq / Local Ollama)\"]\n    end\n    \n    G -- \"OpenAI Chunk Stream\" --> I[\"SSE Stream Adapter\\n(Zero-Crash Generator)\"]\n    H -- \"OpenAI Chunk Stream\" --> I\n    I -- \"Anthropic SSE Events\" --> A\nClaudeGate/\n├── assets/                    # Visual assets and screenshots\n│   ├── ClaudeGate.png         # Project Banner & Logo\n│   ├── claude_terminal_ss.png # Claude Code CLI in action\n│   └── proxy_terminal.png     # ClaudeGate terminal proxy log\n├── Dockerfile                 # Container image specification\n├── docker-compose.yml         # Container service configuration\n├── requirements.txt           # Python package dependencies\n├── pyproject.toml             # Modern package build configuration\n├── setup.py                   # Legacy pip install compatibility\n├── start_proxy.py             # CLI & Server launcher script\n├── .env.example               # Comprehensive environment template\n├── LICENSE                    # MIT License\n├── SECURITY.md                # Security policy & reporting guidelines\n├── CODE_OF_CONDUCT.md         # Community standard of conduct\n├── CONTRIBUTING.md            # Contribution guidelines\n├── CHANGELOG.md               # Version release history\n├── README.md                  # Project documentation\n│\n├── presets/                   # Ready-to-use provider templates\n│   ├── openrouter.env         # OpenRouter (Claude Opus 5, Sonnet 5, Haiku 4.5)\n│   ├── groq.env               # Groq (DeepSeek V4-Pro, Llama 4 Maverick, Muse Glimmer)\n│   ├── ollama.env             # Ollama (100% Local DeepSeek V4-Pro, Qwen3.6-35B, Muse Glimmer)\n│   ├── deepseek.env           # DeepSeek (DeepSeek V4-Pro & V4-Flash)\n│   ├── gemini.env             # Google Gemini (Gemini 3.1 Pro, 3.7 Flash & 3.5 Flash-Lite)\n│   ├── openai.env             # OpenAI Official (GPT-5.6 Sol, GPT-5.6 Terra, GPT-5.6 Luna)\n│   ├── kimi.env               # Moonshot AI (Kimi K3 2.8T Reasoning & K2.7 Code)\n│   ├── qwen.env               # Alibaba Qwen / DashScope (Qwen3.8-Max, Qwen3.7-Plus, Qwen3.8-27B)\n│   ├── mistral.env            # Mistral AI (Mistral Large 3, Mistral Medium 3.5, Mistral Small 4)\n│   ├── perplexity.env         # Perplexity (Sonar Reasoning Pro, Sonar Pro & Sonar)\n│   ├── cohere.env             # Cohere (Command A+, Command A & Command R7B)\n│   ├── minimax.env            # MiniMax (MiniMax M3 Frontier & MiniMax M2.7)\n│   ├── meta.env               # Meta AI (Muse Spark 1.2, Llama 4 Maverick, Muse Glimmer)\n│   ├── zai.env                # Z.ai / Zhipu GLM (GLM-5.3 Flagship, GLM-5-Turbo, GLM-4.7-Flash)\n│   ├── together.env           # Together AI (DeepSeek V4-Pro, DeepSeek V4-Flash, Qwen3.8-27B)\n│   ├── fireworks.env          # Fireworks AI (DeepSeek V4-Pro, DeepSeek V4-Flash, Qwen3.8-27B)\n│   ├── cerebras.env           # Cerebras (DeepSeek V4-Pro, Llama 4 Maverick, Muse Glimmer)\n│   ├── sambanova.env          # SambaNova Cloud (DeepSeek V4-Pro, Llama 4 Maverick, Qwen3.8-27B)\n│   ├── siliconflow.env        # SiliconFlow (DeepSeek V4-Pro, DeepSeek V4-Flash, Qwen3.8-27B)\n│   ├── lmstudio.env           # LM Studio Desktop (DeepSeek V4-Pro & Muse Glimmer)\n│   ├── vllm.env               # vLLM Self-Hosted GPU (DeepSeek V4-Pro & Qwen3.6-35B)\n│   ├── azure.env              # Azure OpenAI Service (o1 & GPT-5.6 Enterprise Deployments)\n│   ├── kiro.env               # AWS Amazon Q Developer / Claude Opus 5 Bridge\n│   ├── ox.env                 # Stealth Ox Alpha (Frontier Reasoning Model)\n│   └── nemotron.env           # Nvidia Nemotron Free Tier\n│\n├── scripts/                   # Verification & test utilities\n│   ├── verify_failover.py     # Automated failover simulation runner\n│   └── test_live_nemotron_ox.py # Live dual-model probe (Nemotron & Ox Alpha)\n│\n└── src/                       # Source code\n    ├── main.py                # FastAPI app & Uvicorn lifecycle\n    ├── cli.py                 # CLI commands, setup wizard & test runner\n    ├── api/\n    │   └── endpoints.py       # /v1/messages, /health & /count_tokens routes\n    ├── conversion/\n    │   ├── request_converter.py   # Anthropic -> OpenAI message & tool parsing\n    │   └── response_converter.py  # OpenAI stream -> Anthropic SSE translation\n    ├── core/\n    │   ├── client.py          # Async client with failover & retry logic\n    │   ├── config.py          # Dynamic environment loader & constant-time auth\n    │   ├── constants.py       # Anthropic & OpenAI protocol constants\n    │   ├── logging.py         # Structured logging configuration\n    │   └── model_manager.py   # Intelligent model tier & slug router\n    ├── models/\n    │   ├── claude.py          # Pydantic schemas for Anthropic API\n    │   └── openai.py          # Pydantic schemas for OpenAI API\n    └── security/\n        └── sanitizer.py       # Secret, AWS key, and PAT redaction engine\ngit clone https://github.com/Santosh-Prasad-Verma/ClaudeGate.git\ncd ClaudeGate\n\npython3 -m venv .venv\nsource .venv/bin/activate\npip install -r requirements.txt\n```\n\nLaunch the interactive configuration wizard:\n\n```\npython start_proxy.py --setup\n```\n\n*Or load a ready-made preset directly:*\n\n```\npython start_proxy.py --preset openrouter\n```\n\nYou can configure Claude Code CLI to communicate with ClaudeGate using either **Permanent** or **Session-Based** configuration:\n\nEdit (or create) `~/.claude/settings.json`\n\nto automatically route all future `claude`\n\ncommands to ClaudeGate:\n\n```\n{\n  \"env\": {\n    \"ANTHROPIC_BASE_URL\": \"http://127.0.0.1:8082\",\n    \"ANTHROPIC_API_KEY\": \"sk-claudegate-local\"\n  }\n}\n```\n\nExport the variables in your active shell before launching Claude:\n\n```\nexport ANTHROPIC_BASE_URL=\"http://127.0.0.1:8082\"\nexport ANTHROPIC_API_KEY=\"sk-claudegate-local\"\n```\n\nRun the built-in diagnostic test to verify your upstream provider connection and measure latency:\n\n```\npython start_proxy.py --test\n```\n\n*Expected Output:*\n\n```\n🔍 Testing upstream connection...\n   Provider Base URL: https://openrouter.ai/api/v1\n   Test Model:        stealth/ox-alpha\n✅ Connection Successful! Model is active and responsive.\n   Status: 200 OK\n```\n\nYou can also probe the gateway health endpoint directly from your terminal:\n\n```\ncurl http://127.0.0.1:8082/health\n# {\"status\":\"healthy\",\"service\":\"claudegate\"}\n```\n\nOnce setup is complete, your day-to-day workflow looks like this:\n\n```\n┌─────────────────────────────────────────────────────────────────────────────┐\n│  TERMINAL 1: Start ClaudeGate Gateway Daemon                                │\n│  $ cd ClaudeGate && python start_proxy.py                                   │\n│  [Gateway listening on http://127.0.0.1:8082 (OpenRouter/Groq/Ollama)]       │\n└──────────────────────────────────────┬──────────────────────────────────────┘\n                                       │ (Translates Anthropic ⟷ OpenAI protocol)\n                                       ▼\n┌─────────────────────────────────────────────────────────────────────────────┐\n│  TERMINAL 2: Your Codebase Workspace (Run Claude Code)                       │\n│  $ cd /path/to/my-project                                                   │\n│  $ claude                                                                   │\n│                                                                             │\n│  > \"Add JWT authentication to src/auth.py and run the unit tests\"           │\n│                                                                             │\n│  Claude Code ──────► ClaudeGate (8082) ──────► DeepSeek R1 / Qwen / Groq    │\n│  (CLI Tool Calls)   (Translates schemas)       (Executes inference & tools) │\n│  ◄────────────────── (Streams SSE Events) ◄──────────────────────────────── │\n│                                                                             │\n│  ✅ Claude Code automatically reads files, writes code, and runs bash tests! │\n└─────────────────────────────────────────────────────────────────────────────┘\n```\n\n-\n**Start the Gateway (Terminal 1)**:\n\n```\ncd ClaudeGate\npython start_proxy.py\n```\n\n*ClaudeGate will boot up, display active model mappings, and listen on*`http://127.0.0.1:8082`\n\n. -\n**Open Your Coding Project (Terminal 2)**: Navigate to whatever software project or repo you want to work on:\n\n```\ncd ~/my-flutter-app   # or any project directory\n```\n\n-\n**Launch Claude Code**:\n\n```\nclaude\n```\n\n*You can now type natural language instructions as usual. Claude Code will execute file inspections, bash commands, multi-file edits, and git commits powered entirely by your chosen backend model!* -\n**Switching Models On The Fly**: Want to swap from free cloud models (OpenRouter) to 100% private offline models (Ollama)? In Terminal 1:\n\n```\npython start_proxy.py --preset ollama\npython start_proxy.py\n```\n\n*Claude Code in Terminal 2 will immediately begin routing through local Ollama without needing a restart.*\n\n| Command | Purpose |\n|---|---|\n`python start_proxy.py` |\nStart the ClaudeGate server |\n`python start_proxy.py --test` |\nRun live connectivity probe & measure upstream latency |\n`python start_proxy.py --setup` |\nLaunch interactive 24-provider setup wizard |\n`python start_proxy.py --preset <name>` |\nQuick-load a preset (e.g. `groq` , `gemini` , `ollama` , `deepseek` ) |\n`python start_proxy.py --help` |\nView help and available options |\n`python start_proxy.py --version` |\nDisplay current release version |\n\nIf you prefer to run ClaudeGate as a background Docker container:\n\n```\n# Build and start container in the background\ndocker compose up -d --build\n\n# View real-time logs\ndocker compose logs -f\n\n# Check container health status\ndocker ps\n\n# Stop container\ndocker compose down\n```\n\nClaudeGate includes built-in live diagnostics and automated test suites:\n\nTest your active model and measure upstream response latency:\n\n```\npython start_proxy.py --test\n```\n\n*Output:*\n\n```\n🔍 Testing upstream connection...\n   Provider Base URL: https://openrouter.ai/api/v1\n   Test Model:        stealth/ox-alpha\n✅ Connection Successful! Model is active and responsive.\n   Status: 200 OK\n```\n\nSimulate an upstream outage to test automatic failover:\n\n```\npython scripts/verify_failover.py\n```\n\nRun the full test suite covering non-streaming failover, SSE streaming, and endpoint security:\n\n```\npytest tests/ -v\n```\n\nClaudeGate implements defense-in-depth privacy controls to ensure secure self-hosting:\n\n**Localhost-Only Default (**: Restricts incoming traffic exclusively to the local machine.`127.0.0.1`\n\n)**Constant-Time Authentication**: Uses Python's`hmac.compare_digest`\n\nto validate`x-api-key`\n\nheaders, preventing side-channel timing analysis.**Secret & PII Redaction Engine**: When`SANITIZE_SECRETS=\"true\"`\n\n, prompts are automatically scrubbed for sensitive tokens (GitHub PATs, AWS Access Keys, OpenAI Keys, Private SSH keys) before reaching upstream providers.**Vulnerability Reporting**: For responsible disclosure, please refer to our[Security Policy](/Santosh-Prasad-Verma/ClaudeGate/blob/main/SECURITY.md).\n\n-\n**Error Markers over Generator Exceptions**:*Problem*: In Starlette / FastAPI, raising`HTTPException`\n\ninside an active`StreamingResponse`\n\nasync generator after HTTP headers (`200 OK`\n\n) are flushed causes a fatal`RuntimeError: response already started`\n\nand terminates the ASGI worker.*Decision*: ClaudeGate's generator yields formatted`ERROR::<status>::<message>`\n\ntokens that the SSE converter catches and translates into standard Anthropic error events, keeping the worker process healthy.\n\n-\n**Multi-Turn**:`<thinking>`\n\nCleansing*Problem*: Reasoning models (like DeepSeek R1) output reasoning tokens. When Claude Code sends subsequent conversation turns containing these blocks in history, standard OpenAI endpoints reject the payload with`400 Bad Request`\n\n.*Decision*: The`request_converter`\n\nautomatically identifies and filters`thinking`\n\nand`redacted_thinking`\n\ncontent blocks before dispatching to upstream providers.\n\n-\n**Constant-Time Client Authentication**:*Problem*: Standard string comparisons (`key == expected`\n\n) are susceptible to side-channel timing attacks.*Decision*: Implemented`hmac.compare_digest`\n\nacross all header validation points.\n\n-\n**10-Minute TCP Keep-Alive (**:`timeout_keep_alive=600`\n\n)*Problem*: Node.js HTTP agents in Claude Code CLI drop connections with`ECONNRESET`\n\nif an interactive user takes longer than 5 seconds between prompts.*Decision*: Configured explicit keep-alive headers and Uvicorn socket timeouts to support extended interactive developer pauses.\n\n**Image Input Format**: Multimodal image support currently converts Base64 images directly; URLs require public accessibility.** Provider-Specific Parameters**: Non-standard hyperparameters outside temperature and top_p are passed as standard OpenAI extensions.\n\n-\n**Real-Time Web Dashboard**: Built-in visual UI (`http://127.0.0.1:8082/dashboard`\n\n) for live latency charts, token velocity, and cost tracking. -\n**Prompt Cache & SQLite Deduplication**: In-memory and SQLite KV caching for repetitive codebase index prompts. -\n**Dynamic Complexity Router**: Automatic classification of task difficulty (e.g. routing simple edits to Groq and complex architectural refactors to DeepSeek R1). -\n**Unix Domain Sockets (UDS)**: Zero-network communication option over`/run/user/$UID/claudegate.sock`\n\n.\n\nWe welcome bug fixes, documentation improvements, new provider presets, and feature additions!\n\n**Contributing Guide**: Check out[CONTRIBUTING.md](/Santosh-Prasad-Verma/ClaudeGate/blob/main/CONTRIBUTING.md)for local environment setup and PR workflows.**Code of Conduct**: This project follows the[Contributor Covenant v2.1](/Santosh-Prasad-Verma/ClaudeGate/blob/main/CODE_OF_CONDUCT.md).** Adding Presets**: To contribute a new preset, add`presets/<provider_name>.env`\n\nand submit a pull request!\n\nDistributed under the **MIT License**. See [LICENSE](/Santosh-Prasad-Verma/ClaudeGate/blob/main/LICENSE) for more information.\n\n**Built with ❤️ for the open-source & AI developer community.**\n\n*Empowering developers to run Claude Code with any model, anywhere, completely unrestricted.*\n\n⭐ **If you find ClaudeGate useful, consider giving it a star on GitHub!** ⭐", "url": "https://wpnews.pro/news/claudegate-use-openrouter-models-0x-alpha-deepseek-in-claude-code-cli", "canonical_source": "https://github.com/Santosh-Prasad-Verma/ClaudeGate", "published_at": "2026-08-25 08:16:10+00:00", "updated_at": "2026-08-25 08:44:49.880601+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "ai-infrastructure"], "entities": ["ClaudeGate", "Anthropic", "OpenRouter", "DeepSeek", "Ollama", "LM Studio", "vLLM", "Azure OpenAI Service"], "alternates": {"html": "https://wpnews.pro/news/claudegate-use-openrouter-models-0x-alpha-deepseek-in-claude-code-cli", "markdown": "https://wpnews.pro/news/claudegate-use-openrouter-models-0x-alpha-deepseek-in-claude-code-cli.md", "text": "https://wpnews.pro/news/claudegate-use-openrouter-models-0x-alpha-deepseek-in-claude-code-cli.txt", "jsonld": "https://wpnews.pro/news/claudegate-use-openrouter-models-0x-alpha-deepseek-in-claude-code-cli.jsonld"}}