Hello, reporting an issue with Gemma 3 in Workers AI, or maybe just the documentation about it. Th

Hello, reporting an issue with Gemma 3 in Workers AI, or maybe just the documentation about it.

The Gemma 3 model is not behaving as documented. Two issues so far:
1. (minor but a bit annoying) "@cf/google/gemma-3-12b-it" is not included in
wrangler types

2. the following code chokes, even though correct per the official doc page (https://developers.cloudflare.com/workers-ai/models/gemma-3-12b-it/) . The part it dislikes is messages[1].content being an object instead of string. The string format only works for text, however, not image, i.e. {role: 'user', content: dataUri} will not choke but Gemma will completely hallucinate the actual content of the image, while recognizing the same image just fine if uploaded in aistudio.google.com.

const res = await fetch(https://cataas.com/cat);
const blob = await res.arrayBuffer();
const imageData = [...new Uint8Array(blob)];

const base64 = btoa(String.fromCharCode(...imageData));
const dataUri = data:image/jpeg;base64,${base64};

const response = await env.AI.run(
"@cf/google/gemma-3-12b-it",
{
messages: [
{role: 'system', content: 'describe uploaded images'},
{role: 'user',
content: {
type: 'image', // tried with and without this line
image_url: {url: dataUri}
}
}
]
}).catch(e => {
console.error(AI.run error, e);
throw e;
});

return new Response(JSON.stringify(response), {
headers: [['content-type', 'application/json']]
});
Was this page helpful?