switch-ai: One Command to Switch AI API Configs — No More Manual Env Vars
Introducing switch-ai, a CLI tool for instantly switching between multiple AI API configurations (Anthropic, OpenAI, and more) using YAML profiles.
If you juggle multiple AI API services — Anthropic, OpenAI, Volcengine Ark, various relay providers — you know the pain of manually exporting environment variables every time you switch.
switch-ai is a lightweight CLI tool built to solve exactly that. It manages multiple API configurations in a single YAML file and lets you switch between them with one command.
The Problem It Solves
As a power user of AI coding tools, you might have:
- An official Anthropic API key
- A Volcengine Ark Coding Plan (using Anthropic-compatible endpoints)
- A relay provider key
- An internal API from your company
Every switch means running export ANTHROPIC_BASE_URL=xxx, export ANTHROPIC_AUTH_TOKEN=xxx… and it’s easy to lose track of which config is currently active. switch-ai lets you define all your configs in one YAML file and switch with a single command.
Dependencies
switch-ai requires just two common CLI tools:
- yq — YAML parser (supports both the Go version and the pip version, auto-detected)
- fzf — Fuzzy finder for interactive selection
# macOS
brew install yq fzf
# Ubuntu/Debian
sudo apt install fzf
pip install yq
Installation
# 1. Create directories
mkdir -p ~/.local/lib ~/.config/ai-keys
# 2. Clone the repo
git clone https://github.com/WhiteWorld/switch-ai.git /tmp/switch-ai
# 3. Copy files
cp /tmp/switch-ai/switch-ai.sh ~/.local/lib/
cp /tmp/switch-ai/profiles.yaml ~/.config/ai-keys/
# 4. Restrict config file permissions (contains API keys)
chmod 600 ~/.config/ai-keys/profiles.yaml
# 5. Add to ~/.zshrc or ~/.bashrc
source ~/.local/lib/switch-ai.sh
alias ai='switch_ai'
Restart your terminal or run source ~/.zshrc to activate.
Configuring API Profiles
Edit ~/.config/ai-keys/profiles.yaml and add your API configurations:
# Official Anthropic
anthropic:
ANTHROPIC_BASE_URL: https://api.anthropic.com
ANTHROPIC_AUTH_TOKEN: sk-ant-xxxxx
# Volcengine Ark Coding Plan
ark:
ANTHROPIC_BASE_URL: https://ark.cn-beijing.volces.com/api/coding
ANTHROPIC_AUTH_TOKEN: your-ark-token
ANTHROPIC_MODEL: ark-code-latest
# A relay provider
relay:
ANTHROPIC_BASE_URL: https://relay.example.com/api
ANTHROPIC_AUTH_TOKEN: your-relay-token
Each top-level key is a profile name, and the keys beneath it are the environment variables to set. You can define any variable names — it’s not limited to Anthropic; OpenAI’s OPENAI_API_KEY works just as well.
Usage
switch-ai provides 4 commands, simple and intuitive:
ai — Interactive Selection
Just type ai and a fzf fuzzy search menu appears, letting you pick from your configured profiles:
$ ai
> anthropic
ark
relay
Select one and it takes effect immediately — your current shell’s environment variables are set to the chosen profile’s values.
ai <profile> — Direct Switch
If you already know which profile you want:
ai ark # Switch to Volcengine Ark
ai anthropic # Switch back to official Anthropic
ai show — View Current Config
Displays the currently active AI-related environment variables (keys are automatically masked, showing only the first 8 characters):
$ ai show
ANTHROPIC_BASE_URL = https://ark.cn-beijing.volces.com/api/coding
ANTHROPIC_AUTH_TOKEN = abcd1234...********
ANTHROPIC_MODEL = ark-code-latest
ai clear — Clear All Config
Remove all AI-related environment variables in one shot:
ai clear
Real-World Use Cases
Use Case 1: Claude Code Users Switching API Sources
If you’re using Claude Code (CLI), just run ai ark to switch to Ark, then launch claude as usual. Want to switch back to official Anthropic? ai anthropic — that’s it.
Use Case 2: Testing Different Models During Development
When building AI applications and comparing models:
ai ark # Test with Ark's Doubao model first
python test.py
ai anthropic # Then test with official Claude
python test.py
Use Case 3: Work/Personal Account Switching
Use the company-provided API at work, switch to your personal one after hours:
ai work # Start of day
ai personal # End of day
Technical Highlights
- Pure Shell implementation — Zero compilation dependencies, works in both Bash and Zsh
- Dual yq compatibility — Automatically detects Go and pip versions of yq
- Key masking —
ai showdisplays only the first 8 characters of sensitive values - Dynamic variable detection — Reads variable names from YAML automatically, no hardcoding needed
- Permission security — Config file recommended at 600 permissions to protect API keys
Summary
switch-ai is a minimal but practical tool, especially useful for developers who work with multiple AI API services simultaneously. Instead of manually exporting a bunch of variables each time, spend 2 minutes setting up switch-ai and handle everything with a single ai command going forward.
Project repository: github.com/WhiteWorld/switch-ai
📚 Keep Reading
📚 Related Guides
Volcengine Ark Coding Plan Guide: Tiers, Agent Plan Differences, and Setup Notes
Based on the official Volcengine Ark Agent/Coding Plan export: Coding Plan is a two-tier coding-focused subscription for individual developers, while Agent Plan is the upgraded multimodal + Harness package. Covers the boundary, model/activity changes, Base URL/API key rules, and setup notes for Cline, Claude Code, OpenCode, and Codex CLI.
Bailian Coding Plan: Complete Guide to Pricing, Quotas, and Client Setup
Alibaba Cloud's Bailian Coding Plan is a subscription-based API package for AI coding. This guide covers the Pro tier, supported models, compatible clients, and configuration steps.
China Coding API Roundup 2026: Ark vs Bailian vs MiniMax vs Zhipu vs DeepSeek
The most comprehensive 2026 comparison of Chinese AI coding API subscriptions: Volcengine Ark Lite ¥40/mo (¥9.9 first month), Alibaba Bailian ¥200, MiniMax ¥29, Zhipu GLM ¥49+, and DeepSeek pay-as-you-go. One big table, six scenarios, and a decision tree to find your fit in 30 seconds.
📖 Related Comparisons
Bailian Coding Plan vs Volcengine Ark Coding Plan: 2026 Deep Comparison
A comprehensive comparison of Alibaba Cloud Bailian and Volcengine Ark — two major China-native AI coding API plans: pricing, quota mechanisms, model ecosystems, client compatibility, and selection advice.
Claude Code vs Cline 2026: Top CLI Agent vs Most Flexible VS Code Plugin
Claude Code vs Cline compared: terminal CLI vs VS Code plugin, pricing, China accessibility, Agent capabilities, and model freedom — helping you pick the right AI coding tool for your workflow.
Aider vs Cline 2026: Two Open-Source Free AI Agents Compared
Aider vs Cline compared: Git-first Python CLI vs VS Code plugin Agent — privacy, pricing, workflow, MCP support, and China accessibility to help you choose the best free AI coding tool.
🎁 Grab deals & free trials
Free quotas, first-month discounts, and sign-up links for tools & coding plans — kept up to date.
View all deals →