> ## Documentation Index
> Fetch the complete documentation index at: https://cerebrium-fix-make-entrypoint-docs-explicit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Streaming Endpoints

Streaming allows users to stream live output from their models using a server-sent event (SSE) stream.
This works for Python objects that use the iterator or generator protocol.

Currently, your generator/iterator is required to `yield` data, as it will be sent downstream via the `text/event-stream` Content-Type.
You may still send data in JSON format and then can decode it appropriately.

Let's see how we can implement a simple example below:

```python theme={null}
import time

def run(upper_range: int):
    for i in range(upper_range):
        yield f"Number {i} "
        time.sleep(1)
```

Once you deploy this code snippet and hit the stream endpoint, you will see the SSE events progressively appear every second.

You can do this as follows:

```bash theme={null}
curl -X POST https://api.aws.us-east-1.cerebrium.ai/v4/<YOUR-PROJECT-ID>/2-streaming-endpoint/run \
       -H 'Content-Type: application/json'\
       -H 'Accept: text/event-stream\
       -H 'Authorization: Bearer <YOUR-JWT-TOKEN>\
       --data '{"upper_range": 3}'
```

This should output:

```bash theme={null}
HTTP/1.1 200 OK
cache-control: no-cache
content-encoding: gzip
content-type: text/event-stream; charset=utf-8
date: Tue, 28 May 2024 21:12:46 GMT
server: envoy
transfer-encoding: chunked
vary: Accept-Encoding
x-envoy-upstream-service-time: 198995
x-request-id: e6b55132-32af-96d7-a064-8915c4a42452

data: Number 0
...
```

Progressively, you will see the rest of the data stream every second:

```
...
data: Number 1

data: Number 2
```

The latest Postman also has great functionality to show this.

<img src="https://mintcdn.com/cerebrium-fix-make-entrypoint-docs-explicit/A-kg3S1foq80GdZZ/images/cortex/streaming-postman.png?fit=max&auto=format&n=A-kg3S1foq80GdZZ&q=85&s=d516b1d83fabbbbd93fa46dc263339a1" alt="Streaming" width="2600" height="1668" data-path="images/cortex/streaming-postman.png" />

If you want to see an example of implementing this with Falcon-7B, please check out the example [here](https://github.com/CerebriumAI/examples/tree/master/5-large-language-models/2-streaming-endpoint).
