Repository: vercel/ai (TypeScript)

Issue:
Google models can't "see" images returned from tool calls
### Description

It seems that calling`toModelOutput` when using models from `@ai-sdk/google` does not map the content properly, and the models cant "see" the images.

If I ask sonnet "Whats in this image", and it calls a tool that responds with an image, sonnet will be able to "see" and describe the image, but when using gemini, it doens't work. 

I suspect it has something to do with the `convert-to-google-generative-ai-messages.ts` file, will probably take a look at it later.

Heres an example for my tool - it just responds with an base64 image:
```
...tool implementation
return [{
        base64Image: await urlToBase64("https://images.unsplash.com/photo-1751225750479-43ad27b94fa0?w=900&auto=format&fit=crop&q=60&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxmZWF0dXJlZC1waG90b3MtZmVlZHwyfHx8ZW58MHx8fHx8")
      }]

      // return results
    },
    toModelOutput: (output: {
      base64Image: string;
    }[]) => {

      return {
        type: "content",
        value: output.map((result) => ({
          type: "media",
          mediaType: "image/jpeg",
          data: result.base64Image,
        })),
      }
    },
```

Claude will tell me whats in the image, gemini wont.

### AI SDK Version

- ai: 5.0.19
- @ai-sdk/google: 2.0.7
- @ai-sdk/anthropic: 2.0.5

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct



Fix (patch):
diff --git a/.changeset/wise-lamps-study.md b/.changeset/wise-lamps-study.md
new file mode 100644
index 000000000000..863fa6ff6445
--- /dev/null
+++ b/.changeset/wise-lamps-study.md
@@ -0,0 +1,5 @@
+---
+'@ai-sdk/google': patch
+---
+
+Fixed handling of image response in the tool call result.
diff --git a/examples/ai-core/src/generate-text/google-image-tool-results.ts b/examples/ai-core/src/generate-text/google-image-tool-results.ts
new file mode 100644
index 000000000000..31e14625aa46
--- /dev/null
+++ b/examples/ai-core/src/generate-text/google-image-tool-results.ts
@@ -0,0 +1,82 @@
+import { google } from '@ai-sdk/google';
+import { generateText, stepCountIs, tool } from 'ai';
+import { z } from 'zod/v4';
+import 'dotenv/config';
+import * as fs from 'fs';
+import * as path from 'path';
+
+async function fileToBase64(filePath: string): Promise<string> {
+  const fileBuffer = await fs.promises.readFile(filePath);
+  return fileBuffer.toString('base64');
+}
+
+const imageAnalysisTool = tool({
+  description: 'Give the image ',
+  inputSchema: z.object({}),
+  execute: async ({}) => {
+    try {
+      const imagePath = path.join(__dirname, '../../data/comic-cat.png');
+      const base64Image = await fileToBase64(imagePath);
+
+      return {
+        success: true,
+        description: 'Image fetched successfully',
+        base64Image,
+      };
+    } catch (error) {
+      return {
+        success: false,
+        error: `Failed to fetch image: ${error instanceof Error ? error.message : 'Unknown error'}`,
+      };
+    }
+  },
+
+  toModelOutput(output: { base64Image?: string }) {
+    return {
+      type: 'content',
+      value: [
+        {
+          type: 'media',
+          mediaType: 'image/png',
+          data: output.base64Image!,
+        },
+      ],
+    };
+  },
+});
+
+async function main() {
+  console.log(
+    '🔍 Testing Google model image analysis with tool-returned images...\n',
+  );
+
+  const result = await generateText({
+    model: google('gemini-2.5-flash'),
+    tools: {
+      analyzeImage: imageAnalysisTool,
+    },
+    stopWhen: stepCountIs(2),
+    prompt: `Whats in this image?`,
+  });
+
+  console.log('📋 Analysis Result: \n');
+  console.log('='.repeat(60));
+  console.log(`${JSON.stringify(result.text, null, 2)}\n`);
+  // console.log(JSON.stringify(result.steps, null, 2));
+
+  if (result.toolCalls && result.toolCalls.length > 0) {
+    console.log('🔧 Tool Calls Made: \n');
+    result.toolCalls.forEach((call, index) => {
+      console.log(`${index + 1}. ${call.toolName}:`);
+      console.log(`   Input: ${JSON.stringify(call.input, null, 2)}`);
+    });
+    console.log();
+  }
+
+  console.log('📊 Usage: \n');
+  console.log(`Input tokens: ${result.usage.inputTokens}`);
+  console.log(`Output tokens: ${result.usage.outputTokens}`);
+  console.log(`Total tokens: ${result.usage.totalTokens}`);
+}
+
+main().catch(console.error);
diff --git a/packages/google/src/convert-to-google-generative-ai-messages.ts b/packages/google/src/convert-to-google-generative-ai-messages.ts
index a4931796fbcf..ed7f6c962736 100644
--- a/packages/google/src/convert-to-google-generative-ai-messages.ts
+++ b/packages/google/src/convert-to-google-generative-ai-messages.ts
@@ -146,17 +146,59 @@ export function convertToGoogleGenerativeAIMessages(
       case 'tool': {
         systemMessagesAllowed = false;
 
-        contents.push({
-          role: 'user',
-          parts: content.map(part => ({
-            functionResponse: {
-              name: part.toolName,
-              response: {
+        const parts: GoogleGenerativeAIContentPart[] = [];
+
+        for (const part of content) {
+          const output = part.output;
+
+          if (output.type === 'content') {
+            for (const contentPart of output.value) {
+              switch (contentPart.type) {
+                case 'text':
+                  parts.push({
+                    functionResponse: {
+                      name: part.toolName,
+                      response: {
+                        name: part.toolName,
+                        content: contentPart.text,
+                      },
+                    },
+                  });
+                  break;
+                case 'media':
+                  parts.push(
+                    {
+                      inlineData: {
+                        mimeType: contentPart.mediaType,
+                        data: contentPart.data,
+                      },
+                    },
+                    {
+                      text: 'Tool executed successfully and returned this image as a response',
+                    },
+                  );
+                  break;
+                default:
+                  parts.push({ text: JSON.stringify(contentPart) });
+                  break;
+              }
+            }
+          } else {
+            parts.push({
+              functionResponse: {
                 name: part.toolName,
-                content: part.output.value,
+                response: {
+                  name: part.toolName,
+                  content: output.value,
+                },
               },
-            },
-          })),
+            });
+          }
+        }
+
+        contents.push({
+          role: 'user',
+          parts,
         });
         break;
       }