Skip to content

wang1970/API-Switch

Repository files navigation

API Switch

Personal AI API Management & Forwarding Hub

Manage multiple AI API providers through a single endpoint with automatic failover — never go down.


✨ Features

Feature Description
Multi-Provider Routing One endpoint for multiple AI providers, auto-match or manually specify models
Never Goes Down Set model to auto for optimal channel matching; auto-cooldown on failure and switch to next available
One-Click Speed Test Test all channels & models sequentially — green response time for success, red ✗ for failure
Smart Circuit Breaker Auto-disable unrecoverable models (401/403/410), cooldown skips failed models, auto-recover on success
Auto Channel Calibration One-click model fetch with auto API type detection, Base URL correction, relay station model discovery
Smart Model Pre-selection Auto-select models released within 6 months + existing models; new entries enabled by default
System Tray Right-click tray icon to reprioritize top AUTO-group entries without opening the main window
Bilingual UI and user guide support Chinese/English
Portable Single EXE file, data stored alongside the executable, copy and run anywhere

🚀 Quick Start

  1. Download from Releases
  2. Run — database is auto-created in the same directory
  3. Go to Channels to add API providers, fetch and select models
  4. Go to API Management to view and enable models
  5. Point your client's API base URL to http://127.0.0.1:9090, set model to auto or any specific name

Client Setup

API Base URL: http://127.0.0.1:9090
API Key: anything (enforce validation in Settings if needed)
Model: auto (smart match) or any specific model name

Routing Rules

Mode Behavior
model: auto Automatically select from enabled, non-cooled AUTO-group entries by priority
model: coding First try case-insensitive group exact match, then model-name fuzzy match, then fall back to the AUTO group
Tray right-click Reprioritize existing AUTO-group entries only; it does not switch groups

📦 Downloads

Platform File
Windows x64 api-switch-*-windows-x64.exe
macOS Intel api-switch-*-macos-x64
macOS Apple Silicon api-switch-*-macos-arm64
Linux x64 api-switch-*-linux-x64

Visit Releases for the latest version.


🔧 Supported Providers

Type Auth Method Description
OpenAI Bearer Token Standard OpenAI API
Anthropic x-api-key Claude series models, full format conversion
Google Gemini Query Parameter OpenAI-compatible endpoint
Azure OpenAI api-key Header Deployment name routing
Custom Bearer Token Any OpenAI-compatible third-party service (CODING PLAN, SiliconFlow, etc.)

CODING PLAN / Relay Stations

Relay stations (like CODING PLAN) often don't expose a standard /models endpoint. API Switch supports these via:

  1. Set API type to Custom, enter the base URL and API key
  2. Click Fetch Models — auto-detection tries multiple protocols and paths as fallback
  3. If the model list API is unavailable, go to API ManagementAdd Model to manually enter model names
  4. Built-in model catalog (models.json) auto-displays release date, capabilities, context length for any model name

🛡️ Fault Tolerance

  • Model Cooldown — Any upstream failure triggers 300s cooldown; cooled models are skipped in routing
  • Auto Recovery — Successful request automatically clears cooldown state
  • Auto Disable — Auto-disable entries on 401/403/410 status codes (configurable in Settings)
  • Failover — Automatically try the next available channel; returns 502 if all fail
  • User Controls Are Sacredenabled toggle is only controlled by the user; the system never auto-enables

📖 User Guide


⚙️ Configuration

Proxy listens on port 9090 by default, configurable in Settings → Proxy.

Cooldown recovery time defaults to 600s (adjustable via slider in Settings → Circuit Breaker, range 300-1800s).


🏗️ Tech Stack

Layer Technology
Desktop Tauri v2 (Rust + Web)
Backend Rust + Axum + SQLite (WAL mode)
Frontend React 19 + TypeScript + Tailwind CSS v4
Protocol Adapters 5 independent adapter modules, isolated from each other

📁 File Structure

api-switch.exe          # Main program (portable)
api-switch.db           # Database (auto-created on first run)

All data is stored alongside the executable. Delete both files to completely remove.


📜 License

MIT License


⭐ Star

If you find it useful, consider giving it a Star on GitHub!

About

Multi-platform, Portable, Desktop + Web Dual Management, Triple Fault Tolerance · Smart Routing · Personal AI Gateway

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages