Skip to content

Fix Anthropic SSE parsing for data: lines without spaces#5

Open
Hcaepllams wants to merge 1 commit intoagentsmith-project:mainfrom
Hcaepllams:fix-kimi-sse-spacing
Open

Fix Anthropic SSE parsing for data: lines without spaces#5
Hcaepllams wants to merge 1 commit intoagentsmith-project:mainfrom
Hcaepllams:fix-kimi-sse-spacing

Conversation

@Hcaepllams
Copy link
Copy Markdown

Summary

  • fix SSE parsing to accept data: lines without a trailing space
  • restore Responses streaming when using Anthropic-compatible upstreams such as Kimi
  • add a regression test covering the no-space data: format
  • document the recommended Kimi -> Codex setup in the README

Problem

Some Anthropic-compatible upstreams emit SSE lines like:

data:{"type":"message_start", ...}                                                                                                                                                                         
                                                                                                                                                                                                           
instead of:                                                                                                                                                                                                
                                                                                                                                                                                                           
data: {"type":"message_start", ...}                                                                                                                                                                        
                                                                                                                                                                                                           
The parser only accepted data:  with a trailing space, so those events were dropped.                                                                                                                       
                                                                                                                                                                                                           
In practice this caused translated OpenAI Responses streams to appear empty, and Codex failed with:                                                                                                        
                                                                                                                                                                                                           
- stream closed before response.completed                                                                                                                                                                  
                                                                                                                                                                                                           
Fix                                                                                                                                                                                                        
                                                                                                                                                                                                           
take_one_sse_event() now accepts any data: prefix and trims the remainder before parsing JSON.                                                                                                             
                                                                                                                                                                                                           
Validation                                                                                                                                                                                                 
                                                                                                                                                                                                           
- added a unit test for data:{...} SSE lines                                                                                                                                                               
- verified responses_endpoint_streaming_translates_to_anthropic_upstream still passes                                                                                                                      
- verified a real Codex -> proxy -> Kimi flow now completes successfully

Accept Anthropic-compatible SSE events that use `data:` without a trailing space so translated Responses streams can complete correctly. Document the recommended Kimi-to-Codex Anthropic setup and the relaxed SSE parsing behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant