@@ -167,8 +167,19 @@ export class ApiHandler {
167167 return { 'Authorization' : `Bearer ${ apiKey } ` } ;
168168 }
169169
170+ // Handle Gemma models specifically
171+ const isGemma = modelId . includes ( 'gemma' ) ||
172+ ( provider . includes ( 'google' ) && modelId . includes ( 'gemma' ) ) ;
173+
174+ if ( isGemma ) {
175+ return {
176+ 'Authorization' : `Bearer ${ apiKey } ` ,
177+ 'Content-Type' : 'application/json'
178+ } ;
179+ }
180+
170181 // Gemini API uses x-goog-api-key header
171- if ( modelId . includes ( 'gemini' ) || modelId . includes ( 'gemma' ) || provider . includes ( 'gemini' ) ) {
182+ if ( modelId . includes ( 'gemini' ) || provider . includes ( 'gemini' ) ) {
172183 return { 'x-goog-api-key' : apiKey } ;
173184 }
174185
@@ -280,7 +291,12 @@ Your response is only the JavaScript code.`;
280291
281292 // build messages depending on heuristics (some providers expect system+user, others expect just user)
282293 const provider = ( modelConfig . provider || '' ) . toLowerCase ( ) ;
283- const isGoogleish = ! provider . includes ( 'aimlapi' ) && ( modelId . toLowerCase ( ) . includes ( 'gemini' ) || modelId . toLowerCase ( ) . includes ( 'gemma' ) || provider . includes ( 'google' ) || provider . includes ( 'vertex' ) ) ;
294+ const isGemma = modelId . toLowerCase ( ) . includes ( 'gemma' ) ;
295+ const isGoogleish = ! provider . includes ( 'aimlapi' ) &&
296+ ! isGemma &&
297+ ( modelId . toLowerCase ( ) . includes ( 'gemini' ) ||
298+ provider . includes ( 'google' ) ||
299+ provider . includes ( 'vertex' ) ) ;
284300 const isAnthropic = provider . includes ( 'anthropic' ) || modelId . toLowerCase ( ) . includes ( 'claude' ) ;
285301
286302 // prefer settings on per-model config, fallback to global
@@ -289,7 +305,17 @@ Your response is only the JavaScript code.`;
289305
290306 // Construct request body for common Chat completions patterns (best-effort)
291307 let requestBody ;
292- if ( isGoogleish ) {
308+ if ( isGemma ) {
309+ // Format for Gemma models
310+ requestBody = {
311+ model : modelId ,
312+ messages : [
313+ { role : 'user' , content : `${ systemPrompt } \n\n${ userMessage } ` }
314+ ] ,
315+ temperature : temperature ,
316+ max_tokens : max_tokens
317+ } ;
318+ } else if ( isGoogleish ) {
293319 // Gemini uses a different API format than OpenAI
294320 // Format: { contents: [{ parts: [{ text: "..." }] }] }
295321 const combinedPrompt = `${ systemPrompt } \n\n${ userMessage } ` ;
0 commit comments