# Local and simple APIs

Render messages from your app or connect a plain-text stream.

## Choose JSON or a text stream

If your app already has message records, [render them directly](/libraries/ai#installation) from your existing store. Use [the external store example](/libraries/ai-runtime#external-store) if you also need commands that check the current conversation.

For a plain UTF-8 stream, [install the view dependencies](/libraries/ai#installation) and add the tested AI SDK packages.

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

Pass TextStreamChatTransport to the hook. Choose a structured protocol if your interface needs tools, files, or other UI data.

```tsx
import { useState } from "react";
import { Button } from "@collectivecreation/ghost-ui/components/button";
import { useChat } from "@ai-sdk/react";
import { TextStreamChatTransport } from "ai";
import { createAiSdkAdapter } from "@collectivecreation/ghost-ui/chat-adapter-ai-sdk";
import { useChatAdapter } from "@collectivecreation/ghost-ui/chat-runtime-react";
import { Message, MessageBody } from "@collectivecreation/ghost-ui/components/message";
import { MessageParts } from "@collectivecreation/ghost-ui/components/message-parts";
const adapter = createAiSdkAdapter();
export function SimpleTextApi({ endpoint, threadId, revision }: { endpoint: string; threadId: string; revision: number }) {
  const chat = useChat({ transport: new TextStreamChatTransport({ api: endpoint }) });
  const runtime = useChatAdapter(adapter, chat, { identity: { threadId, revision } });
  const [error, setError] = useState<unknown>();
  return <>
    {runtime.messages.map(message => <Message key={message.id} actor={message.actor}><MessageBody>
      <MessageParts parts={message.parts} />
    </MessageBody></Message>)}
    <Button disabled={runtime.capabilities.send.support !== "supported" || !runtime.capabilities.send.available}
      onClick={() => { setError(undefined); void Promise.resolve().then(() => runtime.controller.send({ text: "Review the brief", attachments: [] })).catch(setError); }}>Review brief</Button>
    {runtime.capabilities.stop.support === "supported" && runtime.capabilities.stop.available &&
      <Button onClick={() => { void Promise.resolve().then(() => runtime.controller.stop?.()).catch(setError); }}>Stop</Button>}
    {(error || runtime.controller.error) ? <p role="alert">The request could not complete.</p> : null}
  </>;
}

```

Connect a Composer or application input to runtime.controller.send({ text, attachments: [] }); use its guarded stop command and handle rejected commands. The SDK supplies message assembly and cancellation. Supply custom transport request options for authentication and request-body policy rather than hiding them in Ghost.

## Upgrade only when needed

Plain text has no tool or artifact schema. Move to [current UI-message SSE](/libraries/ai-runtime-streams#current), [AG-UI](/libraries/ai-runtime-ag-ui) or [full agent state](/libraries/ai-runtime-state) when those contracts solve an actual need. Do not guess a stream format from a successful response or copy a bespoke parser into the view.
