How do I build a streaming /api/chat endpoint with opencode SDK?

dev
3a750b0Update aarch64-darwin hash
This post might have stale content, as dev is 7978 commits ahead.

say i want to create an /api/chat endpoint, towards which i can send messages and it (ideally streams) sends me responses? how do i build that with opencode SDK? imagine i'm on next.js and have an opencode SDK server already running at https://my-opencode-server.com

Avatar of julianbenegas
Julian Benegas
commented

cool. so imagine the user sends a message and sees the stream. then they refresh: what do they see? what's loaded?

Avatar of julianbenegas
Julian Benegas
commented

gotchu. and if there's a message that's currently streaming? i'd do this?

.messages()
.subscribe()

? like a "re-connect while a stream is ongoing" kind of scenario

Avatar of julianbenegas
Julian Benegas
commented

what about the storage part? if i want to have more metadata associated with, say, a session. is that recommended? would i need to eject to storing stuff in my database?


END OF POST

How do I build a streaming /api/chat endpoint with opencode SDK? — anomalyco/opencode