# Streaming Messages

Streaming messages enables users to receive the model's responses in chunks, rather than waiting for the compete response to be generated. This is done by incrementally transmitting chunks of content to the user. This feature enables users to:

* **Instant Responses:** Content appears progressively without waiting for the full output.
* **Enhanced User Experience:** Minimizes waiting time and offers immediate feedback.
* **Lower Latency:** Information is delivered as it’s created, reducing perceived delay.
* **Dynamic Handling:** Allows real-time processing and display while data is being received.

#### Parameter Settings

To enable streaming, set `stream=True`.

#### Code <a href="#core-parameter-description" id="core-parameter-description"></a>

{% tabs %}
{% tab title="curl" %}

```bash
curl https://api.arcee.ai/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "MODEL_NAME",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "What is the difference between SLMs and LLMs?"
      }
    ],
    "stream":true
  }'
```

{% endtab %}

{% tab title="Python" %}

```python
from openai import OpenAI 
client = OpenAI(
    api_key="YOUR_API_KEY", # Your Arcee API Platform API Key
    base_url="https://api.arcee.ai/api/v1/")

response = client.chat.completions.create(
    model="MODEL_NAME", 
    messages=[ 
        {"role":"system", "content":"You are a helpful assistant"},
        {"role":"user", "content": "What is the difference between SLMs and LLMs?"},
    ],
    stream=True
)

for chunk in response:
    if chunk and hasattr(chunk, 'choices') and chunk.choices:
        delta = chunk.choices[0].delta
        if hasattr(delta, 'content') and delta.content is not None:
            print(delta.content, end="", flush=True)
```

{% endtab %}
{% endtabs %}

#### Response Example

```
data: {"choices": [{"delta": {"content": "Hello"}}]}
data: {"choices": [{"delta": {"content": "!"}}]}
data: {"choices": [{"delta": {"content": " How"}}]}
...
data: {"choices": [{"delta": {"content": " today"}}]}
data: {"choices": [{"delta": {"content": "?"}}]}
data: [DONE]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.arcee.ai/capabilities/streaming-messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
