Skip to content

fix: coerce Mistral image_url parts from object to string#3177

Open
dilanmelvin wants to merge 2 commits into
HeyPuter:mainfrom
dilanmelvin:fix/mistral-image-url-coercion
Open

fix: coerce Mistral image_url parts from object to string#3177
dilanmelvin wants to merge 2 commits into
HeyPuter:mainfrom
dilanmelvin:fix/mistral-image-url-coercion

Conversation

@dilanmelvin
Copy link
Copy Markdown

Mistral's API expects image_url content parts to be a plain string URL, not the OpenAI-style { url: string } object that process_input_messages produces. Without this coercion, sending an image to any Mistral model that supports vision (mistral-small, mistral-medium, mistral-large, ministral-*) results in a request error from the Mistral SDK.

Add #coerceImageUrls() as a private method on MistralAIProvider that maps { type: 'image_url', image_url: { url } } -> { type: 'image_url', image_url: url } for every content part in every message. Messages with plain string content are left untouched, as are parts whose image_url is already a string.

Add four unit tests covering: object-to-string coercion, already-flat strings, plain string message content, and mixed text+image content.

Mistral's API expects image_url content parts to be a plain string URL,
not the OpenAI-style { url: string } object that process_input_messages
produces. Without this coercion, sending an image to any Mistral model
that supports vision (mistral-small, mistral-medium, mistral-large,
ministral-*) results in a request error from the Mistral SDK.

Add #coerceImageUrls() as a private method on MistralAIProvider that
maps { type: 'image_url', image_url: { url } } -> { type: 'image_url',
image_url: url } for every content part in every message. Messages with
plain string content are left untouched, as are parts whose image_url is
already a string.

Add four unit tests covering: object-to-string coercion, already-flat
strings, plain string message content, and mixed text+image content.
Copilot AI review requested due to automatic review settings May 28, 2026 04:26
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 28, 2026

CLA assistant check
All committers have signed the CLA.

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.

3 participants