HTTP Transport
The HTTP transport uses standard HTTP requests with Server-Sent Events (SSE) for streaming. This is the simplest and most compatible transport option.
When to Use HTTP Transport
| Use Case | Recommendation |
|---|---|
| Next.js, Remix, or similar frameworks | ✅ Use HTTP |
| Standard web apps without special requirements | ✅ Use HTTP |
| Serverless deployments (Vercel, etc.) | ✅ Use HTTP |
| Need custom real-time events | Consider Socket Transport |
Basic Setup
Client
tsx
Server (Next.js API Route)
typescript
Session Creation
Sessions should be created server-side before rendering the chat. There are two patterns:
Pattern 1: Create Session on Page Load
tsx
Pattern 2: Server-Side Session Creation (App Router)
tsx
This pattern is cleaner as the session is ready before the component renders.
Error Handling
Handle errors in both the transport and the hook:
tsx
Stop Streaming
Allow users to cancel ongoing streams:
tsx
Express Server
For non-Next.js backends:
typescript
Transport Options
typescript
Protocol
Request Format
The triggerRequest function should send a POST request with:
json
Response Format
The server responds with an SSE stream:
text
See Streaming Events for the full list of event types.
Next Steps
- Quick Start — Complete Next.js integration guide
- Messages — Working with message state
- Streaming — Building streaming UIs