# Integrate Assistant API Streaming through websocket

**URL:** <https://community.openai.com/t/integrate-assistant-api-streaming-through-websocket/696920>\
**Category:** API\
**Tags:** python, assistants-api, assistants-streaming\
**Created:** [March 25, 2024, 5:23pm UTC](https://community.openai.com/t/integrate-assistant-api-streaming-through-websocket/696920 "2024-03-25T17:23:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![william.zebrowski](https://avatars.discourse-cdn.com/v4/letter/w/73ab20/32.png) [@william.zebrowski](https://community.openai.com/u/william.zebrowski)\
**Post date:** [March 25, 2024, 5:23pm UTC](https://community.openai.com/t/integrate-assistant-api-streaming-through-websocket/696920/1 "2024-03-25T17:23:07Z")

</div>

I understand AssistantsAPI Streaming is relatively new and as I’ve been digging, there are not many examples out there incorporating this feature with a front end chat widget but curious if anyone has had any luck with this?

For this streaming to occur real-time, I’m assuming a web socket has to be in place?

If any examples are out there for python that would be great - if you have another language, I would be happy to take it and convert it.

Thanks!

---

<div class="post-metadata">

**Author:** ![cloudUser98](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/clouduser98/32/147246_2.png) [@cloudUser98](https://community.openai.com/u/cloudUser98)\
**Post date:** [March 25, 2024, 6:13pm UTC](https://community.openai.com/t/integrate-assistant-api-streaming-through-websocket/696920/2 "2024-03-25T18:13:40Z")

</div>

You can stream the response of the create run API from your server and read the streamed data using the fetch API on the client side. No need of websockets.

---

<div class="post-metadata">

**Author:** ![william.zebrowski](https://avatars.discourse-cdn.com/v4/letter/w/73ab20/32.png) [@william.zebrowski](https://community.openai.com/u/william.zebrowski)\
**Post date:** [March 25, 2024, 6:43pm UTC](https://community.openai.com/t/integrate-assistant-api-streaming-through-websocket/696920/3 "2024-03-25T18:43:37Z")

</div>

Thanks @cloudUser98. Does this option assume that we get the response in full first and then iterate through the characters in the response to output to the user?

Or is your option streaming the response in real time?

Thanks in advance for the clarification!

---

<div class="post-metadata">

**Author:** ![cloudUser98](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/clouduser98/32/147246_2.png) [@cloudUser98](https://community.openai.com/u/cloudUser98)\
**Post date:** [March 25, 2024, 7:17pm UTC](https://community.openai.com/t/integrate-assistant-api-streaming-through-websocket/696920/4 "2024-03-25T19:17:09Z")

</div>

My answer was about streaming the API response in real time.

Let me show you an example for my approach using python, the openai python SDK and the Django framework.

```auto
    from openai import OpenAI
    client = OpenAI()

    stream = client.beta.threads.runs.create(
        thread_id="thread_123",
        assistant_id="asst_123",
        stream=True
    )

    def my_iterator():
        for event in stream:
            yield event

    return StreamingHttpResponse(my_iterator())

```

**this is only an example as you would need to add more code so you can extract the text value from each stream event.**

Then you can read the stream of data using the javascript Streams API on the client side.

---

<div class="post-metadata">

**Author:** ![icdev2dev](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/icdev2dev/32/148444_2.png) [@icdev2dev](https://community.openai.com/u/icdev2dev)\
**Post date:** [March 26, 2024, 6:32am UTC](https://community.openai.com/t/integrate-assistant-api-streaming-through-websocket/696920/5 "2024-03-26T06:32:15Z")

</div>

See my topic here…[One Shot Streaming Using Svelte with Bi Directional Web Sockets](https://community.openai.com/t/one-shot-streaming-using-svelte-with-bi-directional-web-sockets/697728)

---

<div class="post-metadata">

**Author:** ![curt.kennedy](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/curt.kennedy/32/709249_2.png) [@curt.kennedy](https://community.openai.com/u/curt.kennedy)\
**Post date:** [December 29, 2025, 4:52am UTC](https://community.openai.com/t/integrate-assistant-api-streaming-through-websocket/696920/6 "2025-12-29T04:52:36Z")

</div>


