API

Learn how to use the Flowise Prediction, Vector Upsert and Message API


1. Prediction API

  • POST /api/v1/prediction/{your-chatflowid}

Request Body

KeyDescriptionTypeRequired

question

User's question

string

Yes

overrideConfig

Override existing flow configuration

object

No

history

Prepend history messages at the start of conversation

array

No

You can use the chatflow as API and connect to frontend applications.

Override Config

You also have the flexibility to override input configuration with overrideConfig property.

import requests
API_URL = "http://localhost:3000/api/v1/prediction/<chatlfowid>"

def query(payload):
    response = requests.post(API_URL, json=payload)
    return response.json()
    
output = query({
    "question": "Hey, how are you?",
    "overrideConfig": {
        "sessionId": "123",
        "returnSourceDocuments": true
    }
})

History

You can prepend history messages to give some context to LLM. For example, if you want the LLM to remember user's name:

import requests
API_URL = "http://localhost:3000/api/v1/prediction/<chatlfowid>"

def query(payload):
    response = requests.post(API_URL, json=payload)
    return response.json()
    
output = query({
    "question": "Hey, how are you?",
    "history": [
        {
            "role": "apiMessage",
            "content": "Hello how can I help?"
        },
        {
            "role": "userMessage",
            "content": "Hi my name is Brian"
        },
        {
            "role": "apiMessage",
            "content": "Hi Brian, how can I help?"
        },
    ]
})

Persists Memory

If the chatflow contains Memory nodes, you can pass a sessionId to persists the state of the conversation, so the every subsequent API calls will have context about previous conversation. Otherwise, a new session will be generated each time.

import requests
API_URL = "http://localhost:3000/api/v1/prediction/<chatlfowid>"

def query(payload):
    response = requests.post(API_URL, json=payload)
    return response.json()
    
output = query({
    "question": "Hey, how are you?",
    "overrideConfig": {
        "sessionId": "123"
    } 
})

Image Uploads

When Allow Image Upload is enabled, images can be uploaded from chat interface.

import requests
API_URL = "http://localhost:3000/api/v1/prediction/<chatlfowid>"

def query(payload):
    response = requests.post(API_URL, json=payload)
    return response.json()
    
output = query({
    "question": "Can you describe the image?",
    "uploads": [
        {
            "data": 'data:image/png;base64,iVBORw0KGgdM2uN0', # base64 string or url
            "type": 'file', # file | url
            "name": 'Flowise.png',
            "mime": 'image/png'
        }
    ]
})

Speech to Text

When Speech to Text is enabled, users can speak directly into microphone and speech will be transcribed into text.

import requests
API_URL = "http://localhost:3000/api/v1/prediction/<chatlfowid>"

def query(payload):
    response = requests.post(API_URL, json=payload)
    return response.json()
    
output = query({
    "uploads": [
        {
            "data": 'data:audio/webm;codecs=opus;base64,GkXf', #base64 string
            "type": 'audio',
            "name": 'audio.wav',
            "mime": 'audio/webm'
        }
    ]
})

Authentication

You can assign an API key to the prediction API from the UI. Refer Chatflow Level for more details.

The Authorization header must be provided with the correct API key specified during a HTTP call.

"Authorization": "Bearer <your-api-key>"

2. Vector Upsert API

  • POST /api/v1/vector/upsert/{your-chatflowid}

Request Body

KeyDescriptionTypeRequired

overrideConfig

Override existing flow configuration

object

No

stopNodeId

Node ID of the vector store. When you have multiple vector stores in a flow, you might not want to upsert all of them. Specifying stopNodeId will ensure only that specific vector store node is upserted.

array

No

Document Loaders with Upload

Some document loaders in Flowise allow user to upload files:

If the flow contains Document Loaders with Upload File functionality, the API looks slightly different. Instead of passing body as JSON, form-data is being used. This allows you to upload any files to the API.

It is user's responsibility to make sure the file type is compatible with the expected file type from document loader. For example, if a Text File Loader is being used, you should only upload file with .txt extension.

import requests

API_URL = "http://localhost:3000/api/v1/vector/upsert/<chatlfowid>"

# use form data to upload files
form_data = {
    "files": ('state_of_the_union.txt', open('state_of_the_union.txt', 'rb'))
}

body_data = {
    "returnSourceDocuments": True
}

def query(form_data):
    response = requests.post(API_URL, files=form_data, data=body_data)
    print(response)
    return response.json()

output = query(form_data)
print(output)

Document Loaders without Upload

For other Document Loaders nodes without Upload File functionality, the API body is in JSON format similar to Prediction API.

import requests

API_URL = "http://localhost:3000/api/v1/vector/upsert/<chatlfowid>"

def query(form_data):
    response = requests.post(API_URL, json=payload)
    print(response)
    return response.json()

output = query({
    "overrideConfig": { # optional
        "returnSourceDocuments": true
    }
})
print(output)

Authentication

You can assign an API key to the prediction API from the UI. Refer Chatflow Level for more details.

The Authorization header must be provided with the correct API key specified during a HTTP call.

"Authorization": "Bearer <your-api-key>"

3. Message API

  • GET /api/v1/chatmessage/{your-chatflowid}

  • DELETE /api/v1/chatmessage/{your-chatflowid}

Query Parameters

ParamTypeValue

sessionId

string

sort

enum

ASC or DESC

startDate

string

endDate

string

Authentication

Message API is restricted to only Flowise admin user. Basic authentication must be provided in the headers if Flowise instance has been configured with FLOWISE_USERNAME and FLOWISE_PASSWORD. Refer App Level for more details.

"Authorization": "Basic " + Buffer.from(username + ":" + password).toString('base64')

Video Tutorials

Those video tutorials cover the main use cases for implementing the Flowise API.

Last updated