# BF Streaming API

{% hint style="info" %}
The BetterForms Streaming API allows real time streaming of responses from LLM services like OpenAI To be initiated.
{% endhint %}

### **Overview**

Creating a call to this service will create a post to the LLM and stream results back to the appropriate channel. This service is in beta release as of the time of this document.

Avail in <mark style="color:red;">**`bf-staging`**</mark> only

```json
//create endpoint
portal.myapp.com/stream/create

Method: POST
```

| Key                                                   | Type   | Description                                                                                                   |
| ----------------------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------------- |
| <mark style="color:red;">`apiKey`</mark>              | string | Unique API key for BF (find in app settings)                                                                  |
| <mark style="color:red;">`channels`</mark>            | array  | Array of BF Messaging communication channels                                                                  |
| <mark style="color:red;">`actionName`</mark>          | string | Name of the action to be performed                                                                            |
| <mark style="color:red;">`service`</mark>             | string | Name of the service to be used (OpenAI)                                                                       |
| <mark style="color:red;">`payload`</mark>             | object | Object containing parameters for the action, this contains params that are passed on to the streaming service |
| <mark style="color:red;">`payload.apiKey`</mark>      | string | Unique API key for the streaming service                                                                      |
| <mark style="color:red;">`payload.stream`</mark>      | bool   | Indicator if streaming is enabled, if disabled, result is returned directly to the POST result                |
| <mark style="color:red;">`payload.functions`</mark>   | array  | Array of functions to be executed                                                                             |
| <mark style="color:red;">`payload.max_tokens`</mark>  | number | Maximum number of tokens for the response                                                                     |
| <mark style="color:red;">`payload.seed`</mark>        | number | Seed for the random number generator                                                                          |
| <mark style="color:red;">`payload.messages`</mark>    | array  | Array of messages to be processed                                                                             |
| <mark style="color:red;">`payload.model`</mark>       | string | Model to be used for processing                                                                               |
| <mark style="color:red;">`payload.temperature`</mark> | number | Parameter controlling randomness in output                                                                    |

```json
{
  "apiKey": "BFAPI_xxxxxxxx-xxxxxx-xxxxxx,
  "channels": [
    "anonymous"
  ],
  "actionName": "assistantReceiveResultsStream",
  "service": "openAI",
  "payload": {
    "apiKey": "sk-xxxxxxx-xxxxxxxx-xxxxxxx",
    "stream": true,
    "functions": [],
    "max_tokens": 4000,
    "seed": 1,
    "messages": [
      {
        "content": "You are a Chuck Norris Joke teller.",
        "role": "system"
      },
      {
        "content": "create a joke about software developers",
        "role": "user"
      }
    ],
    "model": "gpt-4-turbo-preview",
    "temperature": 0
  }
}
```


---

# 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.klai.studio/engineering-reference-docs/bf-streaming-api.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.
