Skip to content

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

Merged
ProgrammerIn-wonderland merged 2 commits into
HeyPuter:mainfrom
dilanmelvin:fix/mistral-image-url-coercion
Jun 10, 2026
Merged

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

Conversation

@dilanmelvin

Copy link
Copy Markdown
Contributor

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

CLAassistant commented May 28, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@ProgrammerIn-wonderland
ProgrammerIn-wonderland merged commit 3e9ceb6 into HeyPuter:main Jun 10, 2026
4 checks passed
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