Responses API output_text is null for OpenAI-compatible non-streaming responses
Bug
When /v1/responses is backed by an OpenAI-compatible chat completions provider, CLIProxyAPI returns generated text inside output[].content[].text, but the top-level output_text field is missing/null.
Many Responses API clients read response.output_text directly, so they display an empty result even though the model generated text and usage reports output tokens.
Reproduction shape
Request:
{
"model": "gpt-5.4",
"input": "Reply with exactly: ping",
"max_output_tokens": 32
}
Observed response shape:
{
"status": "completed",
"output_text": null,
"output": [
{
"type": "message",
"content": [
{ "type": "output_text", "text": "ping" }
]
}
],
"usage": { "output_tokens": 5 }
}
Expected
Top-level output_text should be populated with the concatenated assistant output text:
{
"output_text": "ping"
}
Likely fix
In internal/translator/openai/openai/responses/openai_openai-responses_response.go:
- In
ConvertOpenAIChatCompletionsResponseToOpenAIResponsesNonStream, aggregate eachchoices[].message.contentstring while building message output items. - Set
resp.output_textto the concatenated value when non-empty. - In the streaming completed event builder, aggregate
st.MsgTextBufin output order and setresponse.output_textonresponse.completed.
Potential helper:
func responseOutputTextFromMessageBuffers(msgTextBuf map[int]*strings.Builder, msgOutputIx map[int]int) string {
type textItem struct {
outputIndex int
text string
}
items := make([]textItem, 0, len(msgTextBuf))
for choiceIndex, b := range msgTextBuf {
if b == nil || b.Len() == 0 {
continue
}
items = append(items, textItem{outputIndex: msgOutputIx[choiceIndex], text: b.String()})
}
sort.Slice(items, func(i, j int) bool { return items[i].outputIndex < items[j].outputIndex })
var out strings.Builder
for _, item := range items {
out.WriteString(item.text)
}
return out.String()
}
Then set:
if outputText := responseOutputTextFromMessageBuffers(st.MsgTextBuf, st.MsgOutputIx); outputText != "" {
completed, _ = sjson.SetBytes(completed, "response.output_text", outputText)
}
For non-streaming, accumulate outputText.WriteString(c.String()) near the message item creation, then:
if outputText.Len() > 0 {
resp, _ = sjson.SetBytes(resp, "output_text", outputText.String())
}
Workaround
Clients can read output[].content[].text as a fallback when output_text is absent/null.
Reviewed this against the native gpt-5.4 /v1/responses streaming output.
The native Responses result does not include a top-level response.output_text; assistant text is carried under response.output[].content[].text. After restarting the service and comparing the same request with gpt-5.4 and agnes-2.0-flash, both now match on this contract: no top-level output_text, message text in output[].content[].text, and tool calls kept as separate function_call output items.
Because the reported shape is now considered the expected compatibility target rather than a repository bug, closing this as not planned.