Skip to content

ReasoningContent not forwarded in streaming responses despite ReasoningFormat being set #17

@edenreich

Description

@edenreich

Summary

When using the SDK with ReasoningFormat: "parsed" for reasoning models (e.g., deepseek/deepseek-reasoner), the reasoning content is not being forwarded to the client application despite the underlying API correctly providing reasoning content in the stream.

Environment

  • SDK Version: Latest from main branch
  • Go Version: 1.24+
  • Model: deepseek/deepseek-reasoner
  • Request Type: Streaming chat completion with ReasoningFormat: "parsed"

Expected Behavior

When setting ReasoningFormat: "parsed" for reasoning models, the SDK should forward the reasoning_content field from the API response to the client application through the ChatCompletionStreamChoice.Delta or provide it through a dedicated field.

Actual Behavior

The SDK does not forward any reasoning content to the client application. All ChatChunkEvent objects have empty ReasoningContent fields, even though the underlying API stream contains reasoning content.

Evidence

1. Direct API Test (Working)

curl -X POST http://localhost:8080/v1/chat/completions -d '{
  "model": "deepseek/deepseek-reasoner",
  "messages": [{"role": "user", "content": "Hi"}],
  "stream": true,
  "reasoning_format": "parsed"
}'

Result: Returns chunks with "reasoning_content": "Hmm, the user starts with..."

2. SDK Implementation (Not Working)

reasoningFormat := "parsed"
options := &sdk.CreateChatCompletionRequest{
    ReasoningFormat: &reasoningFormat,
}
client.WithOptions(options).GenerateContentStream(ctx, provider, model, messages)

Result: All chunks have empty reasoning content ❌

Despite receiving regular content chunks correctly.

Code Analysis

The issue appears to be in the SDK's stream processing logic where:

  1. ✅ Request Setup: ReasoningFormat parameter is correctly set and sent to the API
  2. ❌ Response Processing: The reasoning content from the API response is not being extracted or forwarded
  3. ✅ Regular Content: Normal content chunks are processed correctly

Impact

This prevents client applications from implementing reasoning model features like:

  • Showing "Thinking..." status during reasoning phases
  • Displaying reasoning steps to users
  • Proper UX flow for reasoning models

Reproduction Steps

  1. Set up SDK with reasoning model (deepseek/deepseek-reasoner)
  2. Set ReasoningFormat: "parsed" in request options
  3. Create streaming chat completion
  4. Observe that no reasoning content is received in stream chunks
  5. Compare with direct API call which shows reasoning content is available

Suggested Investigation Areas

  1. Stream parsing logic: Check if reasoning_content field is being parsed from API response
  2. Delta creation: Verify reasoning content is included when creating ChatCompletionStreamChoice.Delta
  3. Event forwarding: Ensure reasoning content is properly forwarded to client event handlers

Related Documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions