# useClientSession
`useClientSession` reads a `ClientSession` from the nearest [`ClientSessionProvider`](https://ably.com/docs/ai-transport/api/react/core/providers.md#client-session-provider). It is a thin context reader that never throws during render. If no matching provider exists or the session failed to construct, the hook returns a stub session and a populated `sessionError` so the component can render an error state without an error boundary.
#### Javascript
```
import { useClientSession } from '@ably/ai-transport/react';
function Chat() {
const { session, sessionError } = useClientSession();
if (sessionError) return
This hook must be used within a [`ClientSessionProvider`](https://ably.com/docs/ai-transport/api/react/core/providers.md#client-session-provider). When the provider is absent the hook still returns a handle, but `session` is a stub that throws on every access and `sessionError` is set.
## Parameters
### Javascript
```
import { useState } from 'react';
import { useClientSession } from '@ably/ai-transport/react';
function Chat() {
const [runtimeError, setRuntimeError] = useState();
const { session, sessionError } = useClientSession({
channelName: 'ai:demo',
onError: setRuntimeError,
});
if (sessionError) return ;
if (runtimeError) return ;
return ;
}
```
## Related Topics
- [Providers](https://ably.com/docs/ai-transport/api/react/core/providers.md): API reference for the AI Transport React providers: ClientSessionProvider and the createSessionHooks factory.
- [useView](https://ably.com/docs/ai-transport/api/react/core/use-view.md): Subscribe to a paginated, branch-aware view of the AI Transport conversation tree from React.
- [useCreateView](https://ably.com/docs/ai-transport/api/react/core/use-create-view.md): Create an independent View over the AI Transport conversation tree from React, with its own branch selections and pagination.
- [useTree](https://ably.com/docs/ai-transport/api/react/core/use-tree.md): Stable structural query callbacks for the AI Transport conversation tree from React.
- [useAblyMessages](https://ably.com/docs/ai-transport/api/react/core/use-ably-messages.md): Subscribe to raw Ably InboundMessages on the AI Transport channel 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.