> ## Documentation Index
> Fetch the complete documentation index at: https://docs.plato.ae/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Streaming

> Stream a Connect360 AI reply as server-sent events.

Use AI streaming when a website or support surface should show the AI answer as it is generated.

```text theme={null}
POST /api/v1/connect/ai-stream
```

The response uses server-sent events.

## Request

```bash theme={null}
curl "https://api.plato.ae/api/v1/connect/ai-stream" \
  -X POST \
  -H "Authorization: Bearer $PLATO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agentId": "ai_agent_id",
    "conversationId": "conversation_id",
    "lastMessageId": "message_id"
  }'
```

## Body

```ts theme={null}
{
  agentId: string;
  conversationId: string;
  channelId?: string | null;
  lastMessageId?: string | null;
  senderId?: string | null;
}
```

`senderId` is required unless Plato can read it from `lastMessageId`.

`channelId` is optional when the conversation already has a channel or the last message has a channel.

## Events

The stream sends `data:` events.

Delta event:

```json theme={null}
{
  "type": "delta",
  "delta": "Hello",
  "text": "Hello"
}
```

Done event:

```json theme={null}
{
  "type": "done",
  "messageId": "message_id",
  "text": "Hello, how can I help?"
}
```

Error event:

```json theme={null}
{
  "type": "error",
  "error": "Conversation not found."
}
```

## Browser Example

```ts theme={null}
const response = await fetch("https://api.plato.ae/api/v1/connect/ai-stream", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    agentId: "ai_agent_id",
    conversationId: "conversation_id",
    lastMessageId: "message_id",
  }),
});

const reader = response.body?.getReader();
```

For public websites, call this endpoint from your backend when possible. Do not expose long-lived API keys in browser code.

## Permission

AI streaming requires:

```text theme={null}
connect360:conversation:engage
```
