# useChatTransport
`useChatTransport` reads a [`ChatTransport`](https://ably.com/docs/ai-transport/api/javascript/vercel/chat-transport.md#chat-transport) and its underlying [`ClientSession`](https://ably.com/docs/ai-transport/api/javascript/core/client-session.md) from the nearest `ChatTransportProvider`. Pass the returned `chatTransport` to Vercel AI SDK's `useChat({ transport })` and use `session` for everything else (cancel, tree inspection, raw message access).
The hook is a thin context reader; it does not create or manage any session or transport state. When no provider is found or the session failed to construct, the hook returns stubs along with populated `sessionError` and `chatTransportError` so the component can render an error state without an error boundary.
#### Javascript
```
import { useChat } from '@ai-sdk/react';
import { useChatTransport } from '@ably/ai-transport/vercel/react';
function Chat() {
const { chatTransport, chatTransportError } = useChatTransport();
const { messages, sendMessage } = useChat({ transport: chatTransport });
if (chatTransportError) return
This hook must be used within a `ChatTransportProvider` (exported from `@ably/ai-transport/vercel/react`). The provider wraps the subtree in a `ClientSessionProvider` baked to the Vercel types, so [`useClientSession`](https://ably.com/docs/ai-transport/api/react/core/use-client-session.md) and the other core hooks work inside the same subtree.
## Parameters
### Javascript
```
import { useChat } from '@ai-sdk/react';
import { useChatTransport, useMessageSync } from '@ably/ai-transport/vercel/react';
function Chat() {
const { session, chatTransport, chatTransportError } = useChatTransport();
const { messages, setMessages, sendMessage, status } = useChat({
transport: chatTransport,
});
useMessageSync({ setMessages });
if (chatTransportError) return ;
return (
<>
{messages.map((m) => )}
sendMessage({ role: 'user', parts: [{ type: 'text', text }] })}
/>
{status === 'streaming' && (
)}
>
);
}
```
## Related Topics
- [ChatTransportProvider](https://ably.com/docs/ai-transport/api/react/vercel/chat-transport-provider.md): API reference for ChatTransportProvider: the Vercel React entry point that wraps a ClientSession in a ChatTransport bound to UIMessageCodec.
- [useMessageSync](https://ably.com/docs/ai-transport/api/react/vercel/use-message-sync.md): Wire AI Transport view updates into Vercel useChat's setMessages from React.
## Documentation Index
To discover additional Ably documentation:
1. Fetch [llms.txt](https://ably.com/llms.txt) for the canonical list of available pages.
2. Identify relevant URLs from that index.
3. Fetch target pages as needed.
Avoid using assumed or outdated documentation paths.