Skip to content

fix(apicompat): support array-format content in streaming chat completions#1396

Open
YanzheL wants to merge 2 commits intoWei-Shaw:mainfrom
YanzheL:fix/1247-chat-completions-array-content
Open

fix(apicompat): support array-format content in streaming chat completions#1396
YanzheL wants to merge 2 commits intoWei-Shaw:mainfrom
YanzheL:fix/1247-chat-completions-array-content

Conversation

@YanzheL
Copy link
Copy Markdown
Contributor

@YanzheL YanzheL commented Mar 30, 2026

Summary

  • normalize text-only messages[].content arrays into a plain string in the chat-completions → responses compatibility path
  • preserve multimodal arrays as structured content so image inputs continue to pass through correctly
  • add regression coverage for both the compat converter and the streaming OpenAI chat-completions forwarding path

Problem

  • OpenAI-compatible clients such as Cursor can send chat-completions messages[].content as an array instead of a string
  • streaming /v1/chat/completions requests could fail on that payload shape and return 502 upstream_error
  • plain string content and non-streaming requests were not affected

Fix

  • flatten pure text content arrays into a single string during ChatCompletionsToResponses
  • keep mixed or multimodal arrays in structured Responses API part form instead of collapsing them
  • add a service-level streaming regression test that verifies the forwarded upstream payload for Cursor-style requests

Verification

  • go test ./internal/pkg/apicompat
  • go test -tags unit ./internal/service -run 'TestExtractCCReasoningEffortFromBody|TestHandleCCBufferedFromAnthropic_PreservesMessageStartCacheUsageAndReasoning|TestHandleCCStreamingFromAnthropic_PreservesMessageStartCacheUsageAndReasoning|TestOpenAIGatewayService_ForwardAsChatCompletions_StreamTextArrayContent'
  • go test ./...
  • go build ./cmd/server
  • go test -tags=unit ./...
  • go test -tags=integration ./...
  • golangci-lint run ./... (not available in this environment: command not found)

Closes #1247

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.

[Bug] Streaming chat completions fails with array-format content (Cursor compatibility)

1 participant