> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.privategpt.dev/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.privategpt.dev/_mcp/server.

# Observe Async Chat Stream Events

GET /v1/messages/async/{message_id}/stream

Observe an asynchronous chat stream via Server-Sent Events.

This endpoint provides a Server-Sent Events stream that delivers
chat completion events in real-time. The events follow
the same format as synchronous chat streaming responses.

Stream Lifecycle:

1. Stream initiated via POST /v1/messages/async
2. Events begin flowing when processing starts
3. Stream automatically closes when message completes
4. Stream can be cancelled via POST /v1/messages/async/\{message\_id}/cancel

Notes:

* Stream remains active until message completion or cancellation
* Events are delivered in chronological order
* Connection will automatically close when stream ends
* Use appropriate SSE client libraries for robust event handling

Reference: https://docs.privategpt.dev/api-reference/async-messages/observe-stream-v-1-messages-async-message-id-stream-get

## Request

### Path parameters

- `message_id` (string, required) — Message ID of the asynchronous chat stream to observe.

## Response

### 200

Server-sent events stream with chat completion data

- `any`

## Errors

### 401 Unauthorized Error

Unauthorized

- `any`

### 404 Not Found Error

Stream not found

- `detail` (OpenApiValidationErrorResponseDetail, required) — Error detail — a string message or a list of validation error objects.

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional) — detail field.

## Types

### OpenApiValidationErrorResponseDetail

Error detail — a string message or a list of validation error objects.

### ValidationError

ValidationError schema.

- `loc` (list of ValidationErrorLocItems, required) — loc field.
- `msg` (string, required) — msg field.
- `type` (string, required) — type field.
- `input` (any, optional) — input field.
- `ctx` (ValidationErrorCtx, optional) — ctx field.

### ValidationErrorLocItems

### ValidationErrorCtx

ctx field.

## Examples

**SDK Code**

```python
import requests

url = "https://api.example.com/v1/messages/async/message_id/stream"

response = requests.get(url)

print(response.json())
```

```javascript
const url = 'https://api.example.com/v1/messages/async/message_id/stream';
const options = {method: 'GET'};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/messages/async/message_id/stream"

	req, _ := http.NewRequest("GET", url, nil)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/messages/async/message_id/stream")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.get("https://api.example.com/v1/messages/async/message_id/stream")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://api.example.com/v1/messages/async/message_id/stream');

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.example.com/v1/messages/async/message_id/stream");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/messages/async/message_id/stream")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```