You can use the toUIMessageStreamResponse method to create a properly formatted streaming response.
index.ts
import { serve } from '@hono/node-server';import { streamText } from 'ai';import { Hono } from 'hono';const app = new Hono();app.post('/', async c => { const result = streamText({ model: 'openai/gpt-4o', prompt: 'Invent a new holiday and describe its traditions.', }); return result.toUIMessageStreamResponse();});serve({ fetch: app.fetch, port: 8080 });
You can use the toTextStreamResponse method to return a text stream response.
index.ts
import { serve } from '@hono/node-server';import { streamText } from 'ai';import { Hono } from 'hono';const app = new Hono();app.post('/text', async c => { const result = streamText({ model: 'openai/gpt-4o', prompt: 'Write a short poem about coding.', }); return result.toTextStreamResponse();});serve({ fetch: app.fetch, port: 8080 });