> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bland.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat with Knowledge Base Item

> Performs a conversational query against knowledge base items with context.

Query a knowledge base item 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 item to query against.

### Response

**data** `object`

Chat response with contextual information.

**data.response** `string`

The AI-generated response based on the knowledge base item 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.

```json Success Response theme={null}
{
  "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
}
```

```json Error Response theme={null}
{
  "data": null,
  "errors": [
    {
      "error": "KB_ERROR",
      "message": "Knowledge base not found or not accessible"
    }
  ]
}
```

***

Docs for agents: [llms.txt](https://docs.bland.ai/llms.txt)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.