by yinxulai
One Switch 是面向 Codex、Claude Code 等 AI 开发工具的本地故障切换网关。它通过统一的本地 API 入口集中管理多个 AI 供应商、模型与密钥,让各类工具只需配置一次,无需在切换供应商或模型时反复修改 Base URL、模型名称和 API Key。当上游服务出现网络故障、超时、限流、鉴权失败或服务端异常时,One Switch 会按优先级自动切换到可用渠道,尽可能保障 AI 工作流持续稳定运行。
Unlocks once the catalog security scan passes (runs nightly).
⚠️ Third-Party Software Notice
This skill is third-party open-source software developed and hosted independently on GitHub. SkillsLLM is an informational directory and does not control or maintain the underlying repository.
Any security checks, ratings, or warnings displayed by SkillsLLM are automated and limited in scope. They do not constitute a security certification or guarantee that the software is safe, error-free, or free from malicious code, vulnerabilities, compromised dependencies, or prompt-injection risks.
Review the source code, permissions, dependencies, and configuration before installing or running any third-party skill. Use is at your own risk. To the maximum extent permitted by applicable law, SkillsLLM is not liable for losses arising from third-party software.
The deep catalog scan for this skill is still queued. Run an instant dependency check now instead.
# Add to your Claude Code skills
git clone https://github.com/yinxulai/one-switchGuides for using api integration skills like one-switch.
本地 AI API 网关,在多个模型供应商或上游模型之间自动故障转移。
只需把 AI 客户端连接到一个本地地址,One Switch 就会按队列优先级选择上游。当当前渠道遇到网络故障、超时、限流、鉴权异常或服务端错误时,请求会自动尝试下一个可用渠道。所有配置、密钥和请求记录均保留在本机。
401、403、408、429 和 5xx 响应会触发队列中的下一次尝试。model 会被替换为当前队列项配置的真实上游模型 ID。safeStorage 加密保存,配置导出默认不包含密钥。截图素材统一存放在 snapshot/ 目录中。




| 协议 | 本地路径 | 常见上游 |
|---|---|---|
| OpenAI Chat Completions | /v1/chat/completions |
OpenAI、DeepSeek、OpenRouter、Ollama 及其他 OpenAI 兼容服务 |
| OpenAI Completions | /v1/completions |
OpenAI 兼容的传统 Completions 服务 |
| OpenAI Embeddings | /v1/embeddings |
OpenAI 兼容的 Embeddings 服务 |
| OpenAI Responses | /v1/responses |
OpenAI Responses API 兼容服务 |
| Anthropic Messages | /v1/messages |
Anthropic Claude 及兼容服务 |
上述路径也兼容省略 /v1 的形式。GET /v1/models 由 One Switch 本地提供,返回统一的 default 模型。
One Switch 默认优先使用与客户端协议一致的端点;对明确开启端点级协议转换的绑定,也支持部分 OpenAI 与 Anthropic 协议之间的请求、响应和流式 SSE 转换。转换属于尽力而为的兼容层,部分参数可能丢失。一次故障转移只会尝试原生匹配或已明确开启转换的队列项。Gemini 和自定义协议目前尚未在当前版本中开放。
AI 客户端
│
│ http://127.0.0.1:9300/v1/...
▼
One Switch
│
├─ 1. 识别请求协议
├─ 2. 筛选支持该协议且处于健康状态的模型
├─ 3. 按队列顺序改写真实模型 ID 并发起请求
└─ 4. 失败时尝试下一个候选
├─ Provider A / Model A
├─ Provider B / Model B
└─ Provider C / Model C
对于流式请求,One Switch 只会在响应尚未发送给客户端时切换上游。一旦响应头或内容已经开始透传,中途断开会被记录为失败,但不会拼接另一个模型的输出,以免产生混杂响应。
前往 GitHub Releases 下载适合当前平台的安装包:
.dmg,支持 Apple Silicon 和 Intel.exe,支持 x64 和 ARM64.AppImagemacOS 构建目前采用 ad-hoc 签名且未公证。若系统阻止首次打开,请在“系统设置 → 隐私与安全性”中确认打开,或在 Finder 中右键应用并选择“打开”。
打开 模型管理,新增一个供应商并填写:
API Key 只保存在本机加密存储中,不会出现在导出的配置文件里。
在供应商下添加真实模型 ID,例如 gpt-4.1、deepseek-chat 或 claude-sonnet-4-20250514,然后为它启用一个或多个协议端点。
端点可以使用供应商的默认地址,也可以为单个模型填写完整接口地址。一个模型即使支持多个协议,在故障转移队列中也只占一行。
进入 模型队列:
手动切换只影响后续请求,正在进行的普通或流式请求不会被中断。首选模型失败后,自动故障转移仍然生效。
代理默认监听:
http://127.0.0.1:9300
在客户端中根据其协议填写 Base URL:
| 客户端使用的协议 | Base URL 或接口地址 |
|---|---|
| OpenAI 兼容 | http://127.0.0.1:9300/v1 |
| OpenAI Responses | http://127.0.0.1:9300/v1 |
| Anthropic Messages | http://127.0.0.1:9300 |
客户端要求填写 API Key 时,可以填写任意非空占位值;真实上游密钥由 One Switch 按供应商注入。模型名可填写 default,代理会自动替换为最终选中队列项的真实模型 ID。
也可以直接验证本地模型列表:
curl http://127.0.0.1:9300/v1/models
监听地址和端口可在 设置 中修改。修改后需要重启本地代理服务才能让监听配置生效。
| 情况 | 行为 |
|---|---|
| 网络错误、连接超时、流式空闲超时 | 尝试下一个候选 |
401、403 |
尝试下一个候选,并累计供应商失败状态 |
408、429 |
尝试下一个候选 |
5xx |
尝试下一个候选 |
其他 4xx |
直接返回客户端,不切换 |
| 已开始向客户端发送响应后断开 | 终止当前请求,不拼接其他上游输出 |
连续失败阈值、初始冷却时间、最大冷却时间和流式空闲超时均可在 设置 → 故障转移 中调整。
127.0.0.1,不会主动暴露到局域网。safeStorage 加密后保存在本地。默认应用数据目录:
| 平台 | 路径 |
|---|---|
| macOS | ~/Library/Application Support/One Switch/ |
| Windows | %APPDATA%\One Switch\ |
| Linux | ~/.config/one-switch/ |
需要 Node.js 22 或更高版本,以及 pnpm 9.6:
pnpm install
pnpm run dev
常用命令:
pnpm run typecheck # TypeScript 类型检查
pnpm run lint # ESLint
pnpm run test:server # 服务端测试
pnpm run build # 构建当前平台安装包
pnpm run release:mac # 构建 macOS arm64 与 x64 安装包
pnpm run release:win # 构建 Windows arm64 与 x64 安装包
pnpm run release:linux # 构建 Linux arm64 与 x64 安装包
技术栈包括 Electron、React、TypeScript、Vite、Drizzle ORM 和 SQLite。更详细的设计与行为约定见 规格文档。
欢迎通过 Issues 报告问题或提出建议。提交问题时,建议附上 One Switch 版本、操作系统、请求协议以及脱敏后的运行日志;请勿粘贴 API Key、完整提示词或其他敏感信息。
one-switch is an open-source api integration skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by yinxulai. One Switch 是面向 Codex、Claude Code 等 AI 开发工具的本地故障切换网关。它通过统一的本地 API 入口集中管理多个 AI 供应商、模型与密钥,让各类工具只需配置一次,无需在切换供应商或模型时反复修改 Base URL、模型名称和 API Key。当上游服务出现网络故障、超时、限流、鉴权失败或服务端异常时,One Switch 会按优先级自动切换到可用渠道,尽可能保障 AI 工作流持续稳定运行。. It has 52 GitHub stars.
one-switch's catalog security scan is still queued. You can run an instant dependency and prompt-injection check now with the "Scan for vulnerabilities" button above.
Clone the repository with "git clone https://github.com/yinxulai/one-switch" and add it to your Claude Code skills directory (see the Installation section above).
one-switch is primarily written in TypeScript. It is open-source under yinxulai on GitHub, so you can review or fork the full source.
Yes. SkillsLLM lists many other API Integration skills you can browse and compare side by side. Open the API Integration category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh one-switch against similar tools.
No comments yet. Be the first to share your thoughts!
Top skills in this category by stars