Skip to content

servingSanitize

Repairs traffic between Mastra / the AI SDK and Databricks Model Serving’s OpenAI-compatible /chat/completions route, in both directions.

Outbound (rewriteServingBody), because the transcript Mastra persists is not always a transcript the provider will accept back: Databricks-hosted Claude rejects replayed extended-thinking blocks and reads a trailing assistant message as a prefill request.

Inbound (rewriteServingResponseBody), because Databricks-hosted Gemini answers with its native content-parts array where the OpenAI contract (and therefore the AI SDK’s response schema) requires a plain string.

Every repair here is a provider quirk rather than a schema violation, so all of them are applied on the wire (see the globalThis.fetch wrapper in model.ts) rather than by changing what the agent stores or what the UI shows.