Skip to content

fix: correct streaming id/model extraction and multi-format usage tracking#28

Merged
john-zhh merged 1 commit intofeat/v3.0.1from
fix/streaming-protocol-fixes
Mar 12, 2026
Merged

fix: correct streaming id/model extraction and multi-format usage tracking#28
john-zhh merged 1 commit intofeat/v3.0.1from
fix/streaming-protocol-fixes

Conversation

@john-zhh
Copy link
Copy Markdown
Contributor

Summary

  • stream.go: response.created/response.in_progress now correctly reads id and model from the nested response object (not top-level) — fixes wrong id/model in emitted chat.completion.chunk objects
  • stream.go: Added response.output_item.added handler to capture call_id and name per tool call index; first delta now emits full header (id, type: "function", function.name, first args chunk)
  • server.go: sseUsageExtractor.processChunk now handles three SSE formats:
    • Anthropic: message_start / message_delta (existing)
    • Responses API: response.completed with nested response.usage
    • OpenAI Chat: no type field, final chunk with top-level usage.prompt_tokens / completion_tokens
  • Tests: streaming tests now assert id, model, tool_call.id, and function.name; usage extractor tests cover all three formats

Test plan

  • TestTransformResponsesAPIToOpenAIChat_Text — asserts chatcmpl-resp_chat1 id and gpt-5 model in output chunks
  • TestTransformResponsesAPIToOpenAIChat_ToolCall — asserts call_abc tool call id and get_weather function name
  • TestSSEUsageExtractor/extracts_usage_from_responses_api_sse — covers response.completed usage extraction
  • TestSSEUsageExtractor/extracts_usage_from_openai_chat_sse — covers OpenAI Chat final chunk usage extraction
  • All unit tests pass, internal/proxy coverage ≥ 80.2%, internal/proxy/transform ≥ 87.7%

🤖 Generated with Claude Code

…cking

- stream.go: extract id/model from nested response object in
  response.created/in_progress events (was reading wrong top-level key)
- stream.go: capture call_id/name from response.output_item.added so
  first tool_calls delta includes proper id and function.name header
- stream.go: emit full tool call header (id, type, function.name,
  first args) on first delta; subsequent deltas carry args only
- server.go: sseUsageExtractor.processChunk now handles Responses API
  response.completed events and OpenAI Chat final chunks (no "type"
  field, usage at top level with prompt_tokens/completion_tokens)
- tests: assert id and model fields in streaming chunks; add
  response.output_item.added to tool call test; cover Responses API
  and OpenAI Chat usage extraction in sseUsageExtractor tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@john-zhh john-zhh merged commit 9b9dd51 into feat/v3.0.1 Mar 12, 2026
4 checks passed
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