# Create knowledge base

> POST https://api.nabrah.ai/api/ext/kb

Group: Knowledge bases. Page: https://www.nabrah.ai/en/docs/api-reference/knowledge-bases/create-knowledge-base

Creates a knowledge base (KB) in your project. A KB is a named container of documents that an agent can retrieve from during a call. Provide a human-readable `name`, a stable machine `key` used to reference the KB from agents/tools, and a `desc` that tells the agent **when** to use this KB. The `key` must be unique within the project — a duplicate returns **409**. Returns the created KB, including its `id` and `document_count` (0 to start). Next steps: upload documents with `POST /api/ext/document/file`, then link the KB to an agent so it becomes retrievable at call time.

## Request

- **name**: Human-readable display name for the knowledge base. 1–255 characters. Fields: `name`.
- **key**: Stable machine identifier used to reference this KB from agents. Must match `^[A-Za-z_][A-Za-z0-9_]*$` (letters, digits, underscore; not starting with a digit), 1–100 chars, and be unique within the project. Fields: `key`.
- **desc**: Short description of what the KB contains and when the agent should consult it. This guides retrieval, so be specific. Fields: `desc`.

Duplicate `key` in the same project returns 409.

## Authorization

- `X-API-Key` (string, header, required): your workspace API key.

## Body (application/json)

### Example: Create KB

A simple product knowledge base.

```json
{
  "name": "Product FAQ",
  "key": "product_faq",
  "desc": "Answers about product features, pricing, plans, and returns. Use for general product questions."
}
```

## Response

### 201 Successful Response

Content type: `application/json`

```json
{
  "id": "00000000-0000-4000-8000-000000000000",
  "project_id": "00000000-0000-4000-8000-000000000000",
  "name": "string",
  "key": "string",
  "desc": "string",
  "document_count": 0,
  "created_at": "2026-01-15T12:00:00.000Z",
  "updated_at": "2026-01-15T12:00:00.000Z"
}
```

### 422 Validation Error

Content type: `application/json`

```json
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

## Request examples

### cURL

```bash
curl --request POST \
  --url 'https://api.nabrah.ai/api/ext/kb' \
  --header 'X-API-Key: <your-api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "Product FAQ",
  "key": "product_faq",
  "desc": "Answers about product features, pricing, plans, and returns. Use for general product questions."
}'
```

### Python

```python
import requests

url = "https://api.nabrah.ai/api/ext/kb"
headers = {
    "X-API-Key": "<your-api-key>",
}
payload = {
    "name": "Product FAQ",
    "key": "product_faq",
    "desc": "Answers about product features, pricing, plans, and returns. Use for general product questions."
}

response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
print(response.json())
```

### JavaScript

```javascript
const response = await fetch("https://api.nabrah.ai/api/ext/kb", {
  method: "POST",
  headers: {
    "X-API-Key": "<your-api-key>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "Product FAQ",
    "key": "product_faq",
    "desc": "Answers about product features, pricing, plans, and returns. Use for general product questions."
  }),
});

const data = await response.json();
console.log(data);
```

### Go

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"strings"
)

func main() {
	payload := strings.NewReader(`{
  "name": "Product FAQ",
  "key": "product_faq",
  "desc": "Answers about product features, pricing, plans, and returns. Use for general product questions."
}`)

	req, _ := http.NewRequest("POST", "https://api.nabrah.ai/api/ext/kb", payload)
	req.Header.Set("X-API-Key", "<your-api-key>")
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	out, _ := io.ReadAll(res.Body)
	fmt.Println(string(out))
}
```
