hi everyone! today I want to share a small trick I used to make AgentRouter work with OpenCode when the service only accepts a handful of official AI clients (Codex, Qwen Code, Claude Code, and so on).
If you log in with an older GitHub account, AgentRouter can give you a decent balance, but when you try to use it directly you’ll hit a client restriction error like this:
❯ opencode run "Who are you" --model=agentrouter/deepseek-v3.2
> build · deepseek-v3.2
Error: unauthorized client detected, contact support for assistance at https://discord.com/invite/V6kaP6Rg44So I made a tiny reverse proxy that forwards requests to AgentRouter and spoofs the same headers used by the Codex CLI. After that, OpenCode works fine.
Steps
1. Create the proxy
Save this as main.go:
package main
import ( "log" "net/http" "net/http/httputil" "net/url")
func main() { // The target API we are forwarding to targetURL := "https://agentrouter.org" target, err := url.Parse(targetURL) if err != nil { log.Fatal("Failed to parse target URL:", err) }
// Create a built-in reverse proxy proxy := httputil.NewSingleHostReverseProxy(target)
// Intercept and modify the request before it goes out originalDirector := proxy.Director proxy.Director = func(req *http.Request) { originalDirector(req)
// Override Host header for proper SSL routing at the destination req.Host = target.Host
// Inject the required Codex headers req.Header.Set("Originator", "codex_cli_rs") req.Header.Set("User-Agent", "codex_cli_rs/0.101.0 (Mac OS 26.0.1; arm64) Apple_Terminal/464") req.Header.Set("Version", "0.101.0") }
// Start the server port := ":8318" log.Printf("🚀 Proxy running on http://localhost%s\n", port) log.Printf("➡️ Configure OpenCode Base URL to: http://localhost%s/v1\n", port)
if err := http.ListenAndServe(port, proxy); err != nil { log.Fatal("Server error:", err) }}2. Build the binary
go build -ldflags="-s -w" -o agentrouter-proxy main.go3. Run and test
Start the proxy, then point OpenCode to http://localhost:8318/v1. After that, you should be able to call the model without the client restriction:
❯ opencode run "Who are you" --model=agentrouter/deepseek-v3.2
> build · deepseek-v3.2
I'm opencode, an interactive CLI tool that helps with software engineering tasks.Extra: systemd auto-start
If you want the proxy to always run in the background, create a systemd user service like this:
[Unit]Description=AgentRouter ProxyAfter=network.target
[Service]# systemd requires absolute paths. %h resolves to your home directory (e.g., /home/username)ExecStart=/home/LIGHT/Documents/Tools/AgentRouter/agentrouter-proxyRestart=alwaysRestartSec=3
# Optional: Limits memory usage to 50MB just as a safety netMemoryHigh=50MMemoryMax=100M
[Install]WantedBy=default.targetSave it to ~/.config/systemd/user/agentrouter-proxy.service, then enable it:
systemctl --user enable --now agentrouter-proxy.serviceThat’s it. Your proxy will now start automatically on every boot.