# Chain of thought
Your users see the agent's reasoning as it streams, side by side with the response. AI Transport multiplexes reasoning and text streams within the same turn.
Chain of thought streams reasoning content alongside the main response text. The codec supports multiple stream types within a single turn. Text and reasoning are delivered as separate streams that render independently in the UI.
## How it works
When an LLM produces reasoning or thinking tokens, the codec multiplexes them alongside text tokens on the same Ably channel. Each stream type is tagged so the client routes reasoning content to one part of the UI and response text to another.
With the Vercel AI SDK integration, reasoning arrives as a separate `reasoning` stream type within the UI message stream:
### Javascript
```
app.post('/api/chat', async (req, res) => {
const { turnId, clientId, messages } = req.body;
const turn = transport.newTurn({ turnId, clientId });
const result = streamText({
model: anthropic('claude-sonnet-4-20250514'),
messages,
abortSignal: turn.abortSignal,
});
await turn.streamResponse(result.toUIMessageStream());
await turn.end('complete');
res.json({ ok: true });
});
```
No additional server configuration is needed. If the model produces reasoning tokens, the codec encodes them as a distinct stream within the turn.
## Display reasoning in the UI
On the client, message nodes contain both text and reasoning content. Render them separately to show the agent's thinking process:
### Javascript
```
const { nodes } = useView({ transport });
for (const node of nodes) {
for (const part of node.message.parts) {
if (part.type === 'reasoning') {
renderThinkingPanel(part.reasoning);
} else if (part.type === 'text') {
renderResponsePanel(part.text);
}
}
}
```
Both streams update in real time. Users see the reasoning appear as the model thinks, followed by (or alongside) the response text.
## Edge cases and unhappy paths
- A model that produces reasoning but the codec does not surface it folds reasoning into the text stream. Update the codec or the framework integration if you need it separated.
- Reasoning tokens are often longer than the final response. They count toward the channel's message rate and storage like any other tokens. See [token streaming](https://ably.com/docs/ai-transport/features/token-streaming.md?source=llms.txt#rollup) for rollup tuning.
- A cancelled turn aborts both streams. Partial reasoning content stays with status `aborted`.
- Two reasoning streams in the same turn are exposed in the same order they were emitted by the model. Multiple distinct reasoning episodes are common with tool-augmented agents.
- A client that does not render reasoning parts still receives them on the channel. Filter at the render layer if you want to hide them by default.
## FAQ
### Which models support chain of thought?
Anthropic's thinking-enabled models and OpenAI's o-series surface reasoning tokens. Other models do not. Check the model provider documentation.
### Can I hide reasoning from the user?
Yes. Reasoning is a separate part type. Filter it out at the render layer. The content is still on the channel for any client that wants it.
### Does cancelling cut off reasoning too?
Yes. Both the reasoning and text streams share the turn's abort signal.
### Are reasoning tokens charged the same as text?
Yes. The channel does not distinguish between part types for billing. The cost depends on the published message count after rollup.
### How do I render reasoning differently after the turn finishes?
The `node.message.parts` array stays available after the turn ends. Hide or collapse reasoning when the streaming flag flips to false.
## Related features
- [Token streaming](https://ably.com/docs/ai-transport/features/token-streaming.md?source=llms.txt): how text tokens are streamed and accumulated.
- [Tool calling](https://ably.com/docs/ai-transport/features/tool-calling.md?source=llms.txt): another multi-part stream type within a turn.
- [Codec API](https://ably.com/docs/ai-transport/api/javascript/codec.md?source=llms.txt): reference for the codec that multiplexes reasoning and text streams.
## Related Topics
- [Token streaming](https://ably.com/docs/ai-transport/features/token-streaming.md?source=llms.txt): Stream AI-generated tokens to clients in realtime using AI Transport, with support for message-per-response and message-per-token patterns.
- [Cancellation](https://ably.com/docs/ai-transport/features/cancellation.md?source=llms.txt): Cancel AI responses mid-stream with Ably AI Transport. Scoped cancel signals, server-side authorization, and graceful abort handling.
- [Reconnection and recovery](https://ably.com/docs/ai-transport/features/reconnection-and-recovery.md?source=llms.txt): AI Transport streams survive connection drops automatically. Clients reconnect and resume from where they left off with no lost tokens.
- [Multi-device sessions](https://ably.com/docs/ai-transport/features/multi-device.md?source=llms.txt): Share AI conversations across tabs, phones, and laptops with Ably AI Transport. All devices see the same session in real time.
- [History and replay](https://ably.com/docs/ai-transport/features/history.md?source=llms.txt): Load conversation history from Ably channels with AI Transport. Paginated history, gapless continuity, and scroll-back patterns.
- [Conversation branching](https://ably.com/docs/ai-transport/features/branching.md?source=llms.txt): Edit user messages, regenerate AI responses, and navigate branches with Ably AI Transport. The full history is preserved as a tree.
- [Interruption](https://ably.com/docs/ai-transport/features/interruption.md?source=llms.txt): Let users interrupt AI agents mid-stream with Ably AI Transport. Cancel-then-send and send-alongside patterns for responsive AI interactions.
- [Concurrent turns](https://ably.com/docs/ai-transport/features/concurrent-turns.md?source=llms.txt): Run multiple AI turns simultaneously with Ably AI Transport. Independent streams, scoped cancellation, and multi-agent support.
- [Tool calling](https://ably.com/docs/ai-transport/features/tool-calling.md?source=llms.txt): Stream tool invocations and results through Ably AI Transport. Server-executed and client-executed tools with persistent state.
- [Human-in-the-loop](https://ably.com/docs/ai-transport/features/human-in-the-loop.md?source=llms.txt): Add human approval gates to AI agent workflows with Ably AI Transport. Approve tool executions and provide input across devices.
- [Optimistic updates](https://ably.com/docs/ai-transport/features/optimistic-updates.md?source=llms.txt): User messages appear instantly in Ably AI Transport. Optimistic insertion with automatic reconciliation when the server confirms.
- [Agent presence](https://ably.com/docs/ai-transport/features/agent-presence.md?source=llms.txt): Show agent status in your AI application with Ably Presence. Display streaming, thinking, idle, and offline states in real time.
- [Push notifications](https://ably.com/docs/ai-transport/features/push-notifications.md?source=llms.txt): Notify users when AI agents complete background tasks with Ably Push Notifications. Reach users even when they're offline.
- [Double texting](https://ably.com/docs/ai-transport/features/double-texting.md?source=llms.txt): Handle users sending multiple messages while the AI is streaming with Ably AI Transport. Queue or run messages concurrently.
## Documentation Index
To discover additional Ably documentation:
1. Fetch [llms.txt](https://ably.com/llms.txt?source=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.