Skip to main content

API Endpoints

Prediction API

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

Request Body

KeyDescriptionTypeRequired
questionUser's questionstringYes
overrideConfigOverride existing flow configurationobjectNo
historyPrepend history messagesarrayNo

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

Override Config

You can override input configuration with the overrideConfig property.

{
"question": "Hey, how are you?",
"overrideConfig": {
"sessionId": "123",
"returnSourceDocuments": true
}
}

History

You can prepend history messages to provide context to the LLM:

{
"question": "Hey, how are you?",
"history": [
{
"role": "apiMessage",
"content": "Hello, how can I help?"
},
{
"role": "userMessage",
"content": "Hi, my name is Alice"
},
{
"role": "apiMessage",
"content": "Hi Alice, how can I assist you today?"
}
]
}

Persisting Memory

If the chatflow contains Memory nodes, you can pass a sessionId to persist the conversation state:

{
"question": "Hey, how are you?",
"overrideConfig": {
"sessionId": "123"
}
}

Image Uploads

When image upload is enabled, you can include image data in the request:

{
"question": "Can you describe this image?",
"uploads": [
{
"data": "data:image/png;base64,iVBORw0KGgdM2uN0",
"type": "file",
"name": "example.png",
"mime": "image/png"
}
]
}

Speech to Text

When speech-to-text is enabled, you can send audio data:

{
"uploads": [
{
"data": "data:audio/webm;codecs=opus;base64,GkXf",
"type": "audio",
"name": "speech.webm",
"mime": "audio/webm"
}
]
}

Authentication

Include an API key in the Authorization header:

Authorization: Bearer <your-api-key>

Vector Upsert API

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

Request Body

KeyDescriptionTypeRequired
overrideConfigOverride existing flow configurationobjectNo
stopNodeIdSpecific vector store node to upsertarrayNo

Document Loaders with Upload

For document loaders that support file uploads, use multipart/form-data:

POST /api/v1/vector/upsert/{your-chatflowid}
Content-Type: multipart/form-data

files: (binary)
returnSourceDocuments: true

Document Loaders without Upload

For other document loaders, use a JSON body:

{
"overrideConfig": {
"returnSourceDocuments": true
}
}

Authentication

Include an API key in the Authorization header:

Authorization: Bearer <your-api-key>

3. Message API

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

Query Parameters

ParamTypeDescription
sessionIdstringSession identifier
sortenumASC or DESC
startDatestringStart date for filter
endDatestringEnd date for filter

Authentication

The Message API is restricted to admin users. Use Basic Authentication:

Authorization: Basic <base64-encoded-credentials>

Implementation Examples

Here are some examples of how to use the AnswerAI API in different programming languages:

Python

import requests

API_URL = "<your-answer-ai-host-domain>/api/v1/prediction/<chatflowid>"
API_KEY = "your-api-key"

headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}

data = {
"question": "What is AnswerAI?",
"overrideConfig": {
"sessionId": "unique-session-id"
}
}

response = requests.post(API_URL, json=data, headers=headers)
print(response.json())

JavaScript

const API_URL = '<your-answer-ai-host-domain>/api/v1/prediction/<chatflowid>'
const API_KEY = 'your-api-key'

async function query(data) {
const response = await fetch(API_URL, {
method: 'POST',
headers: {
Authorization: `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
return await response.json()
}

query({
question: 'What is AnswerAI?',
overrideConfig: {
sessionId: 'unique-session-id'
}
}).then((response) => console.log(response))

These examples demonstrate how to make basic API calls to AnswerAI. Remember to replace <chatflowid> with your actual chatflow ID and use your specific API key for authentication.