[Bug] Failover/retry not triggered when upstream Claude API relay returns empty stream or undefined error (context canceled)
Is it a request payload issue? [ ] Yes, this is a request payload issue. [x] No, it's another issue.
Describe the bug
When using multiple claude-api-key entries pointing to different third-party Claude API relays (configured for redundancy), the failover/retry mechanism fails to activate when the first upstream relay returns certain non-standard errors. Only the first relay is attempted; the remaining backup relays are never tried.
Setup: 3 Claude API relay keys configured via claude-api-key (different providers at different price tiers) to achieve high availability at lower cost than official Claude API.
What happened:
- One of the three upstream relays experienced a temporary outage.
- CLIProxyAPI's error log showed:
{"error":{"message":"context canceled","type":"server_error","code":"internal_server_error"}}
- The downstream client (Open WebUI) received:
empty_stream: upstream stream closed before first payload - The management panel showed only the first relay was activated and errored — the other two backup relays were never attempted.
- Switching
routing.strategyfromfill-firsttoround-robindid not fix the issue — still only one relay was tried. - Manually disabling the broken relay restored service immediately (the remaining two relays worked fine).
Root cause investigation:
I bypassed CLIProxyAPI and sent requests directly to the broken relay using Cherry Studio. The relay returned an error with type Undefined (no standard HTTP error code or recognizable error body). This appears to be an empty or malformed upstream response.
Key finding — the retry logic is error-type dependent:
To verify, I deliberately set an invalid API key for the broken relay in CLIProxyAPI config. This caused that relay to return a clear, well-formed error response ("invalid key"). With this explicit error, the failover worked correctly — CLIProxyAPI properly rotated to the next relay.
This confirms that the failover mechanism works fine when the upstream returns a recognizable error, but fails to trigger when the upstream returns an empty stream, undefined error, or closes the connection before sending any payload.
In summary, CLIProxyAPI's retry/failover logic does not recognize certain upstream failure modes:
- Empty response body
Undefinederror typecontext canceledbefore any payload is sent- Possibly: upstream closes connection before sending any SSE data
In these cases, the error is not matched against the retriable status codes (403, 408, 500, 502, 503, 504 per config.example.yaml), so no retry is attempted even though the request clearly failed.
CLI Type
claude-api-key (third-party Claude API relays via claude-api-key with custom base-url)
Model Name Claude Opus 4.6 | Anthropic
LLM Client Open WebUI (connecting to CLIProxyAPI as OpenAI-compatible endpoint)
Request Information
CLIProxyAPI error log at the time of failure:
=== API RESPONSE ===
Timestamp: 2026-03-17T18:06:52.850475624+08:00
{"error":{"message":"context canceled","type":"server_error","code":"internal_server_error"}}
=== RESPONSE ===
Status: 500
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
Access-Control-Allow-Headers: *
Content-Type: application/json
{"error":{"message":"context canceled","type":"server_error","code":"internal_server_error"}}
Relevant config:
routing:
strategy: "round-robin" # also tested with fill-first, same result
request-retry: 3 # default
claude-api-key:
- api-key: "sk-relay-A..."
base-url: "https://relay-a.example.com"
- api-key: "sk-relay-B..."
base-url: "https://relay-b.example.com"
- api-key: "sk-relay-C..."
base-url: "https://relay-c.example.com"
Expected behavior
When the first upstream relay fails (regardless of error type — including empty streams, context cancellation, or undefined errors), CLIProxyAPI should retry with the next available relay credential, up to request-retry times. The current behavior only retries on recognized HTTP error codes, which means a relay that fails in a "silent" way (empty body, connection reset before payload, undefined error) will block all requests without triggering failover — defeating the purpose of multi-relay redundancy.
Specifically:
- Any upstream response that results in
empty_stream/context canceledshould be treated as a retriable failure. - If the upstream closes the connection before sending any SSE data, it should trigger credential rotation.
- The failover mechanism should not depend on receiving a well-formed error response from the upstream.
Version CLIProxyAPI v6.8.55 (Commit: db63f9b5, Built: 2026-03-16T14:33:45Z)
Hi, I looked into this and found the root cause in the conductor's streaming retry logic.
In executeStreamWithModelPool (sdk/cliproxy/auth/conductor.go), when the last model in the pool encounters a bootstrap error (e.g. empty stream, context canceled, or a retriable HTTP status), it wraps the error into a StreamChunk channel and returns (result, nil). Because the error is nil, the caller executeStreamMixedOnce treats the call as successful and never rotates to the next auth credential.
This is different from the HTTP (non-streaming) path, which correctly returns the error and lets the inner loop try the next credential.
The fix is straightforward: remove the last-model special case so all models follow the same error handling path — call MarkResult to update the scheduler, discard remaining stream chunks, and propagate the error. This allows the auth rotation loop to pick the next available credential, which is the expected behavior.
I've submitted a PR with the fix and tests: #2210
Thanks for the detailed report and the follow-up investigation.
I rechecked this against the current dev/main branch. The failure mode described here was present in v6.8.55: on the last pooled stream attempt, executeStreamWithModelPool wrapped bootstrap and empty-stream errors into a StreamChunk channel and returned a nil error, so executeStreamMixedOnce treated the call as successful and did not rotate to the next credential.
Current code no longer has that behavior. In sdk/cliproxy/auth/conductor.go, bootstrap errors and empty streams now return newStreamBootstrapError(...) as a non-nil error, and executeStreamMixedOnce continues to the next auth credential when the error is retryable. This fix is present in the current release line (v6.9.33+, including v6.10.2). PR #2222 also added related cross-auth fallback coverage.
I am closing this as completed because the reported bug no longer reproduces in current main. If this still happens on v6.9.33 or newer, please reopen with the exact version, routing config, and a fresh request log showing the selected auth sequence.