# Create a knowledge base

> Creates an empty knowledge base; add documents with Add a knowledge base document. With validate_only, the checks run and 204 answers, nothing is created.

Source: https://docs.stacksync.com/api-reference/knowledge-bases/create_knowledge_base

`POST https://api.stacksync.com/v1/workspaces/{workspace_id}/knowledge-bases`

- Operation: `create_knowledge_base`
- Resource: Knowledge bases
- Access: writes data

## Authentication

- `Authorization: Bearer <key>`: A workspace API key (workspace_…, created by a workspace owner under Workspace settings > Stacksync API) acts with editor rights on that workspace only; a user API key (user_…, created under Profile > Stacksync API) acts as that user in every workspace they belong to. POST, PUT and PATCH requests must send Content-Type: application/json. Every authentication failure answers 403.
- `Content-Type: application/json` on every request with a body.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspace_id` | integer | Yes | The workspace. List the ones your key can reach with GET /v1/workspaces. |

## Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `region` | string (besg \| usnv) | Yes | Region of the resource: besg (Europe) or usnv (United States), as GET /v1/regions lists them |

## Header parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string \| null | No | Makes the create retry-safe for 24 hours: a retry with the same key answers the resource the first call created, with the Idempotent-Replayed: true header, and creates nothing. 1 to 255 visible ASCII characters. The same key with a different request answers 422; while the first call still runs, 409. |

## Request body

`application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string, 1 to 255 characters | Yes | Name, unique among the workspace's knowledge bases of the region |
| `resource_id` | string \| null, pattern `^[a-z0-9_]{1,60}$` | No | The id genies reference it by, unique in the region; derived from the name when absent (a renamed knowledge base keeps its own, so its old name needs another one) |
| `folder_id` | string (uuid) \| null | No | Folder to list it in; the root when absent |
| `is_shared_with_workspace` | boolean, default false | No | true lets every member of the workspace use it |
| `validate_only` | boolean, default false | No | Run every check of the write and answer 204 without writing: a refused write answers the error the write would |

## Returns

### 201 Created

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `knowledge_base_id` | string | Yes |  |
| `name` | string | Yes |  |
| `resource_id` | string | Yes |  |
| `region` | string | Yes |  |
| `is_shared_with_workspace` | boolean | Yes |  |
| `folder_id` | string \| null | Yes |  |
| `created_time` | string (date-time) | Yes |  |
| `last_modified_time` | string (date-time) | Yes |  |

### 204 No Content

No body.

## Example request

```bash
curl -X POST "https://api.stacksync.com/v1/workspaces/{workspace_id}/knowledge-bases?region=besg" \
  -H "Authorization: Bearer $STACKSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "<name>"
}'
```

## Example response (201)

```json
{
  "knowledge_base_id": "<knowledge_base_id>",
  "name": "<name>",
  "resource_id": "<resource_id>",
  "region": "<region>",
  "is_shared_with_workspace": false,
  "folder_id": "<folder_id>",
  "created_time": "2027-01-15T09:00:00Z",
  "last_modified_time": "2027-01-15T09:00:00Z"
}
```

## Errors

| Status | Meaning | Body |
| --- | --- | --- |
| 400 | Bad Request | `{ "error": string, "msg": string, "field": string \| null }` |
| 403 | Forbidden | `{ "error": string, "msg": string, "field": string \| null }` |
| 409 | Conflict | `{ "error": string, "msg": string, "field": string \| null }` |
| 422 | Unprocessable Content | `{ "error": string, "msg": string, "field": string \| null }` |

## Related

- [API Reference overview](https://docs.stacksync.com/api-reference): base URLs, regions, pagination, idempotency and errors
- [Authentication](https://docs.stacksync.com/api-reference/authentication): API keys and the 403 answers
- OpenAPI document: https://docs.stacksync.com/openapi.json
- [List knowledge bases](https://docs.stacksync.com/api-reference/knowledge-bases/list_knowledge_bases)
- [Get a knowledge base](https://docs.stacksync.com/api-reference/knowledge-bases/get_knowledge_base)
- [Update a knowledge base](https://docs.stacksync.com/api-reference/knowledge-bases/update_knowledge_base)
- [Delete a knowledge base](https://docs.stacksync.com/api-reference/knowledge-bases/delete_knowledge_base)