CC Reverse Proxy Tutorial: Routing Claude Code and Codex Through a Single Gateway
Use local reverse proxies like cc-switch or claude-code-proxy to forward Claude Code (Anthropic) and Codex (OpenAI) through this gateway, enabling unified billing with a single API key.
I. What is this?
CC Reverse Proxy (common tools include cc-switch, claude-code-proxy) is a type of local/self-hosted forwarding proxy: it provides a unified entry point (Anthropic / OpenAI compatible) and forwards requests to your upstream provider. This allows local Claude Code (Anthropic) and Codex (OpenAI) to connect to the same reverse proxy, funneling traffic through this gateway using a single sk- API key and quota.
When your local Claude Code (Anthropic) and Codex (OpenAI) need to use this gateway, the reverse proxy dispatches the requests to the unified entry point, utilizing one key and one balance.
II. Preparation
- Log in to the Azztimes console and create an
sk-…API Key (displayed only once; please save it). - Confirm the model slugs you intend to use (one for Claude and one for GPT, or as needed).
- Confirm the gateway address:
https://www.relay-api.com.
III. Configuring CC Reverse Proxy
① Install and Start
npm install -g cc-switch # Or claude-code-proxy / corresponding tool
cc-switch start # Default local port 127.0.0.1:8787
② Point the reverse proxy "upstream" to this gateway (Key items: upstream address + API key). Using cc-switch configuration as an example:
# cc-switch configuration example
anthropic_upstream = "https://www.relay-api.com"
openai_upstream = "https://www.relay-api.com/v1"
api_key = "sk-your-key"
③ Connect Claude Code and Codex separately (point to the reverse proxy's local port):
export ANTHROPIC_BASE_URL="http://127.0.0.1:8787"
export ANTHROPIC_API_KEY="sk-your-key"
export ANTHROPIC_MODEL="claude-sonnet-5"
claude
export OPENAI_BASE_URL="http://127.0.0.1:8787"
export OPENAI_API_KEY="sk-your-key"
codex --model gpt-5.4
IV. Upstream Endpoint Reference
| Usage | Upstream Base URL |
|---|---|
| Claude Code (Claude) | https://www.relay-api.com |
| Codex (GPT) | https://www.relay-api.com/v1 |
V. Common Issues
| Symptom | Resolution |
|---|---|
| 401 / 403 | Invalid key or insufficient balance; verify the sk- key and top up if necessary. |
| 404 / Invalid Model | Confirm the upstream address uses this gateway; ensure the model is enabled. |
Security Suggestion: Do not commit your platform sk- key to public repositories; it is recommended to create a dedicated key for the reverse proxy to facilitate tracking and rate limiting.
