Documentation Index
Fetch the complete documentation index at: https://mintlify.com/vercel/ai/llms.txt
Use this file to discover all available pages before exploring further.
Transport
TheuseChat transport system provides fine-grained control over how messages are sent to your API endpoints and how responses are processed. This is particularly useful for alternative communication protocols like WebSockets, custom authentication patterns, or specialized backend integrations.
Default Transport
By default,useChat uses HTTP POST requests to send messages to /api/chat:
Custom Transport Configuration
Configure the default transport with custom options:Dynamic Configuration
You can also provide functions that return configuration values. This is useful for authentication tokens that need to be refreshed, or for configuration that depends on runtime conditions:Request Transformation
Transform requests before sending to your API:Direct Agent Transport
For scenarios where you want to communicate directly with an Agent without going through HTTP, you can useDirectChatTransport. This transport invokes the agent’s stream() method directly in-process.
This is useful for:
- Server-side rendering: Run the agent on the server without an API endpoint
- Testing: Test chat functionality without network requests
- Single-process applications: Desktop or CLI apps where client and agent run together
How It Works
UnlikeDefaultChatTransport which sends HTTP requests:
DirectChatTransportvalidates incoming UI messages- Converts them to model messages using
convertToModelMessages - Calls the agent’s
stream()method directly - Returns the result as a UI message stream via
toUIMessageStream()
Configuration Options
You can pass additional options to customize the stream output:DirectChatTransport does not support stream reconnection since there is no
persistent server-side stream. The reconnectToStream() method always returns
null.Building Custom Transports
To understand how to build your own transport, refer to the source code of the default implementation:- DefaultChatTransport - The complete default HTTP transport implementation
- HttpChatTransport - Base HTTP transport with request handling
- ChatTransport Interface - The transport interface you need to implement
- Handle the
sendMessagesmethod - Process UI message streams
- Transform requests and responses
- Handle errors and connection management