Knowledge

Upload documents, add and sync knowledge sources such as your website or questions and answers, attach them to agents, search them, and ask an agent's knowledge a question. Requires `knowledge:read` to read and `knowledge:write` for everything else.

List knowledge sources
GET /knowledge/sources
Add a knowledge source
POST /knowledge/sources
Delete several knowledge sources
POST /knowledge/sources/bulk-delete
Get a knowledge source
GET /knowledge/sources/{id}
Update a knowledge source
PATCH /knowledge/sources/{id}
Delete a knowledge source
DEL /knowledge/sources/{id}
List a source's documents
GET /knowledge/sources/{id}/documents
Crawl a website source now
POST /knowledge/sources/{id}/sync
Retry a source's failed documents
POST /knowledge/sources/{id}/retry
Give an agent access to a source
POST /knowledge/sources/{id}/assistants/{assistantId}
Take a source away from an agent
DEL /knowledge/sources/{id}/assistants/{assistantId}
List documents
GET /knowledge/documents
Upload a document
POST /knowledge/documents
Search knowledge
GET /knowledge/search
Get a document
GET /knowledge/documents/{id}
Edit a document
PATCH /knowledge/documents/{id}
Delete a document
DEL /knowledge/documents/{id}
List a document's passages
GET /knowledge/documents/{id}/chunks
Reprocess a document
POST /knowledge/documents/{id}/retry
Get a document's stored text
GET /knowledge/documents/{id}/content
Download a document's file
GET /knowledge/documents/{id}/file
Preview a document as text
GET /knowledge/documents/{id}/preview
Rebuild the search index
POST /knowledge/reindex
Ask what an agent knows
POST /assistants/{id}/knowledge/ask

The Knowledge object

Returned by the knowledge endpoints.

Attributes
deletedinteger
How many sources were deleted.
removedinteger
How many were only removed from the given agent.
failedarray<string>
Names of the sources that couldn't be deleted. `null` when none failed.
The Knowledge object
{
  "deleted": 2,
  "removed": 0,
  "failed": null
}

List knowledge sources

GET https://api.trycareflow.com/knowledge/sources

Requires `knowledge:read`. Returns every knowledge source in the workspace, in no particular order and without paging. Pass `assistantId` to see only what that agent can search: sources shared with every agent plus those granted to it by name. Each is then labelled with `grantedVia`. `type` and `scope` are ignored when `assistantId` is set.

Query parameters
typeenumoptional
Only sources of this type. Ignored with `assistantId`.uploadwebsitesnippetqa
scopeenumoptional
Only sources with this scope. Ignored with `assistantId`.all_agentsselected
assistantIdstringoptional
Only the sources this agent can search.
curl https://api.trycareflow.com/knowledge/sources \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.list()
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "sources": [
      {
        "_id": "6710a1b2c3d4e5f6a7b8c901",
        "createdAt": "2026-10-01T09:30:00Z",
        "updatedAt": "2026-10-01T09:34:12Z",
        "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
        "type": "website",
        "name": "harbourviewhotel.example.com",
        "scope": "all_agents",
        "status": "ready",
        "docCount": 24,
        "chunkCount": 187,
        "sync": {
          "rootUrl": "https://harbourviewhotel.example.com",
          "maxDepth": 2,
          "maxPages": 50,
          "excludePaths": [
            "/blog"
          ],
          "frequency": "weekly",
          "lastRunAt": "2026-10-01T09:33:40Z"
        },
        "createdBy": "66f1c2a9e4b0f1a2b3c4d5ff",
        "assistantCount": -1
      },
      {
        "_id": "6710a1b2c3d4e5f6a7b8c902",
        "createdAt": "2026-10-01T11:00:00Z",
        "updatedAt": "2026-10-01T11:00:41Z",
        "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
        "type": "upload",
        "name": "room-service-menu.pdf",
        "scope": "selected",
        "assistantIds": [
          "66f1c2a9e4b0f1a2b3c4d5e6",
          "66f1c2a9e4b0f1a2b3c4d5e7"
        ],
        "status": "ready",
        "docCount": 1,
        "chunkCount": 12,
        "createdBy": "66f1c2a9e4b0f1a2b3c4d5ff",
        "assistantCount": 2
      }
    ]
  }
}
{
  "code": "ERROR",
  "message": "invalid assistantId",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "assistant not found",
  "error": "no such assistant in this workspace"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to list sources",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Add a knowledge source

POST https://api.trycareflow.com/knowledge/sources

Requires `knowledge:write`. Adds content for your agents to search. Send JSON to add a website to crawl (`website`), a text note (`snippet`) or a question with its answer (`qa`). Send `multipart/form-data` with a `file` to upload a document instead; that works exactly like `POST /knowledge/documents`. Notes and Q&A entries don't each become a source. They are added as documents to one shared source per type: "Notes" for snippets and "Q&A snippets" for Q&A, one for the whole workspace plus one per agent when you pass `assistantId`. The response returns that source and the new `document`. A website source starts crawling straight away and the response has only `source`. Processing happens in the background. Poll `GET /knowledge/documents/{id}` (for a note, Q&A or file) or `GET /knowledge/sources/{id}` (for a website) until `status` is `ready` or `failed`.

Parameters
typeenumrequired
`website` crawls a site; `snippet` adds a text note; `qa` adds a question and answer. Spaces around it are trimmed. `upload` is refused here: send a file as `multipart/form-data` instead.websitesnippetqa
namestringoptional
For `website`, the source name (default: the address without `https://` and trailing slash). For `snippet` and `qa`, the title of the entry (default: the `question`, then the first 60 characters of `content`).
contentstringoptional
The text of a `snippet`, or the answer of a `qa`. Required for those types and can't be blank. Ignored for `website`.
questionstringoptional
The question a `qa` entry answers. When set, the entry is stored as "Q: ... A: ..." so searches match either part.
assistantIdstringoptional
Make the new content available to this agent only. Leave it out to share it with every agent.
syncobjectoptional
Crawl settings. Required for `website`; ignored otherwise.
curl https://api.trycareflow.com/knowledge/sources \
  -H "Authorization: Bearer sk_live_••••" \
  -d type=qa \
  -d name=Early check-in \
  -d content=Early check-in from 11am is possible when your room is ready. Ask at reception or message us on the day. \
  -d question=Can I check in early?
const Knowledge = await careflow.knowledge.create({
  type: 'qa',
  name: 'Early check-in',
  content: 'Early check-in from 11am is possible when your room is ready. Ask at reception or message us on the day.',
  question: 'Can I check in early?',
})
Response
{
  "code": "SUCCESS",
  "message": "created",
  "data": {
    "source": {
      "_id": "6710a1b2c3d4e5f6a7b8c901",
      "createdAt": "2026-10-01T09:30:00Z",
      "updatedAt": "2026-10-01T09:34:12Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "type": "website",
      "name": "harbourviewhotel.example.com",
      "scope": "all_agents",
      "assistantIds": [
        "66f1c2a9e4b0f1a2b3c4d5e6"
      ],
      "status": "ready",
      "docCount": 24,
      "chunkCount": 187,
      "error": "no pages could be fetched from https://harbourviewhotel.example.com",
      "widgetPublished": false,
      "sync": {
        "rootUrl": "https://harbourviewhotel.example.com",
        "maxDepth": 2,
        "includePaths": [
          "/rooms",
          "/dining"
        ],
        "excludePaths": [
          "/blog"
        ],
        "maxPages": 50,
        "frequency": "weekly",
        "lastRunAt": "2026-10-01T09:33:40Z",
        "lastError": "page limit reached — 50 pages stored, increase max pages to crawl deeper"
      },
      "createdBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "grantedVia": "direct",
      "assistantCount": -1
    },
    "document": {
      "_id": "6710a1b2c3d4e5f6a7b8d001",
      "createdAt": "2026-10-01T11:00:00Z",
      "updatedAt": "2026-10-01T11:00:41Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "sourceId": "6710a1b2c3d4e5f6a7b8c902",
      "fileName": "room-service-menu.pdf",
      "fileType": "pdf",
      "fileSize": 482113,
      "sourceUrl": "https://harbourviewhotel.example.com/dining",
      "status": "ready",
      "chunkCount": 12,
      "uploadedBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "error": "no text could be extracted from this file",
      "progress": 60,
      "processAttempts": 1,
      "filePath": "6710a1b2c3d4e5f6a7b8f001"
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid body",
  "error": "<JSON decoding error>"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "assistant not found",
  "error": "no such assistant in this workspace"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "processing could not be scheduled",
  "error": "the entry was saved but its processing job could not be queued — retry from the source row"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Delete several knowledge sources

POST https://api.trycareflow.com/knowledge/sources/bulk-delete

Requires `knowledge:write`. Deletes up to 200 sources and everything in them in one call, the same way as deleting each one. With `assistantId`, a source limited to selected agents that other agents still use is only taken away from that agent (counted in `removed`) instead of deleted. Sources that fail are listed by name in `failed`; IDs that don't exist in your workspace are skipped without a mention.

Parameters
sourceIdsarray<string>required
The sources to delete, 1 to 200. IDs from another workspace are skipped silently.
assistantIdstringoptional
Optional. When set, a source that is limited to selected agents and still used by other agents is only removed from this agent instead of deleted.
curl https://api.trycareflow.com/knowledge/sources/bulk-delete \
  -H "Authorization: Bearer sk_live_••••" \
  -d sourceIds=6710a1b2c3d4e5f6a7b8c902,6710a1b2c3d4e5f6a7b8c903 \
  -d assistantId=66f1c2a9e4b0f1a2b3c4d5e6
const Knowledge = await careflow.knowledge.create({
  sourceIds: '6710a1b2c3d4e5f6a7b8c902,6710a1b2c3d4e5f6a7b8c903',
  assistantId: '66f1c2a9e4b0f1a2b3c4d5e6',
})
Response
{
  "code": "SUCCESS",
  "message": "done",
  "data": {
    "deleted": 2,
    "removed": 0,
    "failed": null
  }
}
{
  "code": "ERROR",
  "message": "sourceIds required",
  "error": "send at least one source id"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "assistant not found",
  "error": "no such assistant in this workspace"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to load sources",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Get a knowledge source

GET https://api.trycareflow.com/knowledge/sources/{id}

Requires `knowledge:read`. Returns one source with its status and counts. Poll this after creating or syncing a website: the crawl is done when `sync.lastRunAt` moves on, and the pages are searchable once `status` is `ready`.

Path parameters
idstringrequired
The knowledge source's ID.
curl https://api.trycareflow.com/knowledge/sources/value \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.retrieve('value')
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "source": {
      "_id": "6710a1b2c3d4e5f6a7b8c901",
      "createdAt": "2026-10-01T09:30:00Z",
      "updatedAt": "2026-10-01T09:34:12Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "type": "website",
      "name": "harbourviewhotel.example.com",
      "scope": "all_agents",
      "status": "ready",
      "docCount": 24,
      "chunkCount": 187,
      "sync": {
        "rootUrl": "https://harbourviewhotel.example.com",
        "maxDepth": 2,
        "maxPages": 50,
        "excludePaths": [
          "/blog"
        ],
        "frequency": "weekly",
        "lastRunAt": "2026-10-01T09:33:40Z"
      },
      "createdBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "assistantCount": -1
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "no such knowledge source"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Update a knowledge source

PATCH https://api.trycareflow.com/knowledge/sources/{id}

Requires `knowledge:write`. Renames a source, changes which agents can search it, changes a website's crawl settings, or shows it in your web widget's Help section. `assistantIds` replaces the whole list; to add or remove one agent without touching the others, use the grant and revoke endpoints. Setting `scope` to `all_agents` clears the list. New crawl settings take effect on the next crawl; call the sync endpoint to crawl now.

Path parameters
idstringrequired
The knowledge source's ID.
Parameters
namestringoptional
A new name. Can't be blank.
scopeenumoptional
`all_agents` shares it with every agent and clears `assistantIds`. `selected` limits it to `assistantIds`.all_agentsselected
assistantIdsarray<string>optional
The full list of agents that may search it. Replaces the current list. Sending it without `scope` also switches the scope to `selected`. Every ID must be an agent in this workspace.
syncobjectoptional
New crawl settings. Website sources only. Saving them doesn't start a crawl.
widgetPublishedbooleanoptional
`true` shows this source publicly as a Help article in your web widget.
curl -X PATCH https://api.trycareflow.com/knowledge/sources/value \
  -H "Authorization: Bearer sk_live_••••" \
  -d name=Harbourview website \
  -d scope=selected \
  -d assistantIds=66f1c2a9e4b0f1a2b3c4d5e6,66f1c2a9e4b0f1a2b3c4d5e7 \
  -d sync=value
const Knowledge = await careflow.knowledge.update({
  name: 'Harbourview website',
  scope: 'selected',
  assistantIds: '66f1c2a9e4b0f1a2b3c4d5e6,66f1c2a9e4b0f1a2b3c4d5e7',
  sync: 'value',
})
Response
{
  "code": "SUCCESS",
  "message": "updated",
  "data": {
    "source": {
      "_id": "6710a1b2c3d4e5f6a7b8c902",
      "createdAt": "2026-10-01T11:00:00Z",
      "updatedAt": "2026-10-01T11:00:41Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "type": "upload",
      "name": "room-service-menu.pdf",
      "scope": "selected",
      "assistantIds": [
        "66f1c2a9e4b0f1a2b3c4d5e6",
        "66f1c2a9e4b0f1a2b3c4d5e7"
      ],
      "status": "ready",
      "docCount": 1,
      "chunkCount": 12,
      "createdBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "assistantCount": 2
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "no such knowledge source"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to update",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Delete a knowledge source

DEL https://api.trycareflow.com/knowledge/sources/{id}

Requires `knowledge:write`. Deletes a source with all its documents, passages and stored files. Agents stop finding its content straight away. This can't be undone. To stop one agent using a source but keep it for others, revoke that agent instead. The response has no `data`.

Path parameters
idstringrequired
The knowledge source's ID.
curl -X DELETE https://api.trycareflow.com/knowledge/sources/value \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.del('value')
Response
{
  "code": "SUCCESS",
  "message": "deleted"
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "no such knowledge source"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to delete source",
  "error": "load documents: <database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

List a source's documents

GET https://api.trycareflow.com/knowledge/sources/{id}/documents

Requires `knowledge:read`. Returns every document in a source: the uploaded file, each note or Q&A entry, or each crawled page. Use it to check which items are still `processing` or `failed`.

Path parameters
idstringrequired
The knowledge source's ID.
curl https://api.trycareflow.com/knowledge/sources/value/documents \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.retrieve('value')
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "documents": [
      {
        "_id": "6710a1b2c3d4e5f6a7b8d003",
        "createdAt": "2026-10-01T09:31:02Z",
        "updatedAt": "2026-10-01T09:31:30Z",
        "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
        "sourceId": "6710a1b2c3d4e5f6a7b8c901",
        "fileName": "harbourviewhotel.example.com/dining",
        "fileType": "html",
        "fileSize": 0,
        "sourceUrl": "https://harbourviewhotel.example.com/dining",
        "status": "ready",
        "chunkCount": 6,
        "uploadedBy": "66f1c2a9e4b0f1a2b3c4d5ff",
        "filePath": "6710a1b2c3d4e5f6a7b8f003"
      }
    ]
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "no such knowledge source"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to list documents",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Crawl a website source now

POST https://api.trycareflow.com/knowledge/sources/{id}/sync

Requires `knowledge:write`. Starts a fresh crawl of a website source. Only `website` sources can be synced; files, notes and Q&A are updated by editing or re-uploading them. The crawl runs in the background. Pages it finds are added or refreshed, and pages that have gone from the site are removed. The returned `source` shows the state before the crawl. Note the current `sync.lastRunAt`, then poll `GET /knowledge/sources/{id}` until it changes; after that `status` is `processing` while the pages are indexed, then `ready` (or `failed`, with the reason in `error`). Check `sync.lastError` for pages that were skipped or a page limit that was hit.

Path parameters
idstringrequired
The knowledge source's ID.
curl https://api.trycareflow.com/knowledge/sources/value/sync \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.create('value')
Response
{
  "code": "SUCCESS",
  "message": "queued",
  "data": {
    "source": {
      "_id": "6710a1b2c3d4e5f6a7b8c901",
      "createdAt": "2026-10-01T09:30:00Z",
      "updatedAt": "2026-10-01T09:34:12Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "type": "website",
      "name": "harbourviewhotel.example.com",
      "scope": "all_agents",
      "status": "ready",
      "docCount": 24,
      "chunkCount": 187,
      "sync": {
        "rootUrl": "https://harbourviewhotel.example.com",
        "maxDepth": 2,
        "maxPages": 50,
        "excludePaths": [
          "/blog"
        ],
        "frequency": "weekly",
        "lastRunAt": "2026-10-01T09:33:40Z"
      },
      "createdBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "assistantCount": -1
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "no such knowledge source"
}
{
  "code": "ERROR",
  "message": "sync already running",
  "error": "this source is currently being crawled"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to enqueue crawl",
  "error": "<queue error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Retry a source's failed documents

POST https://api.trycareflow.com/knowledge/sources/{id}/retry

Requires `knowledge:write`. Puts every document in the source that `failed`, or that has been `processing` for more than 10 minutes, back in the processing queue. Documents are spaced 2 seconds apart. It succeeds with `retried: 0` when there was nothing to retry. To crawl a website again, use the sync endpoint instead.

Path parameters
idstringrequired
The knowledge source's ID.
curl https://api.trycareflow.com/knowledge/sources/value/retry \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.create('value')
Response
{
  "code": "SUCCESS",
  "message": "retrying",
  "data": {
    "retried": 3,
    "failed": 0
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "no such knowledge source"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "processing could not be scheduled",
  "error": "please try again"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Give an agent access to a source

POST https://api.trycareflow.com/knowledge/sources/{id}/assistants/{assistantId}

Requires `knowledge:write`. Adds one agent to the agents that can search a source limited to selected agents. Other agents already on the list keep their access. A source shared with every agent (`scope: all_agents`) is left unchanged and the call succeeds with the message `already available to every agent`. To limit such a source to certain agents, update it with `scope: selected` and `assistantIds`.

Path parameters
idstringrequired
The knowledge source's ID.
assistantIdstringrequired
The ID of an agent in the same workspace.
curl https://api.trycareflow.com/knowledge/sources/value/assistants/value \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.create('value')
Response
{
  "code": "SUCCESS",
  "message": "granted",
  "data": {
    "source": {
      "_id": "6710a1b2c3d4e5f6a7b8c902",
      "createdAt": "2026-10-01T11:00:00Z",
      "updatedAt": "2026-10-01T11:00:41Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "type": "upload",
      "name": "room-service-menu.pdf",
      "scope": "selected",
      "assistantIds": [
        "66f1c2a9e4b0f1a2b3c4d5e6",
        "66f1c2a9e4b0f1a2b3c4d5e7"
      ],
      "status": "ready",
      "docCount": 1,
      "chunkCount": 12,
      "createdBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "assistantCount": 2
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "no such knowledge source"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to grant",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Take a source away from an agent

DEL https://api.trycareflow.com/knowledge/sources/{id}/assistants/{assistantId}

Requires `knowledge:write`. Stops one agent searching a source. The source and its content stay, and other agents keep their access. This only works on sources limited to selected agents. For a source shared with every agent it fails with 409; set its scope to `selected` with the agents that should keep it instead.

Path parameters
idstringrequired
The knowledge source's ID.
assistantIdstringrequired
The ID of an agent in the same workspace.
curl -X DELETE https://api.trycareflow.com/knowledge/sources/value/assistants/value \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.del('value')
Response
{
  "code": "SUCCESS",
  "message": "revoked",
  "data": {
    "source": {
      "_id": "6710a1b2c3d4e5f6a7b8c902",
      "createdAt": "2026-10-01T11:00:00Z",
      "updatedAt": "2026-10-01T11:00:41Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "type": "upload",
      "name": "room-service-menu.pdf",
      "scope": "selected",
      "assistantIds": [
        "66f1c2a9e4b0f1a2b3c4d5e7"
      ],
      "status": "ready",
      "docCount": 1,
      "chunkCount": 12,
      "createdBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "assistantCount": 1
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "no such knowledge source"
}
{
  "code": "ERROR",
  "message": "source is shared with every agent",
  "error": "narrow its scope to 'selected' first, then grant the agents that should keep it"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to revoke",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

List documents

GET https://api.trycareflow.com/knowledge/documents

Requires `knowledge:read`. Returns every document in the workspace across all sources, in no particular order and without paging. Crawled websites can add hundreds of pages, so filter where you can.

Query parameters
statusenumoptional
Only documents with this status.processingreadyfailed
searchstringoptional
Only documents whose name contains this text, ignoring case. It's read as a regular expression, so escape characters like `.` and `(`.
curl https://api.trycareflow.com/knowledge/documents \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.list()
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "documents": [
      {
        "_id": "6710a1b2c3d4e5f6a7b8d001",
        "createdAt": "2026-10-01T11:00:00Z",
        "updatedAt": "2026-10-01T11:00:41Z",
        "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
        "sourceId": "6710a1b2c3d4e5f6a7b8c902",
        "fileName": "room-service-menu.pdf",
        "fileType": "pdf",
        "fileSize": 482113,
        "status": "ready",
        "chunkCount": 12,
        "uploadedBy": "66f1c2a9e4b0f1a2b3c4d5ff",
        "filePath": "6710a1b2c3d4e5f6a7b8f001"
      },
      {
        "_id": "6710a1b2c3d4e5f6a7b8d002",
        "createdAt": "2026-10-01T10:00:00Z",
        "updatedAt": "2026-10-01T10:00:00Z",
        "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
        "sourceId": "6710a1b2c3d4e5f6a7b8c903",
        "fileName": "Can I check in early?",
        "fileType": "md",
        "fileSize": 112,
        "status": "processing",
        "chunkCount": 0,
        "uploadedBy": "66f1c2a9e4b0f1a2b3c4d5ff",
        "filePath": "6710a1b2c3d4e5f6a7b8f002"
      }
    ]
  }
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to list",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Upload a document

POST https://api.trycareflow.com/knowledge/documents

Requires `knowledge:write`. Uploads one file as `multipart/form-data` with the field `file`. Accepted: PDF, Word (`.docx`), CSV, plain text and Markdown, judged by the file name's extension. Careflow doesn't set a size limit, but the upload must finish within 5 minutes; very large files may take long to process or fail. Each upload creates a new `upload` source holding one document, shared with every agent unless you send `assistantId`. Uploading the same file again creates a second source; to replace a file, delete the old source. Processing runs in the background. Poll `GET /knowledge/documents/{id}` with the returned document ID until `status` is `ready` or `failed`.

curl -X POST https://api.trycareflow.com/knowledge/documents \
  -H "Authorization: Bearer sk_live_xxx" \
  -F "file=@room-service-menu.pdf"
import { readFile } from "node:fs/promises";

const form = new FormData();
form.append("file", new Blob([await readFile("room-service-menu.pdf")]), "room-service-menu.pdf");

const res = await fetch("https://api.trycareflow.com/knowledge/documents", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.CAREFLOW_API_KEY}` },
  body: form,
});
const { data } = await res.json();
Response
{
  "code": "SUCCESS",
  "message": "uploaded",
  "data": {
    "document": {
      "_id": "6710a1b2c3d4e5f6a7b8d001",
      "createdAt": "2026-10-01T11:00:00Z",
      "updatedAt": "2026-10-01T11:00:00Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "sourceId": "6710a1b2c3d4e5f6a7b8c902",
      "fileName": "room-service-menu.pdf",
      "fileType": "pdf",
      "fileSize": 482113,
      "status": "processing",
      "chunkCount": 0,
      "uploadedBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "filePath": "6710a1b2c3d4e5f6a7b8f001"
    },
    "source": {
      "_id": "6710a1b2c3d4e5f6a7b8c902",
      "createdAt": "2026-10-01T11:00:00Z",
      "updatedAt": "2026-10-01T11:00:00Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "type": "upload",
      "name": "room-service-menu.pdf",
      "scope": "selected",
      "assistantIds": [
        "66f1c2a9e4b0f1a2b3c4d5e6"
      ],
      "status": "processing",
      "docCount": 1,
      "chunkCount": 0,
      "createdBy": "66f1c2a9e4b0f1a2b3c4d5ff"
    }
  }
}
{
  "code": "ERROR",
  "message": "file required",
  "error": "http: no such file"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "processing could not be scheduled",
  "error": "the file was uploaded but its processing job could not be queued — retry from the document row"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Search knowledge

GET https://api.trycareflow.com/knowledge/search

Requires `knowledge:read`. Finds the 5 passages that best match a query across every document in the workspace, whichever agents they're shared with. Pass `documentId` to search one document. To see what a particular agent would find and say, use `POST /assistants/{id}/knowledge/ask` instead.

Query parameters
querystringrequired
What to search for, in plain words.
documentIdstringoptional
Search only this document.
curl https://api.trycareflow.com/knowledge/search?query=value \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.list({ query: 'value' })
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "chunks": [
      {
        "_id": "6710a1b2c3d4e5f6a7b8e001",
        "createdAt": "2026-10-01T11:00:40Z",
        "updatedAt": "2026-10-01T11:00:40Z",
        "documentId": "6710a1b2c3d4e5f6a7b8d001",
        "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
        "content": "Room service runs from 6am to midnight. Breakfast trays ordered by 10pm the night before arrive within a 15-minute window you choose.",
        "chunkIndex": 0,
        "metadata": {
          "fileName": "room-service-menu.pdf",
          "fileType": "pdf"
        },
        "score": 0.83
      }
    ]
  }
}
{
  "code": "ERROR",
  "message": "query required",
  "error": "query parameter missing"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "embedding failed",
  "error": "<provider error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Get a document

GET https://api.trycareflow.com/knowledge/documents/{id}

Requires `knowledge:read`. Returns one document. Poll this after an upload or a new note or Q&A entry: it's searchable when `status` is `ready`. On `failed`, `error` says why; fix the cause and call the retry endpoint.

Path parameters
idstringrequired
The document's ID.
curl https://api.trycareflow.com/knowledge/documents/value \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.retrieve('value')
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "document": {
      "_id": "6710a1b2c3d4e5f6a7b8d001",
      "createdAt": "2026-10-01T11:00:00Z",
      "updatedAt": "2026-10-01T11:00:41Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "sourceId": "6710a1b2c3d4e5f6a7b8c902",
      "fileName": "room-service-menu.pdf",
      "fileType": "pdf",
      "fileSize": 482113,
      "status": "ready",
      "chunkCount": 12,
      "uploadedBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "filePath": "6710a1b2c3d4e5f6a7b8f001"
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "mongo: no documents in result"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Edit a document

PATCH https://api.trycareflow.com/knowledge/documents/{id}

Requires `knowledge:write`. Changes a note or Q&A entry's title, text or both. New `content` replaces the whole stored text (for a Q&A entry, include the question in it if you want it kept), and the document returns to `processing` while it's indexed again. Use this for notes and Q&A only. Sending `content` for an uploaded PDF, Word or CSV file breaks it, because the text is stored under the original file type; upload a new file instead. A crawled page is overwritten on the next crawl.

Path parameters
idstringrequired
The document's ID.
Parameters
namestringoptional
A new title. Can't be blank.
contentstringoptional
New text that replaces the whole body. Can't be blank. The document goes back to `processing` and is indexed again.
curl -X PATCH https://api.trycareflow.com/knowledge/documents/value \
  -H "Authorization: Bearer sk_live_••••" \
  -d name=Early check-in \
  -d content=Early check-in from 10am is possible when your room is ready.
const Knowledge = await careflow.knowledge.update({
  name: 'Early check-in',
  content: 'Early check-in from 10am is possible when your room is ready.',
})
Response
{
  "code": "SUCCESS",
  "message": "updated",
  "data": {
    "document": {
      "_id": "6710a1b2c3d4e5f6a7b8d002",
      "createdAt": "2026-10-01T10:00:00Z",
      "updatedAt": "2026-10-02T08:15:00Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "sourceId": "6710a1b2c3d4e5f6a7b8c903",
      "fileName": "Can I check in early?",
      "fileType": "md",
      "fileSize": 86,
      "status": "processing",
      "chunkCount": 0,
      "uploadedBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "filePath": "6710a1b2c3d4e5f6a7b8f002"
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "mongo: no documents in result"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to store content",
  "error": "<storage error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Delete a document

DEL https://api.trycareflow.com/knowledge/documents/{id}

Requires `knowledge:write`. Deletes one document with its passages and stored file. If it was the last document in its source, the source is deleted too. A crawled page comes back on the next crawl if it's still on the site; to drop pages for good, add them to the source's `excludePaths`. The response has no `data`.

Path parameters
idstringrequired
The document's ID.
curl -X DELETE https://api.trycareflow.com/knowledge/documents/value \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.del('value')
Response
{
  "code": "SUCCESS",
  "message": "deleted"
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "mongo: no documents in result"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to delete",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

List a document's passages

GET https://api.trycareflow.com/knowledge/documents/{id}/chunks

Requires `knowledge:read`. Returns the passages a document was split into, in order, without their search vectors. Useful to check what an agent can actually read from a file. Empty until the document is `ready`.

Path parameters
idstringrequired
The document's ID.
curl https://api.trycareflow.com/knowledge/documents/value/chunks \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.retrieve('value')
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "chunks": [
      {
        "_id": "6710a1b2c3d4e5f6a7b8e001",
        "createdAt": "2026-10-01T11:00:40Z",
        "updatedAt": "2026-10-01T11:00:40Z",
        "documentId": "6710a1b2c3d4e5f6a7b8d001",
        "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
        "content": "Room service runs from 6am to midnight. Breakfast trays ordered by 10pm the night before arrive within a 15-minute window you choose.",
        "chunkIndex": 0,
        "metadata": {
          "fileName": "room-service-menu.pdf",
          "fileType": "pdf"
        }
      }
    ]
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "document not found",
  "error": "mongo: no documents in result"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to list chunks",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Reprocess a document

POST https://api.trycareflow.com/knowledge/documents/{id}/retry

Requires `knowledge:write`. Puts a document back in the processing queue and sets it to `processing`. Use it on a `failed` document after fixing the cause, or on a `ready` one to index it again.

Path parameters
idstringrequired
The document's ID.
curl https://api.trycareflow.com/knowledge/documents/value/retry \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.create('value')
Response
{
  "code": "SUCCESS",
  "message": "retrying",
  "data": {
    "document": {
      "_id": "6710a1b2c3d4e5f6a7b8d001",
      "createdAt": "2026-10-01T11:00:00Z",
      "updatedAt": "2026-10-02T08:20:00Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "sourceId": "6710a1b2c3d4e5f6a7b8c902",
      "fileName": "room-service-menu.pdf",
      "fileType": "pdf",
      "fileSize": 482113,
      "status": "processing",
      "chunkCount": 0,
      "uploadedBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "filePath": "6710a1b2c3d4e5f6a7b8f001"
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "mongo: no documents in result"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "processing could not be scheduled",
  "error": "please try again"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Get a document's stored text

GET https://api.trycareflow.com/knowledge/documents/{id}/content

Requires `knowledge:read`. Returns exactly what's stored for a document, as a string, together with the document. This is the way to load a note or Q&A entry for editing, and it works for plain-text, Markdown and crawled pages too. For PDF, Word and CSV files `content` is the raw file bytes and isn't readable; use the preview endpoint for their text, or the file endpoint for the original.

Path parameters
idstringrequired
The document's ID.
curl https://api.trycareflow.com/knowledge/documents/value/content \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.retrieve('value')
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "content": "Q: Can I check in early?

A: Early check-in from 11am is possible when your room is ready.",
    "document": {
      "_id": "6710a1b2c3d4e5f6a7b8d002",
      "createdAt": "2026-10-01T10:00:00Z",
      "updatedAt": "2026-10-01T10:00:00Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d5e0",
      "sourceId": "6710a1b2c3d4e5f6a7b8c903",
      "fileName": "Can I check in early?",
      "fileType": "md",
      "fileSize": 112,
      "status": "ready",
      "chunkCount": 1,
      "uploadedBy": "66f1c2a9e4b0f1a2b3c4d5ff",
      "filePath": "6710a1b2c3d4e5f6a7b8f002"
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "mongo: no documents in result"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to read content",
  "error": "<storage error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Download a document's file

GET https://api.trycareflow.com/knowledge/documents/{id}/file

Requires `knowledge:read`. Downloads the stored file as an attachment, not JSON. Uploads come back in their original format. Notes and Q&A entries come back as Markdown, and crawled pages as plain text (`.txt`) of the extracted page text. The file name is in `Content-Disposition`, with the right extension added if it was missing. Errors are still JSON.

Path parameters
idstringrequired
The document's ID.
curl https://api.trycareflow.com/knowledge/documents/value/file \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.retrieve('value')
Response
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "mongo: no documents in result"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to read file",
  "error": "<storage error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Preview a document as text

GET https://api.trycareflow.com/knowledge/documents/{id}/preview

Requires `knowledge:read`. Returns a document's readable text as Markdown, for any file type. PDF, Word and CSV files give the text Careflow extracted while processing; text files, notes, Q&A and crawled pages give their stored text. If neither is available, the text is pieced together from the document's passages. The preview stops at 2 MB (2,097,152 bytes); `truncated` tells you when it was cut.

Path parameters
idstringrequired
The document's ID.
curl https://api.trycareflow.com/knowledge/documents/value/preview \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.retrieve('value')
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "markdown": "# Room service

Room service runs from 6am to midnight.",
    "origin": "extracted",
    "truncated": false
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "mongo: no documents in result"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to build preview",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Rebuild the search index

POST https://api.trycareflow.com/knowledge/reindex

Requires `knowledge:write`. Recomputes the search vectors of every passage in the workspace. You only need this if Careflow support asks you to, for example after a change of search model; normal uploads, edits and syncs index themselves. It runs while you wait and stops at the first error, leaving earlier documents done. On a large workspace it can outlast the server's 30-second response limit, in which case the connection closes before you get a reply while the work may carry on.

curl https://api.trycareflow.com/knowledge/reindex \
  -H "Authorization: Bearer sk_live_••••"
const Knowledge = await careflow.knowledge.create()
Response
{
  "code": "SUCCESS",
  "message": "reindexed",
  "data": {
    "documents": 42,
    "chunks": 1310
  }
}
{
  "code": "ERROR",
  "message": "invalid businessId",
  "error": "<id error>"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "failed to list documents",
  "error": "<database error>"
}
{
  "code": "ERROR",
  "message": "embedding failed for <file name>",
  "error": "<provider error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Ask what an agent knows

POST https://api.trycareflow.com/assistants/{id}/knowledge/ask

Requires `knowledge:write`. Answers a question using only the knowledge this agent can search, and shows the passages it used. It's a quick check that an agent will find the right information, without starting a conversation, using playbooks or calling tools. An empty `answer` means the agent's knowledge doesn't cover the question. Only documents that are `ready` and in sources shared with this agent are searched. Even though it only reads, it needs `knowledge:write` because it's a POST.

Path parameters
idstringrequired
The agent's ID.
Parameters
questionstringrequired
The question, as a customer would ask it. Can't be blank.
curl https://api.trycareflow.com/assistants/value/knowledge/ask \
  -H "Authorization: Bearer sk_live_••••" \
  -d question=Can I check in before 2pm?
const Knowledge = await careflow.knowledge.create({
  question: 'Can I check in before 2pm?',
})
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "answer": "Yes, early check-in from 11am is possible when your room is ready.",
    "sources": [
      {
        "name": "Can I check in early?",
        "documentId": "6710a1b2c3d4e5f6a7b8d002",
        "excerpt": "Q: Can I check in early? A: Early check-in from 11am is possible when your room is ready."
      }
    ]
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "the provided hex string is not a valid ObjectID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "no such assistant in this workspace"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "ask failed",
  "error": "couldn't answer just now, try again"
}
{
  "code": "ERROR",
  "message": "unavailable",
  "error": "knowledge search isn't set up"
}