File: stream-object-with-image-prompt.md | Updated: 11/15/2025
Menu
Google Gemini Image Generation
Get started with Claude 3.7 Sonnet
Get started with OpenAI o3-mini
Generate Text with Chat Prompt
Generate Image with Chat Prompt
streamText Multi-Step Cookbook
Markdown Chatbot with Memoization
Generate Object with File Prompt through Form Submission
Model Context Protocol (MCP) Tools
Share useChat State Across Components
Human-in-the-Loop Agent with Next.js
Render Visual Interface in Chat
Generate Text with Chat Prompt
Generate Text with Image Prompt
Generate Object with a Reasoning Model
Stream Object with Image Prompt
Record Token Usage After Streaming Object
Record Final Object after Streaming Object
Model Context Protocol (MCP) Tools
Retrieval Augmented Generation
Copy markdown
Stream Object with Image Prompt
====================================================================================================================================
Some language models that support vision capabilities accept images as part of the prompt. Here are some of the different formats you can use to include images as input.
import { streamObject } from 'ai';import { openai } from '@ai-sdk/openai';import dotenv from 'dotenv';import { z } from 'zod';
dotenv.config();
async function main() { const { partialObjectStream } = streamObject({ model: openai('gpt-4.1'), maxOutputTokens: 512, schema: z.object({ stamps: z.array( z.object({ country: z.string(), date: z.string(), }), ), }), messages: [ { role: 'user', content: [ { type: 'text', text: 'list all the stamps in these passport pages?', }, { type: 'image', image: new URL( 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/WW2_Spanish_official_passport.jpg/1498px-WW2_Spanish_official_passport.jpg', ), }, ], }, ], });
for await (const partialObject of partialObjectStream) { console.clear(); console.log(partialObject); }}
main();
import { streamObject } from 'ai';import { openai } from '@ai-sdk/openai';import dotenv from 'dotenv';import { z } from 'zod';import fs from 'fs';
dotenv.config();
async function main() { const { partialObjectStream } = streamObject({ model: openai('gpt-4.1'), maxOutputTokens: 512, schema: z.object({ stamps: z.array( z.object({ country: z.string(), date: z.string(), }), ), }), messages: [ { role: 'user', content: [ { type: 'text', text: 'list all the stamps in these passport pages?', }, { type: 'image', image: fs.readFileSync('./data/passport.png', { encoding: 'base64', }), }, ], }, ], });
for await (const partialObject of partialObjectStream) { console.clear(); console.log(partialObject); }}
main();
On this page
Stream Object with Image Prompt
Deploy and Scale AI Apps with Vercel.
Vercel delivers the infrastructure and developer experience you need to ship reliable AI-powered applications at scale.
Trusted by industry leaders: