Skip to content

Issue connecting to grok model #84

Description

@machingclee

I was constantly plagued with the problem from clauded code stating that

API Error: Server error mid-response. The response above may be incomplete

I discussed with grok, back end forth (fixing, trying), and spotted the root cause is an SSE event that may seem valid to grok but invalid to claude-code-proxy (like "event: { ... }" instead of "data: { ... }").

After vibe coding the steps to fix this are as follows, and all my problems with claude code are gone:

  1. Clone/use https://github.com/raine/claude-code-proxy (latest release, e.g. v0.1.26).
  2. Optionally cherry-pick/merge open PR fix(grok): stabilize prefix cache and long-stream timing #57 (Grok prefix cache / no 120s timeout / reasoning replay) if not already in the release.
  3. In src/providers/grok/client.rs:
    • Remove whole-request .timeout(Duration::from_secs(120)).
    • Keep .connect_timeout(10s) + tcp_nodelay.
    • Do NOT enable http2_keep_alive_interval / http2_keep_alive_timeout (they abort during silent Grok reasoning).
  4. In src/providers/grok/translate/stream.rs SseDecoder/parse_frame:
    • Comment-only and id-only SSE frames must be ignored (Ok(None)), NOT "Grok SSE frame lacks data" errors.
  5. Optional but recommended in src/providers/grok/mod.rs stream loop:
    • While waiting on upstream, every ~5s emit SSE comment ": keepalive\n\n" to Claude so client idle (~15s) doesn't abort.
    • Log mid-stream failures (malformed_sse etc.) even when HTTP status is already 200.
  6. cargo test (at least providers::grok), cargo build --release, install binary somewhere early on PATH, restart claude-code-proxy serve.
  7. Verify: long high-effort multi-tool Grok session completes without mid-response; proxy.log should not show grok_stream_failed/malformed_sse on normal turns.

Would someone help make an equivalent fix in rust (I am only a beginner level Rustacean and don't want to pollute the codebase)?

Thanks alot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions