Implementation:FlowiseAI Flowise SendMessageAndGetPrediction
| Attribute | Value |
|---|---|
| Source Repository | FlowiseAI/Flowise |
| Source File | packages/ui/src/api/prediction.js
|
| Domain | Chatflow_Creation |
| Workflow | Chatflow_Creation |
| Last Updated | 2026-02-12 |
Overview
Concrete API client functions for sending prediction requests to a Flowise chatflow endpoint. The module exports three functions covering internal non-streaming, internal streaming, and public prediction endpoints. These functions are the primary interface for executing chatflow graphs with user messages and receiving AI-generated responses.
Code Reference
Source Location
- File:
packages/ui/src/api/prediction.js - Lines: L3-5
Signature
const sendMessageAndGetPrediction = (id, input) =>
client.post(`/internal-prediction/${id}`, input)
const sendMessageAndStreamPrediction = (id, input) =>
client.post(`/internal-prediction/stream/${id}`, input)
const sendMessageAndGetPredictionPublic = (id, input) =>
client.post(`/prediction/${id}`, input)
Import
import predictionApi from '@/api/prediction'
I/O Contract
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | string |
Yes | The chatflow ID identifying which flow graph to execute |
| input | object |
Yes | The prediction request payload |
| input.question | string |
Yes | The user's message text to process |
| input.chatId | string |
No | Conversation session ID for multi-turn conversations; omit for the first message |
| input.uploads | Upload[] |
No | Array of file uploads (images, documents) to include with the message |
| input.overrideConfig | object |
No | Runtime configuration overrides for node parameters |
| input.streaming | boolean |
No | Whether to request streaming mode (only relevant for certain endpoints) |
Outputs
| Field | Type | Description |
|---|---|---|
| data.text | string |
The generated response text from the chatflow |
| data.chatMessageId | string |
Unique identifier for this message exchange |
| data.sourceDocuments | Document[] |
Retrieved source documents (for RAG-based chatflows) |
| data.usedTools | ToolUsage[] |
Tools that were invoked during processing |
| data.agentReasoning | Reasoning[] |
Agent's step-by-step reasoning trace |
| data.fileAnnotations | Annotation[] |
File references embedded in the response |
| data.chatId | string |
The conversation session ID (assigned by server if not provided) |
Implementation Details
Endpoint Variants
| Function | HTTP Method | Endpoint | Use Case |
|---|---|---|---|
sendMessageAndGetPrediction |
POST | /api/v1/internal-prediction/{id} |
Internal UI testing, non-streaming mode |
sendMessageAndStreamPrediction |
POST | /api/v1/internal-prediction/stream/{id} |
Internal UI testing, streaming mode (SSE) |
sendMessageAndGetPredictionPublic |
POST | /api/v1/prediction/{id} |
Public API access for deployed chatflows |
The internal endpoints include the x-request-from: internal header (set by the Axios client in client.js), which distinguishes internal test requests from external API calls on the server side.
Streaming Mode Decision
The decision between streaming and non-streaming is made by querying the chatflow's streaming capability before the first message. The chatflows.js module provides:
const getIsChatflowStreaming = (id) => client.get(`/chatflows-streaming/${id}`)
The chat UI component (ChatMessage) checks this and routes to the appropriate prediction function accordingly.
Session Persistence
The chat ID is persisted in localStorage for conversation continuity:
// From packages/ui/src/utils/genericHelper.js
export const setLocalStorageChatflow = (chatflowid, chatId, saveObj = {}) => {
const obj = { ...saveObj }
if (chatId) obj.chatId = chatId
localStorage.setItem(`${chatflowid}_INTERNAL`, JSON.stringify(obj))
}
export const getLocalStorageChatflow = (chatflowid) => {
const chatDetails = localStorage.getItem(`${chatflowid}_INTERNAL`)
if (!chatDetails) return {}
return JSON.parse(chatDetails)
}
Usage Examples
Non-streaming prediction
import predictionApi from '@/api/prediction'
const chatflowId = 'abc-123'
const response = await predictionApi.sendMessageAndGetPrediction(chatflowId, {
question: 'What is the capital of France?',
chatId: 'session-456'
})
const answer = response.data.text // "The capital of France is Paris."
const sources = response.data.sourceDocuments // [...] if RAG is configured
Streaming prediction
import predictionApi from '@/api/prediction'
const chatflowId = 'abc-123'
const response = await predictionApi.sendMessageAndStreamPrediction(chatflowId, {
question: 'Explain quantum computing in simple terms.',
chatId: 'session-456'
})
// The response is processed as an SSE stream by the chat UI component
// Partial tokens are displayed as they arrive
Public endpoint for deployed chatflows
import predictionApi from '@/api/prediction'
const chatflowId = 'deployed-flow-789'
const response = await predictionApi.sendMessageAndGetPredictionPublic(chatflowId, {
question: 'Help me track my order #12345',
overrideConfig: {
temperature: 0.5
}
})
const answer = response.data.text
const tools = response.data.usedTools // Tools used during processing
First message in a new conversation (no chatId)
import predictionApi from '@/api/prediction'
import { setLocalStorageChatflow } from '@/utils/genericHelper'
const chatflowId = 'abc-123'
// First message -- no chatId
const response = await predictionApi.sendMessageAndGetPrediction(chatflowId, {
question: 'Hello, I need help with my account.'
})
// Save the server-assigned chatId for subsequent messages
const chatId = response.data.chatId
setLocalStorageChatflow(chatflowId, chatId)
// Subsequent messages include the chatId
const followUp = await predictionApi.sendMessageAndGetPrediction(chatflowId, {
question: 'Can you look up my billing history?',
chatId: chatId
})