# Vercel AI SDK

Connect the Vercel AI SDK’s `useChat` hook to Ghost UI.

## Connect the AI SDK

[Install Ghost UI and its view dependencies](/libraries/ai#installation), then add the versions used in this example.

```bash
npm install ai@7.0.138 @ai-sdk/react@4.0.141
```

Pass a ChatTransport<UIMessage> to the component. new DefaultChatTransport({ api: "/api/chat" }) expects a current UI-message stream. For a plain-text or legacy endpoint, see [Data streams](/libraries/ai-runtime-streams).

```tsx
import { useChat } from "@ai-sdk/react";
import type { ChatTransport, UIMessage } from "ai";
import { createAiSdkAdapter } from "@collectivecreation/ghost-ui/chat-adapter-ai-sdk";
import { useChatAdapter } from "@collectivecreation/ghost-ui/chat-runtime-react";
import { Button } from "@collectivecreation/ghost-ui/components/button";
import { Message, MessageBody } from "@collectivecreation/ghost-ui/components/message";
import { MessageParts } from "@collectivecreation/ghost-ui/components/message-parts";
const adapter = createAiSdkAdapter();
export function AiSdkConversation({ transport }: { transport: ChatTransport<UIMessage> }) {
  const chat = useChat({ transport });
  const runtime = useChatAdapter(adapter, chat, { identity: { threadId: "brief", revision: 0 } });
  const { messages, controller } = runtime;
  return <section aria-label="Conversation">
    {messages.map(message => <Message key={message.id} actor={message.actor} aria-label={message.actor}><MessageBody>
      <MessageParts parts={message.parts} />
    </MessageBody></Message>)}
    <Button type="button" disabled={runtime.capabilities.send.support !== "supported" || !runtime.capabilities.send.available}
      onClick={() => void controller.send({ text: "Summarize the brief", attachments: [] })}>Summarize</Button>
    {controller.status === "streaming" && <Button type="button" onClick={() => void controller.stop?.()}>Stop</Button>}
    {controller.error && <p role="alert">Could not complete the request.</p>}
  </section>;
}

```

## Commands and extension points

Keep messages and transport in useChat. The adapter connects send, stop, and regeneration for a specific message. Editing uses sendMessage({ text, messageId }) on the existing user message. Handle storage and failed resends in your app.

An AI SDK tool output with preliminary: true projects as running, even when a payload is already present. Only a known final output becomes output-ready; error/cancellation wins over retained partial content. Classified summaries preserve native IDs when available; anonymous fallback assumes append order. Reasoning is dropped unless your explicit classifier identifies a provider/application summary.

Supply the adapter's normalization options for deliberate part mappings and reasoning summaries. Supply runtime availability to disable actions for application policy. Attachments need the explicit outbound converter described in [runtime integration](/libraries/ai-runtime#attachments); unsupported files are rejected rather than dropped.

## Troubleshooting and native APIs

A missing answer usually indicates a protocol/transport mismatch. Inspect native errors first, then capability support/availability. Keep one hook owner per context and advance the [identity revision](/libraries/ai-threads) on replacement. Retain the native hook for capabilities whose semantics are richer than a generic message command.

[AI SDK UI documentation](https://ai-sdk.dev/docs/ai-sdk-ui/overview) covers transports, resume, approval responses and typed UI data. Use [data streams](/libraries/ai-runtime-streams) to distinguish current SSE from legacy v4.
