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

# Chat (Streaming)

> Receive an assistant reply as it is written

## Overview

Takes the same body as [Chat](https://docs.personal.ai/composer_apis/endpoint/agent-chat.md), but streams the reply back as [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) while the assistant writes it. Member keys can use it.

## Authorization

**x-api-key** `string` *required*

Your Composer API key

## Body

**agent\_slug** `string` *required*

The assistant to talk to.

**conversation\_id** `string` *required*

The conversation, from [Create Conversation](https://docs.personal.ai/composer_apis/endpoint/conversation-create.md).

**message** `string` *required*

Your message.

**timezone** `string`

Your IANA time zone, for example `America/New_York`.

**channel** `string`

The surface the message comes from, such as `sms`. Omit for a web chat.

**attachments** `array`

Files attached to this message: `[{ filename, excerpt }]`. An attachment can also carry `image` (the `object_uri` of an [uploaded](https://docs.personal.ai/composer_apis/file-upload.md) image) and `mime`.

```json Example Request theme={null}
{
  "agent_slug": "my-assistant",
  "conversation_id": "9a2b7c1e-4d3f-4e8a-b6c5-1f0e2d3c4b5a",
  "message": "Draw a chart of my sessions for the last six weeks",
  "timezone": "America/New_York"
}
```

***

## Events

The response is `text/event-stream`. Each event has a name and data:

| Event | Data | When |
| - | - | - |
| `run` | `{ "run_id" }` | Always first. Keep `run_id` to [stop the reply](https://docs.personal.ai/composer_apis/endpoint/run-cancel.md). |
| `goal` | `{ "goal", "conversation_id" }` | The message opened or continued something the assistant is arranging with you. Send follow-ups to this `conversation_id`. |
| `activity` | `{ "label", "iteration", "tool" }` | The assistant is using a tool, such as searching the web |
| `token` | Plain text, not JSON | The next piece of the reply |
| `connect` | JSON | The assistant needs you to connect an account first |
| `done` | JSON, see below | The reply is complete |
| `error` | Plain text | Something went wrong |

The stream also sends keep-alive comments. Ignore them.

### The `done` event

**response** `string`

The full reply.

**run\_id** `string`

The id of this turn.

**conversation\_id** `string`

The conversation the turn landed in. Use this for follow-ups.

**graphics** `array`

Pictures or charts drawn in this reply.

**places** `array`

Places found on the map in this reply.

**stopped** `boolean`

True when the reply was [stopped](https://docs.personal.ai/composer_apis/endpoint/run-cancel.md) before it finished.

**turn\_ttft\_ms** `number`

Time to the first token of the reply, in milliseconds.

```text Example Stream theme={null}
event: run
data: {"run_id":"3f8e2a1b-7c6d-4e5f-9a8b-0c1d2e3f4a5b"}

event: activity
data: {"label":"Drawing","iteration":1,"tool":"make_graphic"}

event: token
data: Here it is.

event: done
data: {"response":"Here it is.","run_id":"3f8e2a1b-7c6d-4e5f-9a8b-0c1d2e3f4a5b","conversation_id":"9a2b7c1e-4d3f-4e8a-b6c5-1f0e2d3c4b5a","graphics":[{"title":"Weekly sessions, last six weeks"}],"places":[],"stopped":false}
```

***

## Example cURL

```bash cURL theme={null}
curl --no-buffer --request POST 'https://composer.personal.ai/lab/api/v1/agent.chat/stream' \
--header 'Content-Type: application/json' \
--header 'x-api-key: <your-api-key>' \
--data '{"agent_slug": "my-assistant", "conversation_id": "9a2b7c1e-4d3f-4e8a-b6c5-1f0e2d3c4b5a", "message": "Draw a chart of my sessions for the last six weeks"}'
```

***

## Error Codes

| Code | Description |
| - | - |
| 400 | `conversation_id` isn't a valid id |
| 401 | Missing or invalid API key |
| 403 | This key can't post in this conversation |
| 404 | No assistant or conversation with that id |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.