backend-switchboard
One local endpoint that lets Claude Code switch between several model backends with /model, in a single session:
/model value |
Goes to |
|---|---|
claude-sonnet-5-5 (no tag) |
Anthropic, using your own Claude Code login. Requests are forwarded untouched. |
claude-sonnet-5-5@argo |
Argo through a running argo-shim |
claude-opus-5-5@google@mag |
A LiteLLM-style gateway with Bearer auth (AMSC "MAG"); the tag @mag is stripped and @google is MAG's own suffix |
beam@alcf, muse@alcf |
ALCF inference endpoints, which serve the Anthropic Messages API natively |
google-claude-opus-5@asksage |
AskSage models, translated in-process to AskSage's /query API |
claude-opus-5-5@copilot, gpt-6.1-sol@copilot |
GitHub Copilot, using your gh login: Claude models natively, GPT/Grok models translated to /responses |
Claude Code only accepts one ANTHROPIC_BASE_URL per session, so the switch has to happen behind that URL.
backend-switchboard is that URL. It reads the model name, picks a backend, swaps in that backend's credentials, and
streams the response back. Standard library only, Python 3.8+. No other services to run.
Not affiliated with Anthropic. The Anthropic route forwards your Claude Code login (OAuth or API key) unchanged and never reads, stores or logs it. Check your plan's terms before sending subscription traffic through a local proxy.
Claude Code --> 127.0.0.1:8790 (backend-switchboard) --+--> api.anthropic.com (no tag)
/model name[@tag] +--> argo-shim (@argo)
+--> MAG (@mag)
+--> ALCF Minerva (@alcf)
+--> AskSage (@asksage)
+--> GitHub Copilot (@copilot)
Install
pip install backend-switchboard
# or without installing:
uvx backend-switchboard run
Use
backend-switchboard run # starts the router if needed, then launches claude
backend-switchboard run -c # anything after "run" is passed to claude
Then inside Claude Code: /model beam@alcf, /model claude-sonnet-5-5@argo, /model claude-sonnet-5-5 (back to your
subscription). You can switch mid-conversation; the history is carried across backends.
Other commands: init (create the key and settings), ensure (start the router in the background), stop, serve
(foreground). State lives in ~/.backend-switchboard/ (override with BACKEND_SWITCHBOARD_HOME).
If you launch Claude Code with a separate config directory, e.g. a personal subscription, export CLAUDE_CONFIG_DIR
first; run leaves it alone.
Backends
Anthropic (no tag). Nothing to configure. Whatever login your Claude Code already has is used.
Argo (@argo). Run argo-shim as usual. The router re-reads its token and
local URL from ~/.claude/settings.json on every request (change the path with argo_settings). If Argo answers an
exhausted quota with HTTP 200 and an "ACCESS REVOKED" notice, the router turns that into a 429 so it is not shown as a
model answer.
MAG (@mag). Export AMSC_TOKEN in the environment the router starts from. Set mag_url in config.json to
point at another Bearer-auth gateway. MAG's own provider suffixes stay in the name: claude-opus-5-5@google@mag.
ALCF (@alcf). Install the ALCF token tools and log in once, in your own terminal:
uv tool install alcf-ai alcf-tokens
alcf-tokens login inference
The router runs alcf-tokens get-token inference (cached for two minutes), or uses ALCF_INFERENCE_TOKEN if you set it.
ALCF's Minerva endpoint accepts the Anthropic Messages API directly with a Bearer token, so requests are forwarded as they
are, including streaming, tool calls and the models' thinking blocks. Aliases beam and muse map to beam-1.0-bf16
and muse-spark-bf16; any other name is passed through. Add or change aliases under aliases.alcf in config.json.
AskSage (@asksage). Setup:
- Get an AskSage API key from your AskSage account settings (for ANL: https://api.asksage.anl.gov) and export it in the
shell that starts the router, e.g. in
~/.bashrc:export ASKSAGE_API_KEY=.... The router reads it per request and never logs it. It reads only the environment, so restart the router after changing it:backend-switchboard stop, then launch again. - If your AskSage host uses a private CA, save its certificate and point at it in
~/.backend-switchboard/config.json:{"asksage_cert": "~/path/to/asksage.pem"}.asksage_urldefaults tohttps://api.asksage.anl.gov/server; change it for another AskSage server. - Use AskSage's own model ids:
/model google-claude-opus-5@asksage,/model gpt-4.1@asksage. To list the ids your account can use, POST to<asksage_url>/get-modelswith anx-access-tokens: $ASKSAGE_API_KEYheader.
How it works: the router translates Anthropic requests to AskSage's /query itself, with no asksage-proxy or llm-rosetta.
The history goes over as me/gpt turns and tools as a JSON list. AskSage has no field for tool results, so earlier
tool calls and their results are written into the history as prose, and answers arrive whole, so streaming is emulated.
Claude models on AskSage handle the full tool loop (Read, ToolSearch, Bash); weaker ones (gpt-4.1) often stall on
deferred tools. Token counts are estimates, and some AskSage models return model_error while their upstream is down.
GitHub Copilot (@copilot). Log in once with gh auth login (the account needs a Copilot seat). The router runs
gh auth token (cached two minutes), or uses COPILOT_GITHUB_TOKEN, GH_TOKEN or GITHUB_TOKEN if set, and sends
the Copilot client headers. It asks /models which endpoint each model supports (cached ten minutes):
- Claude models serve the Anthropic Messages API, so requests are forwarded as they are, with streaming. Claude Code's
dashed names are mapped to Copilot's dotted ones:
claude-opus-5-5@copilotbecomesclaude-opus-5.5. gpt-*,grok-*andmai-*models only offer OpenAI's/responses. The router translates to it in process, including tool calls and tool results. Answers are requested whole and streaming is emulated, and token counts forcount_tokensare estimates. Reasoning content is not carried across turns.gemini-*models only offer/chat/completionsand are rejected with a 400.
To list your models, GET https://api.githubcopilot.com/models with Authorization: Bearer $(gh auth token),
User-Agent: GitHubCopilot/1.0.105 and Copilot-Integration-Id: copilot-developer-cli headers.
Add short names under aliases.copilot in config.json.
A bare name@google is rejected as ambiguous, because more than one backend uses that suffix. Always add a router tag.
Tool search
init sets ENABLE_TOOL_SEARCH=true, which defers most tool definitions and cuts the request size (about 37% fewer
tokens in one measurement with roughly 26 tools; your mix will differ). Claude Code decides this once per session, not per model, and the
Anthropic-only tool_reference blocks it uses are not understood by other backends. For every route except the plain
Anthropic one, the router therefore drops the defer_loading placeholder and rewrites each tool_reference into a short
text result; Claude Code already sends the loaded tool's full schema on the next request. To send every
tool definition on every request instead, set "tool_search": "false" in config.json (Claude Code also accepts
auto:N).
Configuration
Optional ~/.backend-switchboard/config.json; every key has a default:
| key | default | meaning |
|---|---|---|
port |
8790 |
local listen port (loopback only) |
tool_search |
true |
value written to ENABLE_TOOL_SEARCH in the generated Claude Code settings |
anthropic_url |
https://api.anthropic.com |
no-tag route |
mag_url |
the AMSC MAG host | @mag route |
argo_settings / argo_url |
~/.claude/settings.json / read from it |
where to find argo-shim |
asksage_url / asksage_cert |
https://api.asksage.anl.gov/server / none |
AskSage server and optional extra CA bundle |
copilot_url |
https://api.githubcopilot.com |
@copilot route |
alcf_url |
ALCF Minerva /api |
endpoint behind @alcf (Anthropic Messages API) |
aliases |
beam, muse |
short names per backend (alcf, copilot) |
Security
- The router listens on
127.0.0.1only and requires a random key on every request, sent by Claude Code throughANTHROPIC_CUSTOM_HEADERS. This matters on shared login nodes: without it, any other user on the machine could spend your Argo, MAG and ALCF credentials. The key andsettings.jsonare created with mode 600. - Upstream credentials are read per request and are never logged. The log records the model name, backend, status and duration only.
Status and limits
- Tested live: your Anthropic login, ALCF Beam and Muse, and a single conversation switched across backends between turns. The Argo and MAG routes are covered by mock-upstream tests only.
- Beam handled loading a deferred tool with
ToolSearchand then calling it reliably in every run. Muse was inconsistent: in two runs, one succeeded and one looped on tool calls until the client timed out. All requests returned 200, so this is model behavior, not routing. - When a backend is down or returns a 5xx, Claude Code retries for a few minutes, so a stopped Argo tunnel looks like a
hang. Check
~/.backend-switchboard/router.log. - ALCF does not implement the token-count endpoint (404). Claude Code falls back and the turn completes.
- Switching between an Anthropic model and ALCF models worked in testing (history includes the ALCF thinking blocks), but not with extended thinking enabled on the Anthropic side.
- Not covered: the interactive
/modelpicker UI (typing the name works), and prompt-cache behavior across backends.
Tests
python3 tests/selftest.py
See tests/README.md. Releases are cut by merging to main; the workflow bumps the version, updates
the changelog and publishes to PyPI.
License
MIT
Metadata
Release files for backend-switchboard 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| backend_switchboard-0.1.1.tar.gz | 23.5 kB | Without provenance | Details for backend_switchboard-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| backend_switchboard-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for backend_switchboard-0.1.1-py3-none-any.whl |
Total release size: 44.2 kB
Release files / backend_switchboard-0.1.1.tar.gz
| Download URL | backend_switchboard-0.1.1.tar.gz |
|---|---|
| Size | 23.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03cfd35a2c8421678e1d8aa5d22742af4a4b6b55c1bd3f1814ded809f63a7f2d
|
|
BLAKE2b-256 checksum How to use checksums |
047f710345e0d235650ea91320e336be61f77b8766d1a7d490141d9904ff7adc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / backend_switchboard-0.1.1-py3-none-any.whl
| Download URL | backend_switchboard-0.1.1-py3-none-any.whl |
|---|---|
| Size | 20.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f4c63fc0292fa649d233bc0dd332019ad7560eb6cebdc28720d33ace9a4f9fc
|
|
BLAKE2b-256 checksum How to use checksums |
7de097178e1ac2099b7ef7d30b23c18e833d2afafe6f933b5b0f2eac6af23988
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for backend-switchboard 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.