Local Proxy for Multi-Model Access: Routing and Configuration for Coding Tools
This article explains how to route a coding tool through a local proxy to multiple LLM providers. It covers protocol mapping, installation and key storage, virtual model configuration with failover, circuit breaking, sticky sessions, weighted routing, and quota management. It also notes the limits of proxy-based compatibility and the risks of switching upstream models mid-task.
1. Use Cases and Boundaries
This setup suits three groups: developers who prefer a particular coding tool but want to switch models by task; teams that need cost accounting across models; and organizations that must keep code inside their internal network.
It also has clear boundaries. First, the proxy can only convert request and response formats; it cannot give tool-calling capability to models that do not support it. The final result depends on the upstream model itself. Second, the proxy can only connect to services that provide a compatible API or already have a built-in adapter. There is no universal solution that connects every model. Third, the proxy adds one local forwarding step. Local forwarding time is usually much smaller than upstream inference time, but in latency-sensitive scenarios, test it in your own network environment before deciding.
2. Proxy Architecture and Protocol Mapping
The workflow has three steps. The coding tool sends a standard request to the local address 127.0.0.1:3456. The proxy selects an upstream service according to routing rules and rewrites the request into the format required by that service. Finally, the proxy rewrites the data returned by the upstream back into a format the coding tool can recognize.
Interface differences across providers mainly fall into the following categories:
| Content type | Standard form from the coding tool | Common upstream differences | Proxy handling |
|---|---|---|---|
| Chat completion | messages array with roles and content |
Some use the chat completions format; others use a separate message format | Remap field names and nested structures |
| Streaming output | Server-Sent Events (SSE) returned chunk by chunk | Chunk boundaries and end markers differ | Rewrite event types chunk by chunk and preserve order |
| Tool calls | Tool name, parameter schema, and call result | Parameter definitions differ; some models do not support them at all | Convert the format; return an explicit error when unsupported, never drop silently |
| Reasoning process | Separate thinking content block | Some models do not have this field | Leave it blank when the field is missing; do not fabricate content |
| Image results | Base64 encoding or URL | Some models do not accept image input | Return an error directly when the upstream does not support it |
The “return an error directly when unsupported” behavior in the table is intentional. Silently dropping tool calls or images can make the coding tool think the task is complete, which makes troubleshooting harder.
3. Installation and Basic Configuration
The following commands use a proxy tool such as claude-code-router. Port 3456 is a common default. Package names, commands, and configuration field names depend on the installed version; refer to the official documentation for that version.
Step 1: Confirm the runtime environment. The proxy is built on Node.js and requires Node.js 18 or later; Node.js 20 LTS is recommended.
node -vnpm -v
Step 2: Install the proxy globally.
npm install -g claude-code-router
Step 3: Start the proxy and verify the port.
ccr startcurl -sS http://127.0.0.1:3456/
If the connection is refused, run ccr status first to check the process status. If the port is occupied by another program, refer to the troubleshooting table in Section 6.
Step 4: Open the web management panel. If your version provides a panel, access its management address in a local browser. The panel should listen only on 127.0.0.1, and you should set an admin password on first access.
Key Storage
Do not write API keys into configuration files. In the configuration file, reference only environment variable names; store the real values in the operating system keychain.
On macOS, write the key as follows. The command prompts interactively for input so the key does not appear in command history:
security add-generic-password -a deepseek -s llm-proxy-key -w
On macOS, read the key and export it as an environment variable:
export DEEPSEEK_API_KEY="$(security find-generic-password -a deepseek -s llm-proxy-key -w)"
On Linux, use secret-tool (requires libsecret-related packages to be installed):
secret-tool store --label="llm-proxy deepseek" service llm-proxy-key account deepseeksecret-tool lookup service llm-proxy-key account deepseek
On Windows, you can use Credential Manager to save the key, then export it as an environment variable through a startup script.
The panel provides a linked option to “start the proxy when the coding tool starts.” Before enabling it, confirm that the proxy process will terminate when the coding tool exits, rather than remaining resident in the background.
4. How to Configure Virtual Models and Failover?
A virtual model is a logical name that maps to multiple real upstreams. The coding tool only needs to specify the virtual model name, and the proxy selects the actual service.
The following is a structural example. Field names depend on the version you use, and the values are suggested starting points:
# Structural example; field names depend on your versionvirtual_models:coding-default:strategy: failoverupstreams:- provider: primary-amodel: flagship-modelpriority: 1timeout_s: 60- provider: backup-bmodel: light-modelpriority: 2timeout_s: 60circuit_breaker:trigger_status: [429, 500, 502, 503]consecutive_failures: 3cooldown_s: 300sticky_session: truebatch-cheap:strategy: weighted_round_robinupstreams:- { provider: account-1, weight: 3 }- { provider: account-2, weight: 1 }
The parameters mean the following.
priority: A lower number means higher priority. When the preferred upstream fails, the proxy tries upstreams in ascending numeric order.timeout_s: Timeout for a single request. If exceeded, it is treated as a failure and the proxy moves to the next upstream.circuit_breaker: Circuit-breaking rules. If the same upstream returns 429 or 5xx three consecutive times, it is paused for 300 seconds, after which the proxy tries to recover it.sticky_session: Session stickiness. After a session starts, it uses the same upstream until the session ends. This avoids losing context because the account switches mid-conversation.weighted_round_robin: Weighted round-robin. New requests are distributed by weight; in the example, the ratio between the two accounts is about 3:1. This suits scenarios where multiple accounts share quota.
Quota Management
If you manage multiple accounts at the same time, the panel can show the remaining quota for each account and assign an account to new sessions. In-progress sessions do not switch accounts because of quota changes.
Risk of Switching Upstreams
Failover changes the model that actually answers. If the backup model does not support tool calls, editing and execution tasks may fail after failover.
