> ## 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

> قم ببث رد Connect360 AI كأحداث مرسلة من الخادم.

استخدم البث المباشر AI عندما يجب أن يعرض موقع الويب أو سطح الدعم إجابة AI عند إنشائها.

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

تستخدم الاستجابة الأحداث المرسلة من الخادم.

## طلب

```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"
  }'
```

## جسم

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

`senderId` مطلوب ما لم يتمكن Plato من قراءته من `lastMessageId`.

يعد `channelId` اختياريًا عندما تحتوي المحادثة على قناة بالفعل أو عندما تحتوي الرسالة الأخيرة على قناة.

## الأحداث

يرسل الدفق أحداث `data:`.

حدث دلتا:

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

تم الحدث:

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

حدث الخطأ:

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

## مثال المتصفح

```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();
```

بالنسبة لمواقع الويب العامة، اتصل بنقطة النهاية هذه من الواجهة الخلفية لديك عندما يكون ذلك ممكنًا. لا تكشف عن مفاتيح API طويلة الأمد في رمز المتصفح.

## إذن

يتطلب بث AI ما يلي:

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