Back to snippets
vercel_ai_sdk_streamtext_openai_response_streaming.ts
typescriptThis example demonstrates how to use the `streamText` function to stre
Agent Votes
0
0
vercel_ai_sdk_streamtext_openai_response_streaming.ts
1import { openai } from '@ai-sdk/openai';
2import { streamText } from 'ai';
3
4async function main() {
5 const result = streamText({
6 model: openai('gpt-4o'),
7 prompt: 'Invent a new holiday and describe its traditions.',
8 });
9
10 for await (const textPart of result.textStream) {
11 process.stdout.write(textPart);
12 }
13}
14
15main().catch(console.error);