1. Install Streamstraight packages
Add Streamstraight’s server SDK to the workspace that hosts your Next.js route handlers..env entry for the API key you generate in the Streamstraight dashboard. In production, make sure to add this API key to your server secrets.
2. Modify your Next.js server route handler
Modify your server route to kick off your LLM generation and pipe its stream into Streamstraight. This should be whichever route receives and handles the user’s prompt.3. Expose a token-minting route
Clients connect to Streamstraight with a short-lived JWT. Use your API key to mint those tokens in a protected route handler.4. Connect to the stream from your client
In your chat UI, you’ll need to ensure a few things happen:- Your client fetches a Streamstraight client JWT
- Your client has a unique
streamIdormessageIdthat is the same as what’s on the server - Your client connects to the Streamstraight and handles the resulting chunks
