Skip to main content
Languages: every operation supports cURL, Node.js (TypeScript), Python, Go, Ruby, and PHP. The first 15 operations on this page show all six languages; the remaining 11 show cURL and TypeScript — the two most-used.

Knowledge Bases API

Store, index, and search knowledge-base documents for agent grounding Base path: /api/v1/knowledge-bases Endpoint count: 26

Worked sequences

The twenty operations below are the full knowledge-base surface, but four round trips cover the document lifecycle most integrations actually run: upload a document, moderate it once the review queue picks it up, search the base to preview what an agent would retrieve, and diff two versions when the ground truth changed. Each sequence shows the body you send and the body the API returns. For the prose walkthrough of the whole lifecycle (create → load → attach → tune → maintain), read Build and Maintain an AI Knowledge Base. You need the knowledge:write scope (owner / admin / developer role) for uploads and moderation, and knowledge:read for search and diffs.

1. Upload a document

Binary files (PDF, DOCX, images — OCR-extracted) go up as multipart/form-data. Send the file bytes plus the name and type fields; the accepted document comes back in processing status because chunking and embedding run asynchronously. Poll GET /knowledge-bases/kb_abc123/documents until the status reaches ready.
202
A 422 on a multipart upload means a missing name/type field or raw JSON carrying binary bytes — binary formats are multipart-only (inline text under the 10 MB cap may go up as a JSON content body instead; see the operation below).

2. Approve or reject a pending document

A document submitted for moderation (for example, a gap-cluster draft) sits pending until a reviewer acts. Approving flips its publish lifecycle to approved and starts deferred vector indexing so its chunks become retrievable; rejecting flips it to rejected and its chunks are never indexed. Optional notes are stored on the document for the submitter. Approve:
200
Reject the same way — a document that was never indexed stays out of agent retrieval either way:
200
Both actions are audit-logged — approval promotes a document to RAG ground-truth, which is an admin-class decision.

3. Search the knowledge base

This is the same retrieval an attached agent’s search_knowledge tool runs, and the response shape exists so you can preview what an agent would ground on before a customer asks. Results are relevance-ranked chunks; when a per-base search config is active, recency, source weighting, and category filters apply before the list is truncated to limit (default 5).
200
An empty results array means no chunk cleared the raw similarity floor — check whether the document you expect is uploaded, approved, and indexed.

4. Diff two document versions

Every re-upload retains the prior copy as an immutable snapshot, so you can always ask what changed. GET /knowledge-bases/kb_abc123/documents/doc_9a1c3e5b7d/versions/diff takes from and to 1-based version numbers and returns added / removed / unchanged line counts plus unified-style hunk lines (+ added, - removed, context). truncated: true means the inputs were too large for a line-level diff. A 422 here means one of those versions isn’t in the retained lineage. Roll back with POST .../rollback and a body like { "version": 1 } once the hunks confirm the regression.
200

5. Worked sequences — advanced lifecycle

Beyond upload and read-back, most AI-agent deployments run the full editorial loop: register an external source connector with POST /api/v1/knowledge-bases/{id}/connectors, kick off its initial sync with POST .../sync, watch drift and staleness, moderate the AI assistant’s proposed documents, roll a published version back after reading the lineage, and delete the documents the team has retired. The samples below keep the same identifiers end-to-end; pause on scheduled syncs by patching a connector with enabled: false.

5.1 Create a connector and start its initial sync

Register a connector that pulls one knowledge base’s documents from an external source. The body names the provider (one of notion, confluence, google_drive, sharepoint, zendesk) plus an optional scope, sync_schedule (default daily), and auto_refresh_on_drift. The returned id stays the handle for every later call.
201
Start the first pull right away instead of waiting for the schedule. A sync that is accepted but has not yet been picked up by the drain worker reports "status": "queued" (some builds surface the same transition as "syncing"); once a worker claims the row, the same endpoint reports "status": "running" as below. The response is 202 because the sync runs asynchronously; poll GET /api/v1/knowledge-bases/{id}/connectors for the connector’s last-sync status as it moves through queued → syncing → running.
202

5.2 Read the connector drift report and staleness

Once a sync has pulled, the connector drain worker hashes the live source and compares it against the cached content your agents ground on. Read the drift scorecard to decide whether to re-sync or to switch auto_refresh_on_drift on. Until the worker has checked a connector at least once, detection_active is false — the 0-drifted totals are not yet a passing signal.
200
Staleness is the document-side companion: it buckets each document into fresh, stale, or critical against your org’s threshold (90 days by default; override per call with ?default_threshold_days= or per document via its metadata) so an operator’s review queue catches the files an agent still quotes as current.
200
Both endpoints are read-only and deliberately avoid audit-log writes, so polling them from a dashboard or a scheduled job stays cheap.

5.3 Approve or reject the assistant’s proposed document

This moderation path runs in addition to the plain upload flow when your knowledge base enables require_publish_approval, or when an AI assistant (for example, a gap-cluster draft) proposes a document — either way the file arrives with status: pending and never enters retrieval until a reviewer acts. Approving flips the document to approved and starts the deferred vector indexing; rejecting flips it to rejected and its chunks are never indexed. Optional notes are stored on the document so the submitter gets actionable feedback. Approve:
200
Reject the same way, or fix and re-upload before approving — a document that was never indexed stays out of agent retrieval either way:
200
Only documents pending review accept either decision — moderation status approved (or missing) returns 409 CONFLICT, and a publish-scan rejected document must be fixed and re-uploaded before it can be approved. Both actions are audit-logged.

5.4 Roll back a published version

Read the version lineage first, then the diff that tells you what the head changed, and roll back the published version if the retrieval set needs a previous copy. GET .../versions lists the immutable lineage — current head plus retained snapshots — without the heavy content blobs.
200
Read the diff for the two versions you care about. A version outside the retained lineage returns 404; a version whose content was too large to retain returns 422 — rollback works only against retained snapshots.
200
Then roll the document back. Non-destructive: the current head moves into the retained history first, so the operation is fully reversible.
202

5.5 Search the knowledge base

The POST .../search hook is the same retrieval an attached AI agent’s search_knowledge tool runs, and the response shape exists so you can preview what an agent would ground on before a customer asks. The body is query (required, ≤ 1000 chars) plus optional limit (default 5, max 20); when a per-base search config is active, recency, source weighting, and category filters apply before the list is truncated. An empty results array means no chunk cleared the raw similarity floor — check whether the document you expect is uploaded, approved, and indexed.
200

5.6 Delete a document and re-approve publication

A document stuck in moderation, or one the team retires, goes away in one call; anything that carries a public help-center article keeps its status through the same record — flip is_public on the publication endpoint once status is ready. Deleting returns 204 with no body.
204
Then re-publish the surviving document the public help center should keep. The body is { is_public: boolean, slug?, summary? }; flipping public requires the document’s ingestion be done (status: ready), and the slug is unique across every published article in your workspace — a slug collision returns 409 CONFLICT.
200
A document deleted after approval had its chunks removed from the vector index — a re-upload restarts the moderation queue from pending.

SDK surface bridge — Create a knowledge base and add its first source entry — the no-exec/callable shape the agent-runtime retrieval layer consumes.

These three tabs mirror SDK status and coverage. Python fronts client.request, Go fronts client.Request, and TS fronts fetch-TS — each with the sandbox key.

Create a knowledge base

Add a source entry




List knowledge bases

GET /api/v1/knowledge-bases
List the workspace’s knowledge bases — the document collections that ground an AI agent’s RAG answers — paginated by cursor and limit. Use this to resolve a knowledge-base id (kb_…) before uploading documents or registering connectors. Read-only; requires the knowledge:read scope.
string
Pagination cursor from the previous page’s pagination.next_cursor.
integer
Maximum knowledge bases per page (default 20). Coerced, so a numeric string also parses.

Get a knowledge base

GET /api/v1/knowledge-bases/{id}
Read a single knowledge base by id, including its name, description, refresh schedule, and metadata. Use it to confirm a knowledge base exists and inspect its configuration before uploading documents or adjusting connectors. Read-only; requires the knowledge:read scope.
string
required
Knowledge base id (kb_ prefixed).

Get knowledge-base connector drift report

GET /api/v1/knowledge-bases/{id}/connector-drift-report
Score a knowledge base’s source connectors for content drift: which sources have diverged from the content agents currently ground on since the last successful sync. Use it to find connectors that need a resync before their drift reaches an agent’s answers, or that need auto_refresh_on_drift turned on. Read-only; requires the knowledge:read scope.
string
required
Knowledge base id (kb_ prefixed).

List knowledge-base connectors

GET /api/v1/knowledge-bases/{id}/connectors
List the external-source sync connectors registered on a knowledge base (Notion / Confluence / Google Drive / SharePoint / Zendesk), with each connector’s sync schedule, scope, enabled state, and last-sync status. Read-only; requires the knowledge:read scope.
string
required
Knowledge base id (kb_ prefixed).

List documents in a knowledge base

GET /api/v1/knowledge-bases/{id}/documents
List a knowledge base’s documents paginated by cursor and limit. Poll this endpoint after an upload or indexing retry until the document’s status settles on indexed (or error). Read-only; requires the knowledge:read scope.
string
required
Knowledge base id (kb_ prefixed).
string
Pagination cursor from the previous page’s pagination.next_cursor.
integer
Maximum documents per page (default 20). Coerced, so a numeric string also parses.

List document versions

GET /api/v1/knowledge-bases/{id}/documents/{docId}/versions
Read the immutable version lineage of a document: its current head plus every retained snapshot of a superseded version, with per-version metadata (version number, uploaded-by, timestamp). Read before rollback so you can pick the exact snapshot to restore. Read-only; requires the knowledge:read scope.
string
required
Knowledge base id (kb_ prefixed).
string
required
Document id (kb_doc_ prefixed), as returned by GET /knowledge-bases/:id/documents. Obtain from GET /api/v1/knowledge-bases//documents.

Diff two document versions

GET /api/v1/knowledge-bases/{id}/documents/{docId}/versions/diff
Compare two snapshots of a document and return the content-level diff. Both from and to are required 1-based version numbers. Use it to check exactly what a rollback or a re-upload changed before promoting it to RAG retrieval. Read-only; requires the knowledge:read scope.
string
required
Knowledge base id (kb_ prefixed).
string
required
Document id (kb_doc_ prefixed), as returned by GET /knowledge-bases/:id/documents. Obtain from GET /api/v1/knowledge-bases//documents.
string
required
1-based version number of the earlier snapshot. Coerced to a number in-handler, so a numeric string also parses.
string
required
1-based version number of the later snapshot. Coerced to a number in-handler, so a numeric string also parses.

Get knowledge-base search config

GET /api/v1/knowledge-bases/{id}/search-config
Read a knowledge base’s retrieval re-rank / relevance-boost config — recency boost, per-source weights, category include/exclude, and the minimum-score threshold that govern which chunks ground every agent answer for this KB. A KB that has never been tuned reads back as the neutral default (every field a no-op, identical to legacy raw-similarity ordering). Read-only; requires the knowledge:read scope.
string
required
Knowledge base ID (kb_…).

Get knowledge-base staleness report

GET /api/v1/knowledge-bases/{id}/staleness
Score a knowledge base’s documents on freshness: each is classified FRESH / AGING / STALE against a threshold in days (default 30; override with the default_threshold_days query, 1-3650). Use it to find KB content that needs a connector resync or manual update before it grounds an AI agent’s answers. Read-only; requires the knowledge:read scope.
string
required
Knowledge base id (kb_ prefixed).
string
Staleness threshold in days, 1-3650 (default 30). Coerced to a number in-handler; documents not refreshed within it are reported AGING or STALE.

Create a knowledge base

POST /api/v1/knowledge-bases
Create a knowledge base — a named document collection that grounds an AI agent’s RAG answers. Once created, upload documents to it and optionally register external-source connectors. Returns 201 with the new knowledge base. Requires the knowledge:write scope; the creation is audit-logged.
string
required
Display name (1-200 chars), e.g. “Returns policy”.
string
Optional free-form description (max 1000 chars).
object
Optional key/value config persisted on the knowledge base.
string (enum: manual|hourly|daily|weekly)
Cadence for recurring re-fetch of external-source documents; manual (default) refreshes only on demand.

Add a connector to a knowledge base

POST /api/v1/knowledge-bases/{id}/connectors
Register a sync connector binding the knowledge base to an external source (Notion / Confluence / Google Drive / SharePoint / Zendesk). Matched pages/files are pulled on the schedule you set, and connection_id defaults to your organization id when omitted. Returns 201 with the new connector. Requires the knowledge:write scope; the registration is audit-logged.
string
required
Knowledge base id (kb_ prefixed).
string (enum: notion|confluence|google_drive|sharepoint|zendesk)
required
External source provider the connector pulls from.
string
Connection id to pull from (max 200 chars). Optional on create — defaults to your organization id (the connection-id convention shared with the integrations catalog).
string
Human-readable label for the connector (1-200 chars). On update, null clears it.
object
Which slice of the source to pull: space_keys, folder_ids, collection_ids, labels (all optional; empty = everything the connection can see).
string (enum: manual|hourly|daily|weekly)
How often the source is re-pulled (default daily; manual syncs only on demand).
boolean
Pause (false) or resume (true) scheduled syncs. Default true.
boolean
When true, a detected source content drift auto-queues a resync; when false (default), drift only appears in the drift report.

Sync a connector immediately

POST /api/v1/knowledge-bases/{id}/connectors/{connectorId}/sync
Queue an immediate sync for a connector, ahead of its schedule — use after fixing connector credentials or when a source changed and waiting for the next scheduled tick is not an option. The content pull runs asynchronously, so the endpoint returns 202 with the connector record immediately. Requires the knowledge:write scope; the request is audit-logged.
string
required
Knowledge base id (kb_ prefixed).
string
required
Connector id (kbc_ prefixed), as returned by GET /knowledge-bases/:id/connectors. Obtain from GET /api/v1/knowledge-bases//connectors.

Upload a document to a knowledge base

POST /api/v1/knowledge-bases/{id}/documents
Ingest a document into a knowledge base, then chunk, embed, and index it for RAG retrieval. Send JSON with name / type / content for inline text, or multipart/form-data for a binary file (PDF, DOCX, images — images go through vision OCR). The 10 MB content cap applies either way. Returns 202 with the document record: indexing is asynchronous, so poll GET /knowledge-bases/:id/documents until the document’s status is indexed (or error). Requires the knowledge:write scope.
string
required
Knowledge base id (kb_ prefixed).
string
required
Display name (1-200 chars).
string
File-type hint — text, markdown, pdf, docx, csv, etc. Defaults to text.
string
required
Document text content (max 10 MB). Use a multipart/form-data upload for binary files.
string
Optional source URL the content came from (or an empty string).
object
Optional caller-supplied metadata persisted with the document.

Approve a document for retrieval

POST /api/v1/knowledge-bases/{id}/documents/{docId}/approve
Publish a document that is pending moderation review: it becomes re-indexable and is admitted to RAG retrieval, so AI agents may answer from its content. Optionally record reviewer notes (up to 2000 chars) on the document’s moderation block. Requires the knowledge:write scope (admin / owner / developer); the approval is audit-logged.
string
required
Knowledge base id (kb_ prefixed).
string
required
Document id (kb_doc_ prefixed), as returned by GET /knowledge-bases/:id/documents. Obtain from GET /api/v1/knowledge-bases//documents.
string
Optional reviewer feedback (up to 2000 chars), persisted on the document’s moderation block.

Reject a document from retrieval

POST /api/v1/knowledge-bases/{id}/documents/{docId}/reject
Reject a document that is pending moderation review: it stays out of RAG retrieval (its chunks are never indexed) and the reviewer rationale is persisted so the author can see why. Send notes (up to 2000 chars) with the rejection reason. Requires the knowledge:write scope (admin / owner / developer); the rejection is audit-logged.
string
required
Knowledge base id (kb_ prefixed).
string
required
Document id (kb_doc_ prefixed), as returned by GET /knowledge-bases/:id/documents. Obtain from GET /api/v1/knowledge-bases//documents.
string
Optional rejection rationale (up to 2000 chars), persisted on the document’s moderation block.

Retry document indexing

Need this flow in Python, Go, Ruby, or PHP? The Worked sequences section renders this surface’s hero flows in the full six-language group.
POST /api/v1/knowledge-bases/{id}/documents/{docId}/retry
Re-queue a failed knowledge-base document for indexing. Use when a document upload reported an error indexing status and you fixed the underlying cause — the document’s chunks are re-extracted and re-indexed so the AI agent can retrieve them again. The retry is asynchronous: the endpoint returns 202 immediately with an empty body, and the document’s status transitions through pending to indexed (or back to error if it fails again) — poll GET /knowledge-bases/:id/documents for the outcome. Only failed documents are meaningfully retried. Requires an admin-class role and the knowledge:write scope; the call is audit-logged.
string
required
Knowledge base id, as returned by GET /knowledge-bases.
string
required
Document id within that knowledge base, as returned by GET /knowledge-bases/:id/documents. Obtain from GET /api/v1/knowledge-bases//documents.

Roll back a document to a prior version

POST /api/v1/knowledge-bases/{id}/documents/{docId}/rollback
Restore a document to an earlier snapshot. The target version’s content is re-uploaded as a new top version (the current head is snapshotted into history first), so the rollback is fully reversible. Returns 202 with the new document record while re-indexing runs asynchronously. Use the versions + diff endpoints to pick the version first. Requires the knowledge:write scope; the rollback is audit-logged.
string
required
Knowledge base id (kb_ prefixed).
string
required
Document id (kb_doc_ prefixed), as returned by GET /knowledge-bases/:id/documents. Obtain from GET /api/v1/knowledge-bases//documents.
number
required
1-based version number of the snapshot to restore. Coerced, so a JSON number or a numeric string both parse.

Trigger an immediate knowledge-base refresh

POST /api/v1/knowledge-bases/{id}/refresh
Start a manual refresh pass over every external-source document in the knowledge base — use after fixing connector auth, or when a source changed and waiting for the next scheduled tick is not an option. The pass runs asynchronously in the background worker, so the endpoint returns 202 immediately with the knowledge-base record; re-poll the knowledge base’s last_refresh_at to confirm completion. Requires the knowledge:write scope; the request is audit-logged.
string
required
Knowledge base id (kb_ prefixed).

Search a knowledge base

POST /api/v1/knowledge-bases/{id}/search
Retrieve the most relevant chunks across a knowledge base’s documents for a query — the retrieval hook an AI agent grounds its answers on, and the endpoint to debug what an agent would find. Accepts a standard session token or an internal service token (the agent-runtime calls it internally). Per-KB re-rank tuning comes from GET /knowledge-bases/:id/search-config.
string
required
Knowledge base id (kb_ prefixed).
string
required
The search query (1-1000 chars), e.g. “How long is the return window?”.
number
Maximum chunks to return, 1-20 (default 5). Coerced, so a JSON number or a numeric string both parse.

Update a knowledge base

PUT /api/v1/knowledge-bases/{id}
Update a knowledge base’s name, description, config, or refresh schedule. Every field is optional and omitted fields are left unchanged. Returns the updated knowledge base. Requires the knowledge:write scope; the update is audit-logged.
string
required
Knowledge base id (kb_ prefixed).
string
New display name (1-200 chars).
string
New free-form description (max 1000 chars).
object
Replacement key/value config map.
string (enum: manual|hourly|daily|weekly)
New refresh cadence for external-source documents.

Update knowledge-base search config

PUT /api/v1/knowledge-bases/{id}/search-config
Replace a knowledge base’s retrieval re-rank / relevance-boost config. Every field has a no-op default, so a PUT of {} resets the KB to legacy raw-similarity ordering and an omitted knob never silently changes the others. Values are range-clamped server-side. Returns the normalised config. Requires the knowledge:write scope (admin / owner / developer).
string
required
Knowledge base ID (kb_…).
any
Minimum raw vector similarity (0..1) a chunk must clear to reach the agent. 0 = no floor (default).
any
Recency multiplier strength (0..5). 0 = off (default); fresher docs get up to ×(1 + boost).
any
Half-life in days of the recency decay (1..3650). Default 30.
object
Map of source label → score multiplier (0..20, keys matched case-insensitively). Default .
string[]
Allow-list of categories; empty = allow all (default).
string[]
Deny-list of categories. Default [].

Update a knowledge-base connector

PATCH /api/v1/knowledge-bases/{id}/connectors/{connectorId}
Update a connector’s settings — connection id, display name, scope, sync schedule, enabled flag, or auto-refresh-on-drift. Every field is optional and at least one must be provided; omitted fields are left unchanged. Returns the updated connector. Requires the knowledge:write scope; the update is audit-logged.
string
required
Knowledge base id (kb_ prefixed).
string
required
Connector id (kbc_ prefixed), as returned by GET /knowledge-bases/:id/connectors. Obtain from GET /api/v1/knowledge-bases//connectors.
string (enum: notion|confluence|google_drive|sharepoint|zendesk)
External source provider the connector pulls from.
string
Connection id to pull from (max 200 chars). Optional on create — defaults to your organization id (the connection-id convention shared with the integrations catalog).
string
Human-readable label for the connector (1-200 chars). On update, null clears it.
object
Which slice of the source to pull: space_keys, folder_ids, collection_ids, labels (all optional; empty = everything the connection can see).
string (enum: manual|hourly|daily|weekly)
How often the source is re-pulled (default daily; manual syncs only on demand).
boolean
Pause (false) or resume (true) scheduled syncs. Default true.
boolean
When true, a detected source content drift auto-queues a resync; when false (default), drift only appears in the drift report.

Update document help-center publication

PATCH /api/v1/knowledge-bases/{id}/documents/{docId}/publication
Toggle whether a document is exposed on the public help center (is_public), or rename its public slug / summary. The partial PATCH body avoids re-stating a slug that isn’t being renamed. Setting is_public=true exposes the content to the open web — every flip is audit-logged. Requires the knowledge:write scope (admin / owner / developer).
string
required
Knowledge base id (kb_ prefixed).
string
required
Document id (kb_doc_ prefixed), as returned by GET /knowledge-bases/:id/documents. Obtain from GET /api/v1/knowledge-bases//documents.
boolean
required
Set true to expose the document on the public help center; false hides it.
string
Public URL segment for the help-center page (lowercase letters, digits, hyphens; max 200 chars).
string
Optional public summary shown on the help-center page (max 2000 chars).

Delete a knowledge base

DELETE /api/v1/knowledge-bases/{id}
Permanently remove a knowledge base and all of its documents: its chunks are dropped from retrieval, so AI agents can no longer answer from this collection. Responds 204 No Content with an empty body. Requires the knowledge:write scope; the deletion is audit-logged.
string
required
Knowledge base id (kb_ prefixed).
Response: 204 No Content

Delete a knowledge-base connector

DELETE /api/v1/knowledge-bases/{id}/connectors/{connectorId}
Remove a sync connector from a knowledge base. Documents already pulled from the source stay in the knowledge base; only the live sync binding is dropped. Responds 204 No Content with an empty body. Requires the knowledge:write scope; the deletion is audit-logged.
string
required
Knowledge base id (kb_ prefixed).
string
required
Connector id (kbc_ prefixed), as returned by GET /knowledge-bases/:id/connectors. Obtain from GET /api/v1/knowledge-bases//connectors.
Response: 204 No Content

Delete a knowledge-base document

DELETE /api/v1/knowledge-bases/{id}/documents/{docId}
Permanently remove a document from a knowledge base: its chunks are dropped from retrieval, so AI agents can no longer answer from its content. Responds 204 No Content with an empty body. To correct content rather than remove it, roll back to an earlier version or re-upload. Requires the knowledge:write scope; the deletion is audit-logged.
string
required
Knowledge base id (kb_ prefixed).
string
required
Document id (kb_doc_ prefixed), as returned by GET /knowledge-bases/:id/documents. Obtain from GET /api/v1/knowledge-bases//documents.
Response: 204 No Content