You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
V2 media normalization double-prefixes uppercase DATA: URLs #47538
The image URL in prepared.body.messages contains the double prefix shown above. Repeating with AAECAw== or data:image/png;base64,AAECAw== produces the expected URL.
This checks request encoding only: the bytes are a small test fixture, not a PNG, and no provider call is needed.
At 7a4ad68af6: with your OpenAI Chat test, AAECAw== and data:image/png;base64,AAECAw== both produce data:image/png;base64,AAECAw==. DATA:image/png;base64,AAECAw== produces data:image/png;base64,DATA:image/png;base64,AAECAw==.
On the latest dev (b6c43a524): the media API has been refactored, so your exact { type: "media", data: "..." } input no longer applies. The same bug is still there:
A tool-result file with uri DATA:image/png;base64,AAECAw== compiles to the same double-prefixed image_url for OpenAI Chat.
The likely cause now is the case-sensitive DATA_URL regex in packages/ai/src/media.ts, which ProviderShared.toolFileMedia relies on. imageOutput in protocols/utils/media-input.ts also uses a case-sensitive startsWith("data:"). Your earlier PR #47648 targeted the old packages/llm code and was auto-closed. A fix now would need to go in packages/ai.
The script below writes and runs a bun test that reproduces this on dev.
Related, but not the same problem: #47583 (uppercase BASE64 flag in server-side text attachments) and #58937 (uppercase image MIME types in the Cohere route).
Reproduction script (repro-47538.sh)
#!/usr/bin/env bash# Reproduces anomalyco/opencode#47538 on current dev: uppercase DATA: URLs get a second data: prefix.# Usage: REPO=/path/to/opencode-checkout bash repro-47538.sh (after `bun install` in the checkout)set -euo pipefail
cd"${REPO:-/workspace/repo}/packages/ai"
cat > test/provider/repro-47538.test.ts <<'EOF'// Reproduction for anomalyco/opencode#47538 on current dev (packages/ai).// Run from packages/ai: bun test test/provider/repro-47538.test.tsimport { describe, expect } from "bun:test"import { Effect } from "effect"import { LLM, Media, Message, ToolCallPart } from "../../src/effect.js"import * as OpenAIChat from "../../src/protocols/openai-chat.js"import { Auth } from "../../src/route.js"import { compileRequest } from "../../src/route/client.js"import { it } from "../lib/effect.js"const model = OpenAIChat.route .with({ endpoint: { baseURL: "https://api.openai.test/v1/" }, auth: Auth.bearer("test") }) .model({ id: "gpt-4o-mini" })describe("#47538", () => { for (const uri of ["data:image/png;base64,AAECAw==", "DATA:image/png;base64,AAECAw=="]) { it.effect(`parseDataUrl ${uri}`, () => Effect.sync(() => { const parsed = Media.parseDataUrl(uri) console.log("parseDataUrl", uri, "=>", parsed?.source) expect(parsed).toBeDefined() }), ) it.effect(`tool-result file ${uri}`, () => Effect.gen(function* () { const prepared: any = yield* compileRequest( LLM.request({ model, messages: [ Message.user("Show me the screenshot."), Message.assistant([ToolCallPart.make({ id: "call_1", name: "read", input: { filePath: "shot.png" } })]), Message.tool({ id: "call_1", name: "read", resultType: "content", result: [{ type: "file", uri, mime: "image/png" }], }), ], }), ) const body = JSON.stringify(prepared.body.messages) const urls = body.match(/"url":"[^"]*"/g) console.log("tool file", uri, "=>", urls) expect(body).toContain('"url":"data:image/png;base64,AAECAw=="') expect(body).not.toContain("DATA:") }), ) }})EOF
bun test test/provider/repro-47538.test.ts
Fixed by #60963, which recognizes data URLs regardless of scheme case, so uppercase DATA: URLs are no longer double-prefixed. If you still see this on the latest version, comment here and we'll reopen.
Activity
opencodejr commentedon Oct 28, 2026
Thanks for the clear report. I reproduced this.
7a4ad68af6: with your OpenAI Chat test,AAECAw==anddata:image/png;base64,AAECAw==both producedata:image/png;base64,AAECAw==.DATA:image/png;base64,AAECAw==producesdata:image/png;base64,DATA:image/png;base64,AAECAw==.dev(b6c43a524): the media API has been refactored, so your exact{ type: "media", data: "..." }input no longer applies. The same bug is still there:Media.parseDataUrl("DATA:image/png;base64,AAECAw==")returnsundefined.DATA:image/png;base64,AAECAw==compiles to the same double-prefixedimage_urlfor OpenAI Chat.The likely cause now is the case-sensitive
DATA_URLregex inpackages/ai/src/media.ts, whichProviderShared.toolFileMediarelies on.imageOutputinprotocols/utils/media-input.tsalso uses a case-sensitivestartsWith("data:"). Your earlier PR #47648 targeted the oldpackages/llmcode and was auto-closed. A fix now would need to go inpackages/ai.The script below writes and runs a bun test that reproduces this on
dev.Related, but not the same problem: #47583 (uppercase
BASE64flag in server-side text attachments) and #58937 (uppercase image MIME types in the Cohere route).Reproduction script (repro-47538.sh)
Run it:
bash repro-47538.shneriousy commentedon Nov 19, 2026
Fixed by #60963, which recognizes data URLs regardless of scheme case, so uppercase DATA: URLs are no longer double-prefixed. If you still see this on the latest version, comment here and we'll reopen.