POST
/
v1
/
knowledge
/
chat
Chat with Knowledge Base
curl --request POST \
  --url https://api.bland.ai/v1/knowledge/chat \
  --header 'authorization: <authorization>' \
  --header 'content-type: <content-type>' \
  --data '{
  "messages": [
    {
      "messages[].role": "<string>",
      "messages[].content": "<string>"
    }
  ],
  "knowledge_base_id": "<string>"
}'
{
  "data": {
    "response": "Our refund policy allows for full refunds within 30 days of purchase. For products purchased more than 30 days ago, we offer store credit or exchanges. Please contact our customer service team at support@example.com to initiate a refund request.",
    "context": "Based on company policy documentation regarding refunds and returns",
    "sources": [
      {
        "id": "doc_01H8X9QK5R2N7P3M6Z8W4Y1V7V",
        "content": "Refund Policy: Full refunds are available within 30 days of purchase...",
        "metadata": {
          "document_type": "policy",
          "section": "refunds",
          "last_updated": "2025-01-01"
        }
      }
    ]
  },
  "errors": null
}
Query a knowledge base using natural language and receive contextual responses. This endpoint supports both direct queries and conversational context through message history.

Headers

authorization
string
required
Your API key for authentication.
content-type
string
required
Must be application/json.

Body Parameters

messages
array
Array of chat messages for conversational context. Use this for multi-turn conversations.
messages[].role
string
required
The role of the message sender (e.g., “user”, “assistant”, “system”).
messages[].content
string
required
The content of the message.
knowledge_base_id
string
required
The ID of the knowledge base to query against.

Response

data
object
Chat response with contextual information.
data.response
string
The AI-generated response based on the knowledge base content.
data.context
string
Additional context information used to generate the response.
data.sources
array
Array of source documents that were used to generate the response.
data.sources[].id
string
Unique identifier of the source document.
data.sources[].content
string
Relevant content from the source document.
data.sources[].metadata
object
Additional metadata about the source document.
errors
null
Will be null on successful query.
{
  "data": {
    "response": "Our refund policy allows for full refunds within 30 days of purchase. For products purchased more than 30 days ago, we offer store credit or exchanges. Please contact our customer service team at support@example.com to initiate a refund request.",
    "context": "Based on company policy documentation regarding refunds and returns",
    "sources": [
      {
        "id": "doc_01H8X9QK5R2N7P3M6Z8W4Y1V7V",
        "content": "Refund Policy: Full refunds are available within 30 days of purchase...",
        "metadata": {
          "document_type": "policy",
          "section": "refunds",
          "last_updated": "2025-01-01"
        }
      }
    ]
  },
  "errors": null
}