Proxy Routing Debugging
When to Use
When an LLM client (Hermes Agent, Codex, Claude Code, etc.) routed through a local proxy or gateway returns HTTP 400 errors like:
Unexpected message role
BadRequestError
Invalid message format
- Role-related 400 errors from OpenAI-compatible APIs
Common Root Causes
1. API Format Mismatch
The proxy may be configured for a different API format than the client sends:
- Chat Completions (
/v1/chat/completions): standard OpenAI format with role/content
- Responses (
/v1/responses): newer OpenAI format with different message structure
- Function Calling vs Tool Use: different parameter naming
Check: Look for apiFormat in proxy provider config. openai_responses ≠ Chat Completions.
2. Invalid Role Values
Only these role values are valid for OpenAI Chat Completions:
system, user, assistant, tool
Any other value (ai, bot, function, model, empty string, User, Assistant) causes 400.
3. Base URL Misconfiguration
The client may be pointing directly at the upstream provider instead of the proxy:
- Client
base_url should point to proxy address (e.g., http://127.0.0.1:15721/v1)
- Not the upstream provider (e.g.,
https://api.upstream.com/v1)
4. Middleware Transform Errors
Proxies that transform messages (role mapping, system prompt injection, tool format conversion) may introduce invalid structures.
Debugging Checklist
- Verify proxy is running: Check port is LISTENING (
netstat, ss, lsof)
- Check client config: Verify
base_url, provider, model settings
- Read error logs: Look for
BadRequestError, Unexpected message role in client logs
- Inspect proxy config: Check
apiFormat, message transformation settings
- Compare formats: Client sends Chat Completions format → proxy should expect same
- Test direct connection: Bypass proxy temporarily to confirm upstream works
- Enable proxy logging: Turn on request/response logging in proxy config
Provider-Specific Notes
CC Switch (Codex/Claude/Hermes proxy)
- Config stored in
~/.cc-switch/cc-switch.db (SQLite)
- Providers table: check
app_type, meta.apiFormat, is_current
- Proxy config: check
enabled, enable_logging, listen_port
- Settings:
~/.cc-switch/settings.json
- Logs:
~/.cc-switch/logs/cc-switch.log
Hermes Agent
- Config:
~/.hermes/config.yaml — check model.base_url, model.provider
- Logs:
~/.hermes/logs/errors.log, ~/.hermes/logs/agent.log
- Auth:
~/.hermes/auth.json for OAuth providers
Windows Netstat Encoding
netstat output may not be UTF-8. Use: chcp 65001 > nul && netstat -ano
Session-Specific References
See references/ for detailed session debugging transcripts and provider configurations.
Quick Fix Patterns
| Symptom |
Likely Cause |
Fix |
Unexpected message role |
API format mismatch |
Change apiFormat to openai_chat or point client to proxy |
| HTTP 404 |
Wrong base_url / endpoint |
Verify proxy is running on configured port |
| HTTP 401/403 |
Auth token expired/wrong |
Re-authenticate with upstream provider |
| HTTP 429 |
Rate limit |
Check provider limits, enable failover |
| Silent failure |
Proxy not intercepting traffic |
Verify base_url points to proxy, not upstream |
1---2name: proxy-routing-debug3description: Debugging guide for LLM API proxy routing issues — message format mismatches, role errors, base_url misconfigurations, and provider API format conflicts.4license: MIT5---67# Proxy Routing Debugging89## When to Use1011When an LLM client (Hermes Agent, Codex, Claude Code, etc.) routed through a local proxy or gateway returns HTTP 400 errors like:12- `Unexpected message role`13- `BadRequestError`14- `Invalid message format`15- Role-related 400 errors from OpenAI-compatible APIs1617## Common Root Causes1819### 1. API Format Mismatch20The proxy may be configured for a different API format than the client sends:21- **Chat Completions** (`/v1/chat/completions`): standard OpenAI format with `role`/`content`22- **Responses** (`/v1/responses`): newer OpenAI format with different message structure23- **Function Calling** vs **Tool Use**: different parameter naming2425**Check**: Look for `apiFormat` in proxy provider config. `openai_responses` ≠ Chat Completions.2627### 2. Invalid Role Values28Only these role values are valid for OpenAI Chat Completions:29- `system`, `user`, `assistant`, `tool`3031Any other value (`ai`, `bot`, `function`, `model`, empty string, `User`, `Assistant`) causes 400.3233### 3. Base URL Misconfiguration34The client may be pointing directly at the upstream provider instead of the proxy:35- Client `base_url` should point to proxy address (e.g., `http://127.0.0.1:15721/v1`)36- Not the upstream provider (e.g., `https://api.upstream.com/v1`)3738### 4. Middleware Transform Errors39Proxies that transform messages (role mapping, system prompt injection, tool format conversion) may introduce invalid structures.4041## Debugging Checklist42431. **Verify proxy is running**: Check port is LISTENING (`netstat`, `ss`, `lsof`)442. **Check client config**: Verify `base_url`, `provider`, `model` settings453. **Read error logs**: Look for `BadRequestError`, `Unexpected message role` in client logs464. **Inspect proxy config**: Check `apiFormat`, message transformation settings475. **Compare formats**: Client sends Chat Completions format → proxy should expect same486. **Test direct connection**: Bypass proxy temporarily to confirm upstream works497. **Enable proxy logging**: Turn on request/response logging in proxy config5051## Provider-Specific Notes5253### CC Switch (Codex/Claude/Hermes proxy)54- Config stored in `~/.cc-switch/cc-switch.db` (SQLite)55- Providers table: check `app_type`, `meta.apiFormat`, `is_current`56- Proxy config: check `enabled`, `enable_logging`, `listen_port`57- Settings: `~/.cc-switch/settings.json`58- Logs: `~/.cc-switch/logs/cc-switch.log`5960### Hermes Agent61- Config: `~/.hermes/config.yaml` — check `model.base_url`, `model.provider`62- Logs: `~/.hermes/logs/errors.log`, `~/.hermes/logs/agent.log`63- Auth: `~/.hermes/auth.json` for OAuth providers6465### Windows Netstat Encoding66`netstat` output may not be UTF-8. Use: `chcp 65001 > nul && netstat -ano`6768## Session-Specific References6970See `references/` for detailed session debugging transcripts and provider configurations.7172## Quick Fix Patterns7374| Symptom | Likely Cause | Fix |75|---------|-------------|-----|76| `Unexpected message role` | API format mismatch | Change `apiFormat` to `openai_chat` or point client to proxy |77| HTTP 404 | Wrong base_url / endpoint | Verify proxy is running on configured port |78| HTTP 401/403 | Auth token expired/wrong | Re-authenticate with upstream provider |79| HTTP 429 | Rate limit | Check provider limits, enable failover |80| Silent failure | Proxy not intercepting traffic | Verify base_url points to proxy, not upstream |