Skip to content

Cohere route rejects image MIME types with uppercase letters #58937

Open

Description

@clean99

Description

The native Cohere route rejects image MIME types containing uppercase letters. Media.base64(data, "IMAGE/PNG") is classified as an image, but request compilation fails with Cohere Chat user messages only support text and media content for now. The same bytes with image/png work. The Chat, Responses, Messages, Converse and Gemini routes accept both spellings.

OpenCode version

2.1.4, commit 32b57015e5b491a789fba1534ecb472e676c9d8e

Steps to reproduce

From packages/ai, run this with Bun. It only compiles a request; it does not contact Cohere.

import { Effect } from "effect"
import { LLM, Media, Message } from "./src/effect.js"
import { Cohere } from "./src/providers/cohere.js"
import { compileRequest } from "./src/route/client.js"

await Effect.runPromise(
  compileRequest(
    LLM.request({
      model: Cohere.configure({ apiKey: "fixture" }).model("command-a-vision-07-2025"),
      prompt: Message.media(Media.base64("aGVsbG8=", "IMAGE/PNG")),
    }),
  ),
)

Changing only IMAGE/PNG to image/png produces an image_url block. The failure also affects URL images whose declared MIME type is Image/Png.

Operating System

macOS, Bun 1.4.4

Activity

  1. opencode-agent commented on Oct 25, 2026

    @opencode-agent
    Contributor

    Thanks for the clear report. I could reproduce this on commit 32b5701, which is also the latest dev right now.

    The script below builds the same Cohere request twice, without contacting Cohere:

    • Media.base64("aGVsbG8=", "image/png") produces an image_url block.
    • "IMAGE/PNG" fails with Cohere Chat user messages only support text and media content for now.

    The Cohere route's image check (packages/ai/src/protocols/cohere-chat.ts) compares the media type case-sensitively against image/. The other routes lowercase it first, which is why they accept both spellings. I only tested the base64 case; your URL example with Image/Png goes through the same check, so I expect it to fail the same way.

    Reproduction script (cohere-mime.ts)
    // Run from packages/ai of an opencode checkout: bun /workspace/repro/cohere-mime.ts
    // Set AI_DIR to the packages/ai directory (default: /workspace/repo/packages/ai).
    const dir = process.env.AI_DIR ?? "/workspace/repo/packages/ai"
    const { LLM, Media, Message } = await import(`${dir}/src/effect.ts`)
    const { Cohere } = await import(`${dir}/src/providers/cohere.ts`)
    const { compileRequest } = await import(`${dir}/src/route/client.ts`)
    const { Effect: E } = await import("effect")
    
    const model = Cohere.configure({ apiKey: "fixture" }).model("command-a-vision-07-2025")
    const cases: Array<[string, any]> = [
      ["base64 image/png", Media.base64("aGVsbG8=", "image/png")],
      ["base64 IMAGE/PNG", Media.base64("aGVsbG8=", "IMAGE/PNG")],
    ]
    let failed = false
    for (const [label, media] of cases) {
      const exit = await E.runPromiseExit(compileRequest(LLM.request({ model, prompt: Message.media(media) })))
      if (exit._tag === "Success") {
        console.log(`${label}: OK ->`, JSON.stringify(exit.value.body ?? exit.value).slice(0, 200))
      } else {
        failed = true
        console.log(`${label}: FAILED ->`, String(exit.cause).split("\n")[0])
      }
    }
    process.exit(failed ? 1 : 0)

    Run it: bun cohere-mime.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions