Responses route: reasoning sent as typed content-part arrays (delta.content / message.content) reaches the client as raw JSON text
Summary
When an OpenAI-compatible upstream (such as Mistral serving deepseek-v4-1-flash-1017, zai-glm-5-3, or zai-glm-5-3-flash) returns reasoning as typed content-part arrays inside choices[0].delta.content (streaming) or choices[0].message.content (non-streaming), the OpenAI Chat Completions to OpenAI Responses translator (internal/translator/openai/openai/responses/openai_openai-responses_response.go) treats content as a plain string via ojson.Result.String().
As a result, the raw JSON array representation of every thinking chunk is emitted verbatim into response.output_text.delta / output_text and concatenated into the assistant's visible text, while no reasoning output item or response.reasoning_summary_text.delta events are produced.
This is the /v1/responses counterpart to #7255 (which was fixed for the Claude /v1/messages response translator in commit 6044c5d14270fa094333b25932ac11ab13282821).
Evidence Chain & Observed Behavior
1. Upstream Streaming SSE Payload (api.mistral.ai/v1/chat/completions)
When reasoning occurs on Mistral (deepseek-v4-1-flash-1017 with reasoning_effort, or zai-glm-5-3 / zai-glm-5-3-flash by default), the upstream does not populate delta.reasoning_content. Instead, it streams typed content-part arrays in choices[0].delta.content, then switches back to plain strings once thinking closes:
data: {"id":"bf39068555d24f22aaa60dc43231a002","object":"chat.completion.chunk","created":1794374142,"model":"deepseek-v4-1-flash-1017","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"bf39068555d24f22aaa60dc43231a002","object":"chat.completion.chunk","created":1794374142,"model":"deepseek-v4-1-flash-1017","choices":[{"index":0,"delta":{"index":0,"content":[{"type":"thinking","thinking":[{"type":"text","text":"The"}],"closed":true}]},"finish_reason":null}]}
data: {"id":"bf39068555d24f22aaa60dc43231a002","object":"chat.completion.chunk","created":1794374142,"model":"deepseek-v4-1-flash-1017","choices":[{"index":0,"delta":{"index":0,"content":[{"type":"thinking","thinking":[{"type":"text","text":"erse."}],"closed":true},{"type":"text","text":"收到,链路"}]},"finish_reason":null}]}
data: {"id":"bf39068555d24f22aaa60dc43231a002","object":"chat.completion.chunk","created":1794374142,"model":"deepseek-v4-1-flash-1017","choices":[{"index":0,"delta":{"index":0,"content":"正常"},"finish_reason":null}]}
data: {"id":"bf39068555d24f22aaa60dc43231a002","object":"chat.completion.chunk","created":1794374142,"model":"deepseek-v4-1-flash-1017","choices":[{"index":0,"delta":{"index":0,"content":""},"finish_reason":"stop"}],"usage":{"prompt_tokens":31,"total_tokens":62,"completion_tokens":31,"completion_tokens_details":{"reasoning_tokens":21}}}
2. Upstream Non-Streaming JSON Payload
Similarly, on non-streaming responses, choices[0].message.content is returned as a JSON array of typed parts:
{
"id": "bd5377d8250c4022b9a1b4dcb258ec4b",
"object": "chat.completion",
"model": "deepseek-v4-1-flash-1017",
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"role": "assistant",
"tool_calls": null,
"content": [
{
"type": "thinking",
"thinking": [
{
"type": "text",
"text": "We need answer to \"test\". Respond concise."
}
],
"closed": true
},
{
"type": "text",
"text": "Test received. How can I help?"
}
]
}
}
]
}
3. Root Cause in openai_openai-responses_response.go
- Streaming (
ConvertOpenAIChatCompletionsResponseToOpenAIResponses, line 965):
Whenif c := delta.Get("content"); c.Exists() && c.String() != "" { ... _ = msgDoc.Set("delta", c.String()) st.MsgTextBuf[idx].WriteString(c.String()) }cis anojsonarray,c.String()returns the raw JSON text of the array ([{"type":"thinking",...}]). Each chunk's raw JSON array is emitted asresponse.output_text.deltaand concatenated into the final assistant message:[{"type":"thinking","thinking":[{"type":"text","text":"The"}],"closed":true}]...[{"type":"thinking","thinking":[{"type":"text","text":"erse."}],"closed":true},{"type":"text","text":"收到,链路"}]正常 - Non-Streaming (
ConvertOpenAIChatCompletionsResponseToOpenAIResponsesNonStream, lines 1134–1173):choices.0.message.reasoning_contentandchoices.0.message.reasoningare empty, whilemsg.Get("content").String()dumps the raw JSON array intocontent.0.textof themessageoutput item.
Expected Behavior
- Streaming (
ConvertOpenAIChatCompletionsResponseToOpenAIResponses): Whendelta.contentis an array, iterate through its parts in order:- Map
"thinking"/"reasoning"parts (extracting nested text fragments or plain strings) toresponse.reasoning_summary_text.deltaevents within areasoningoutput item. - Map
"text"parts (and unknown fallback parts) toresponse.output_text.deltaevents within amessageoutput item, closing any openreasoningitem at the transition boundary.
- Map
- Non-Streaming (
ConvertOpenAIChatCompletionsResponseToOpenAIResponsesNonStream): Whenmessage.contentis an array, extract"thinking"/"reasoning"parts as fallback reasoning text for thereasoningoutput item'ssummary_text, and join"text"parts (and unknown fallback parts) for themessageoutput item'soutput_text.
Confirmed fixed in dev via commit c3a6c741 (translate typed thinking content-part arrays in responses translator), including reasoning-only stream finalization on explicit finish_reason. Verified with the upstream test suite — all translator tests pass. Thanks @luispater for the merged implementation!