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

# Create Knowledge Base

> Creates a new knowledge base

Create a new knowledge base in your organization to store and manage documents.

## Request Body

<ParamField body="name" type="string" required>
  Display name for the knowledge base
</ParamField>

<ParamField body="description" type="string">
  Optional description of the knowledge base purpose
</ParamField>

## Response

<ResponseField name="id" type="string">
  Unique identifier for the knowledge base (UUID)
</ResponseField>

<ResponseField name="name" type="string">
  Display name of the knowledge base
</ResponseField>

<ResponseField name="description" type="string">
  Description of the knowledge base (nullable)
</ResponseField>

<ResponseField name="type" type="string">
  Knowledge base type: `managed`
</ResponseField>

<ResponseField name="organization_id" type="string">
  UUID of the organization that owns this knowledge base
</ResponseField>

<ResponseField name="agent_id" type="string">
  Associated agent ID (nullable)
</ResponseField>

<ResponseField name="total_documents" type="integer">
  Number of documents in the knowledge base (initially 0)
</ResponseField>

## Example Request

```bash theme={"dark"}
curl -X POST -H "x-api-key: <your-api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Technical Documentation",
    "description": "Internal technical guides and API documentation"
  }' \
  https://api.xpander.ai/v1/knowledge
```

## Example Response

```json theme={"dark"}
{
  "id": "<kb-id>",
  "name": "Product Catalog",
  "description": "Product information and specifications for customer support",
  "type": "managed",
  "organization_id": "<org-id>",
  "agent_id": null,
  "total_documents": 0
}
```

## Notes

* New knowledge bases start with zero documents
* Use the returned `id` to add documents via the [Add Documents](/api-reference/v1/knowledge/add-documents) endpoint


## OpenAPI

````yaml POST /v1/knowledge
openapi: 3.1.0
info:
  title: xpander.ai API Service
  description: |2-

        The xpander.ai API Service provides a unified REST API for managing AI agents,
        executing tasks, managing knowledge bases, and integrating with external systems.
        
        Features:
        - Agent Management: Create, update, deploy, and delete AI agents
        - Task Execution: Invoke agents with support for sync, async, and streaming modes
        - Knowledge Bases: Manage knowledge bases and documents for RAG workflows
        - Tools: Discover, connect, and attach tools (connectors, custom functions, MCP servers, sub-agents, workflows) to agents and workflows
        - MCP Integration: Model Context Protocol support for standardized AI interactions
        
        Authentication: All endpoints require authentication via either an API key (`x-api-key`) or an OAuth2 JWT (`Authorization: Bearer <jwt>`).
        
  version: '0.001'
servers:
  - url: https://api.xpander.ai
security: []
paths:
  /v1/knowledge:
    post:
      tags:
        - API v1
        - Knowledge
        - Knowledge CRUD
      summary: Create Knowledge Base
      description: Creates a knowledge base
      operationId: Create_knowledge_base_v1_knowledge_post
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateManagedKnowledgeBaseRequest'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/KnowledgeBaseItem'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyHeader: []
components:
  schemas:
    CreateManagedKnowledgeBaseRequest:
      properties:
        name:
          type: string
          title: Name
          description: KB name specified by the user
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          description: KB description specified by the user
      type: object
      required:
        - name
      title: CreateManagedKnowledgeBaseRequest
    KnowledgeBaseItem:
      properties:
        id:
          type: string
          title: Id
          description: KB unique identifier
        name:
          type: string
          title: Name
          description: KB name specified by the user
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          description: KB description specified by the user
        type:
          $ref: '#/components/schemas/KnowledgeBaseType'
          description: KB type, managed / external
        organization_id:
          type: string
          title: Organization Id
          description: Organization ID
        agent_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Agent Id
          description: Agent ID
        total_documents:
          type: integer
          title: Total Documents
          description: Total count of embedded documents
          default: 0
      type: object
      required:
        - id
        - name
        - type
        - organization_id
      title: KnowledgeBaseItem
      description: |-
        Represents a Knowledge Base item.

        Attributes:
            id (str): KB unique identifier.
            name (str): KB name specified by the user.
            description (str): KB description specified by the user.
            type (KnowledgeBaseType): KB type, either managed or external.
            organization_id (str): Organization ID associated with the KB.
            total_documents (int): Total count of embedded documents. Defaults to 0.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    KnowledgeBaseType:
      type: string
      enum:
        - managed
        - external
      title: KnowledgeBaseType
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      description: API Key for authentication
      in: header
      name: x-api-key

````