Function: flattenChoiceMessageContent()
flattenChoiceMessageContent(
payload):boolean
Collapse a structured choices[].message.content array to the plain string
the OpenAI Chat Completions contract specifies.
Databricks-hosted Gemini answers a non-streaming /chat/completions call
with the Gemini-native parts shape:
"content": [{ "type": "text", "text": "...", "thoughtSignature": "..." }]@ai-sdk/openai-compatible validates the response against the OpenAI
schema, where content is a nullable string, so it throws
Type validation failed: ... expected string, received array and the whole
call fails (AI_APICallError: Invalid JSON response on an HTTP 200). Mastra
uses doGenerate for its side calls, so the visible symptom is
Error generating title - every thread keeps its placeholder name.
Flattening on the wire keeps the repair in one place: the streaming path is
unaffected (deltas already carry string content), and neither the agent’s
stored transcript nor the UI has to know the provider emitted parts. Any
non-text part (a thoughtSignature-only entry, an inline image) contributes
nothing, matching openaiChat.chatContentToText, and an all-parts-empty
message flattens to "" rather than being dropped, so finish_reason and
usage still round-trip.
Parameters
Section titled “Parameters”payload
Section titled “payload”Record<string, unknown>
Returns
Section titled “Returns”boolean