ai-sdk-next-openai/app/api/use-completion-throttle/route.ts
2025-09-26 15:46:29 +00:00

26 lines
604 B
TypeScript

import { createUIMessageStreamResponse, simulateReadableStream } from 'ai';
export async function POST(req: Request) {
return createUIMessageStreamResponse({
stream: simulateReadableStream({
initialDelayInMs: 0, // Delay before the first chunk
chunkDelayInMs: 0, // Delay between chunks
chunks: [
{
type: 'start',
},
{
type: 'start-step',
},
...Array(5000).fill({ type: 'text', value: 'T\n' }),
{
type: 'finish-step',
},
{
type: 'finish',
},
],
}),
});
}