How to Implement SSE in Next.js
Answered
Semipalmated Plover posted this in #help-forum
Semipalmated PloverOP
How to Implement SSE in Next.js
Answered by tafutada777
@Semipalmated Plover here is my code sample
https://github.com/tfutada/zenn-vercel-ai-sdk/blob/main/app/api-server-sent-event/route.ts
https://github.com/tfutada/zenn-vercel-ai-sdk/blob/main/app/api-server-sent-event/route.ts
5 Replies
@Semipalmated Plover here is my code sample
https://github.com/tfutada/zenn-vercel-ai-sdk/blob/main/app/api-server-sent-event/route.ts
https://github.com/tfutada/zenn-vercel-ai-sdk/blob/main/app/api-server-sent-event/route.ts
Answer
but keep in mind that it won't work in serverless platforms such as Vercel, Cloudflare and so on. it needs to be hosted on long lasting instances such as AWS, GCP and so on.
As SSE is supposed to run for long time as OpenAI API does.
Or,
you are going to impl a ChatGPT like app, use Next.js as a proxy to OpenAI, just use Vercel AI SDK, which converts SSE to streaming nicely. sample codes are aloso available in that repo above.