Skip to content

Function: extractModelOverride()

extractModelOverride(req): string | null

Pull a model override out of a single HTTP request, checking sources in priority order:

  1. X-Mastra-Model header
  2. ?model= query string parameter
  3. Body field (model or modelId, in that order)

Returns null when nothing is set, so callers can wrap with if (override) ... without juggling empty strings. Body inspection is lenient - any plain object with one of the configured keys counts, mirroring how AI SDK chat clients pass arbitrary metadata alongside messages.

ModelOverrideRequest

string | null