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

# Corpus

> Endpoints to manage the knowledge base

Endpoints to manage the chatbot's corpus (knowledge base).

## GET /tenants/{slug}/corpus

List all corpus entries.

**Required scope:** `corpus:read`

### Request

```bash theme={null}
curl https://api.animam.ai/tenants/my-company/corpus \
  -H "Authorization: Bearer ak_your_token"
```

### Query Parameters

| Param     | Type   | Description                              |
| --------- | ------ | ---------------------------------------- |
| `page`    | number | Page (default: 1)                        |
| `limit`   | number | Entries per page (default: 20, max: 100) |
| `segment` | string | Filter by segment                        |
| `search`  | string | Text search                              |

### Response

```json theme={null}
{
  "corpus": [
    {
      "id": "corp_abc123",
      "title": "Return Policy",
      "content": "You have 30 days to return...",
      "segment": "checkout",
      "priority": 5,
      "createdAt": "2024-01-15T10:30:00Z",
      "updatedAt": "2024-01-20T14:00:00Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 42,
    "pages": 3
  }
}
```

## GET /tenants/{slug}/corpus/{id}

Retrieve a specific entry.

**Required scope:** `corpus:read`

```bash theme={null}
curl https://api.animam.ai/tenants/my-company/corpus/corp_abc123 \
  -H "Authorization: Bearer ak_your_token"
```

## POST /tenants/{slug}/corpus

Create a new entry.

**Required scope:** `corpus:write`

### Request

```bash theme={null}
curl -X POST https://api.animam.ai/tenants/my-company/corpus \
  -H "Authorization: Bearer ak_your_token" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Business hours",
    "content": "We are open Monday to Friday, 9am to 6pm. Saturday 10am to 4pm.",
    "segment": "contact",
    "priority": 5
  }'
```

### Body

| Field      | Type      | Required | Description                |
| ---------- | --------- | -------- | -------------------------- |
| `title`    | string    | Yes      | Entry title                |
| `content`  | string    | Yes      | Content (max 50,000 chars) |
| `segment`  | string    | No       | Associated segment         |
| `priority` | number    | No       | Priority 1-10 (default: 5) |
| `tags`     | string\[] | No       | Tags for matching          |

### Response

```json theme={null}
{
  "id": "corp_xyz789",
  "title": "Business hours",
  "content": "We are open...",
  "segment": "contact",
  "priority": 5,
  "createdAt": "2024-01-25T10:30:00Z"
}
```

## PATCH /tenants/{slug}/corpus/{id}

Modify an existing entry.

**Required scope:** `corpus:write`

```bash theme={null}
curl -X PATCH https://api.animam.ai/tenants/my-company/corpus/corp_abc123 \
  -H "Authorization: Bearer ak_your_token" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Updated content",
    "priority": 8
  }'
```

## DELETE /tenants/{slug}/corpus/{id}

Delete an entry.

**Required scope:** `corpus:write`

```bash theme={null}
curl -X DELETE https://api.animam.ai/tenants/my-company/corpus/corp_abc123 \
  -H "Authorization: Bearer ak_your_token"
```

### Response

```json theme={null}
{
  "deleted": true,
  "id": "corp_abc123"
}
```

## POST /tenants/{slug}/corpus/import

Bulk import via CSV.

**Required scope:** `corpus:write`

```bash theme={null}
curl -X POST https://api.animam.ai/tenants/my-company/corpus/import \
  -H "Authorization: Bearer ak_your_token" \
  -F "file=@corpus.csv"
```

### CSV format

```csv theme={null}
title,content,segment,priority
"Hours","Open 9am-6pm","contact",5
"Price","$49/month","pricing",10
```

### Response

```json theme={null}
{
  "imported": 15,
  "errors": [
    { "line": 3, "error": "Missing required field: content" }
  ]
}
```
