fix(daemon): forward original request path and headers to upstream#191
Open
sh1ftred wants to merge 1 commit into
Open
fix(daemon): forward original request path and headers to upstream#191sh1ftred wants to merge 1 commit into
sh1ftred wants to merge 1 commit into
Conversation
Before this change, routeRequests() was called without the incoming request
path, causing the SDK to default to /v1/chat/completions even when Claude Code
was calling /v1/messages. This protocol mismatch made Claude Code fail with:
Stream completed without receiving message_start event
The fix threads the original url.pathname and sanitized request headers
(hop-by-hop headers stripped) through resolveRouteRequestContext() and into
client.routeRequest(), so:
- /v1/messages is forwarded upstream as /v1/messages (not rewritten)
- Anthropic-specific headers like anthropic-version are forwarded upstream
- Streaming responses use the correct SSE event format (message_start, etc.)
This makes the routstr daemon on port 8009 behave identically to a transparent
pass-through proxy from Claude Code's perspective.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Claude Code sends requests to
POST /v1/messages(Anthropic protocol) but theroutstr daemon was silently rewriting the upstream path to
/v1/chat/completionsbecause
routeRequests()was called without passing the incomingurl.pathname.The SDK defaults to
/v1/chat/completionswhenpathis not provided.This caused Claude Code to receive OpenAI-style SSE (
chat.completion.chunk)instead of Anthropic SSE (
message_start,content_block_delta, etc.) andfail with:
Fix
sdk/routeRequests.ts — add optional
headers?: Record<string, string>to
RouteRequestOptionsand thread it throughresolveRouteRequestContext()into
client.routeRequest().scripts/routstr-daemon.ts — add
toForwardHeaders()helper that stripshop-by-hop headers (host, connection, content-length, transfer-encoding, etc.)
and passes both
path: url.pathnameand the sanitized headers intorouteRequests().Result
The daemon now forwards the exact same path and headers the client sent, so:
/v1/messagesstays/v1/messagesupstreamanthropic-versionand other Anthropic-specific headers are preservedThis makes port
8009behave identically to a transparent pass-through proxyfrom Claude Code's perspective.