Skip to content

fix(ai): accept uppercase image MIME types in the Cohere route - #59010

Closed
kpmgprd101-ops wants to merge 1 commit into
anomalyco:devfrom
kpmgprd101-ops:fix-cohere-uppercase-image-mime
Closed

kpmgprd101-ops wants to merge 1 commit into
anomalyco:devfrom
kpmgprd101-ops:fix-cohere-uppercase-image-mime

Conversation

@kpmgprd101-ops

Copy link
Copy Markdown

Issue for this PR

Closes #58937

Type of change

  • Bug fix

What does this PR do?

The Cohere Chat protocol checked part.media.mediaType.startsWith("image/") case-sensitively, so Media.base64(data, "IMAGE/PNG") (or a URL asset declared Image/Png) fell through to the unsupported-content error: Cohere Chat user messages only support text and media content for now. Every other route that classifies media lowercases the type first (anthropic-messages, mistral-chat), which is why they accepted both spellings. The fix lowercases before the prefix check, one line in packages/ai/src/protocols/cohere-chat.ts.

The data URL itself already comes out lowercase (media.ts normalizes it), so no wire-format change.

How did you verify your code works?

  • Added a regression test compiling a Cohere request with both an inline IMAGE/PNG base64 image and a URL image declared Image/Png; it asserts both lower to image_url blocks. It fails with the exact error from the issue without the fix and passes with it.
  • Full packages/ai suite: 1920 tests, 0 failures.
  • bun check (no type errors) and biome check clean on the touched files.

Screenshots / recordings

N/A (protocol compile only).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@opencode-agent opencode-agent Bot closed this Oct 25, 2026
@opencode-agent

Copy link
Copy Markdown
Contributor

Thanks for the fix and the clear write-up, including the regression test for both inline and URL images!

I think this duplicates #58943, which was opened earlier for the same issue (#58937). It changes the same image check in packages/ai/src/protocols/cohere-chat.ts to part.media.kind === "image", which also ignores letter case. It also adds tests for upper-, lower- and mixed-case media types on base64, bytes and URL images. If you think something is missing there, you're very welcome to review or test #58943, or leave a comment on it.

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.

Cohere route rejects image MIME types with uppercase letters

2 participants