# Stop a streaming message

`POST /chat.stopStream`

## Description

Finalize an open stream (see [`/chat.startStream`](/docs/api/chat-start-stream))
into a single persisted chat message and return its timestamp. Optionally
include trailing `text` to append before finalizing.

If the app never calls `stopStream` but has already streamed some text, the
server finalizes the buffered text into a message automatically.

**Required scope:** `chat:send_message` or `chat:write`

---

**OpenAPI Spec:** [chat-v1.json](https://developer.ro.am/chat-v1.json)

## Authentication

```
Authorization: Bearer YOUR_API_KEY
```

## Request Body

| Property | Type | Required | Description |
|----------|------|----------|-------------|
| `streamId` | string | Yes | The stream ID returned by chat.startStream. |
| `text` | string | No | Optional trailing text appended before the message is finalized. |

### Example Request

```json
{
  "streamId": "018f5c8e-7d2a-7c4e-8f9a-1a2b3c4d5e6f",
  "text": " Hope that helps!"
}
```

## Responses

### 200 - Stream finalized and message persisted.

| Property | Type | Required | Description |
|----------|------|----------|-------------|
| `streamId` | string | No |  |
| `chatId` | string | No | ID of the chat where the message was posted. |
| `timestamp` | integer | No | Timestamp of the finalized message (microseconds since epoch). |
| `threadTimestamp` | integer | No | Thread timestamp if the stream was a thread reply. |


#### Example Response

```json
{
  "streamId": "018f5c8e-7d2a-7c4e-8f9a-1a2b3c4d5e6f",
  "chatId": "757dfe66-37b4-4772-baa5-8c86ec68c176",
  "timestamp": 1765602474760032
}
```

### 400 - Bad request. Common causes:
- `streamId` missing or not a valid UUID
- The finalized message would have no content


### 401 - Presented invalid authentication credentials.

### 403 - The token lacks the required scope (`chat:send_message` or `chat:write`).

### 404 - No active stream with that `streamId` for this app.

### 405 - An unsupported method was requested.

### 413 - Accumulated stream text exceeds the maximum allowed size.

### 500 - An internal error occurred.

---

*Machine-readable API documentation.*
*Full documentation: https://developer.ro.am/docs/api/chat-stop-stream*
