When using the useChat hook, custom request options like headers, body fields, and credentials configured directly on the hook are not being sent with the request:
// These options are not sent with the requestconst { messages, sendMessage } = useChat({ headers: { Authorization: 'Bearer token123', }, body: { user_id: '123', }, credentials: 'include',});
The useChat hook has changed its API for configuring request options. Direct options like headers, body, and credentials on the hook itself are no longer supported. Instead, you need to use the transport configuration with DefaultChatTransport or pass options at the request level.
If you need dynamic values at the hook level, you can use functions that return configuration values. However, request-level configuration is generally preferred for better reliability:
For component state that changes over time, request-level configuration
(Option 1) is recommended. If using hook-level functions, consider using
useRef to store current values and reference ref.current in your
configuration function.