#Knowledge base API
Use this API to feed documents into an AI Studio knowledge base from your own systems. You can upload files, check how ingestion is going, retry failures, download and delete documents, and keep the knowledge base in step with a cloud folder.
{BASE_URL} = https://studio.scaletechsolutions.ai/api/v1#Authentication
Every request to {BASE_URL}/public/kb/... needs a knowledge base API key.
#One key, one knowledge base
A key is bound to exactly one knowledge base when it is created. The knowledge base always comes from the key, never from the URL, which is why no path contains a knowledge base id. A key can never read or change any other knowledge base. Every request runs as the user who created the key; for folder sync, the drive is read with that user's connected account.
Authorization: Bearer ai_labs_kb_3f9c0d1e2a4b5c6d7e8f9a0b1c2d3e4fKeys start with ai_labs_kb_ followed by 32 hexadecimal characters.
#Creating, listing and revoking keys
Create, view and revoke keys in the AI Studio app, on the knowledge base's page. There is no public API for this. A key is shown in full only once, when you create it.
#When a key is refused
| Status | detail | Cause |
|---|---|---|
401 | "Not authenticated" | No Authorization header, or it is not Bearer <key>. |
401 | "Invalid or revoked API key" | The key is unknown or revoked, or the user who created it was deactivated. These cases return the same answer on purpose. |
404 | "Knowledge base not found" | The key is valid but its knowledge base has been deleted. |
#Keeping keys safe
- Keys do not expire. Treat them like passwords, and keep them on your server.
- Store keys in a secret manager or environment variable, not in code.
- Create one key per system, with a clear
name, so you can revoke one without breaking the others. - Check
last_used_atto find keys nobody uses any more, and revoke them.
#Documents
#Document lifecycle
Ingestion runs in the background. A document moves through these status values:
| Status | Meaning |
|---|---|
pending | Stored and waiting to be processed. |
processing | Text is being extracted, split into chunks and embedded. |
completed | Done. The document is searchable. chunk_count says how many chunks it produced. |
error | Ingestion failed. error_message says why. |
Upload returns as soon as the file is stored, usually with status: "pending". A document is searchable only once it is completed.
Automatic retries. For documents that came from a folder sync, each sync retries a failed document, up to 3 attempts in total. After that, retries_exhausted becomes true and the document is left alone until you reingest it yourself. A document where no text could be found at all is marked exhausted at once. Documents you upload directly are not retried automatically; use reingest.
#Supported files and limits
Accepted file extensions (checked on the file name, case-insensitive):
| Kind | Extensions |
|---|---|
| Documents | .pdf .docx .doc .pptx .ppt |
| Spreadsheets | .xlsx .xls .csv .tsv |
| Text and markup | .txt .md .html .htm .xml .json |
| Notebooks | .ipynb |
| Images (text is read with OCR) | .jpg .jpeg .png .gif .bmp .tiff .webp |
| Archives | .zip |
| CAD | .step |
| Limit | Value | Applies to |
|---|---|---|
| Per-file size | 200 MB | Files from a folder sync. Larger files are skipped. Direct uploads have no per-file limit set by the API. |
| Files per folder source | 5,000 | Folder sync. Files beyond this are skipped. |
| Text indexed per document | first 40,000 characters | Documents, text files, notebooks, images and archives. |
| OCR pages | first 80 pages | Scanned PDFs with no text layer. |
| Archive expansion | 500 MB uncompressed, 20,000 entries | .zip and Office files. Larger archives fail with an error. |
Password-protected files cannot be read and end in error. If the knowledge base owner has personal-data masking turned on, personal data in the text is masked before it is indexed.
#The document object
Returned by upload, list and single reingest.
{
"id": "c1b2b054-2be4-401f-b1d3-9f0516e43381",
"kb_id": "3b5f69f3-945e-4d68-922d-00e30c66cfcb",
"filename": "q3-report.pdf",
"file_key": "kb/3b5f69f3-.../a779f8b7c0d84e0c9b1f2a3d4e5f6a7b_q3-report.pdf",
"status": "completed",
"chunk_count": 42,
"error_message": null,
"custom_metadata": {"team": "finance"},
"created_at": "2026-11-27T11:23:46Z",
"updated_at": "2026-11-27T11:24:02Z",
"ingest_attempts": 0,
"retries_exhausted": false,
"origin": "manual",
"source_folder": null,
"source_site": null,
"source_site_url": null,
"web_url": null
}| Field | Type | Meaning |
|---|---|---|
id | UUID | The document id. Use it in the per-document routes. |
kb_id | UUID | The knowledge base (the one your key is bound to). |
filename | string | The original file name. |
file_key | string | Internal storage reference. Use the download route instead. |
status | string | pending, processing, completed or error. |
chunk_count | integer | Chunks produced by the last successful run. |
error_message | string or null | Why ingestion failed, written for a person to read. |
custom_metadata | object or null | The metadata you sent on upload. |
created_at, updated_at | datetime | ISO 8601 timestamps. |
ingest_attempts | integer | Automatic extraction attempts so far. Reset to 0 when you reingest. |
retries_exhausted | boolean | true when automatic retries have stopped. Only meaningful when status is error. |
origin | string | manual for an uploaded file. For a synced file: google_drive, onedrive or sharepoint. |
source_folder | string or null | Name of the folder it was synced from. |
source_site, source_site_url | string or null | SharePoint site name and link. |
web_url | string or null | Link to the file at the provider. null for uploads. |
#Upload a document
{BASE_URL}/public/kb/uploadStores a file in the knowledge base and starts ingestion. Request type is multipart/form-data.
| Field | Type | Required | Meaning |
|---|---|---|---|
file | file | yes | The file. Its name must end in a supported extension. |
custom_metadata | string | no | A JSON object as a string, for example {"team":"finance"}. Returned in custom_metadata. |
curl -X POST "{BASE_URL}/public/kb/upload" \
-H "Authorization: Bearer $KB_API_KEY" \
-F "file=@q3-report.pdf" \
--form-string 'custom_metadata={"team":"finance"}'Response 200 OK: a document object.
| Status | detail | What to do |
|---|---|---|
400 | "Unsupported file type. Supported formats: pdf, docx, ..." | Use a supported extension. |
404 | "Knowledge base not found" | The key's knowledge base was deleted. |
422 | validation list | The file field is missing. |
500 | "Could not save file" | Storage failed. Retry later. |
#List documents
{BASE_URL}/public/kb/documentsReturns every document with full details, as an array of document objects. There is no pagination and the order is not guaranteed. On a large knowledge base this response can be big; if you only need progress, use Get ingestion status. Deleted documents are not listed.
#Get ingestion status
{BASE_URL}/public/kb/documents/statusA small summary of where every document stands. This is the route to poll after an upload or a sync.
{
"total": 1346,
"pending": 3,
"processing": 1,
"completed": 1317,
"error": 25,
"in_progress": true,
"failures": [
{
"id": "788fda94-1b11-4bfa-9624-4f22426c151d",
"filename": "logo.webp",
"error_message": "No text could be extracted from 'logo.webp'. The file may contain only images, or no readable content.",
"ingest_attempts": 3,
"retries_exhausted": true,
"web_url": null
}
]
}| Field | Type | Meaning |
|---|---|---|
total | integer | Documents in the knowledge base. |
pending, processing, completed, error | integer | Counts per status. |
in_progress | boolean | true while any document is pending or processing. |
failures | array | Every document in error, most recently updated first. |
Common error_message values:
| Message starts with | Meaning | Will a retry help? |
|---|---|---|
No text could be extracted from '...' | The file has no readable text. | No. |
'...' is password-protected | The file is encrypted. | Only after you remove the password and upload it again. |
'...' expands to more than 500 MB | The archive is too large when unpacked. | No. |
Could not parse document: ... | The file is damaged or could not be read. | Sometimes. |
#Reingest all failed documents
{BASE_URL}/public/kb/documents/reingest-failedProcesses again every document whose status is error. It re-reads each document from the copy AI Studio already stored (nothing is downloaded from the drive), resets ingest_attempts to 0, clears error_message and sets status to pending. Documents that are not in error are never touched. No request body.
{
"failed": 25,
"queued": 24,
"unavailable": ["old-scan.pdf"]
}| Field | Type | Meaning |
|---|---|---|
failed | integer | Documents that were in error. |
queued | integer | Documents now pending again. |
unavailable | array of strings | File names whose stored copy is missing. Upload them again. |
#Reingest one document
{BASE_URL}/public/kb/documents/{document_id}/reingestProcesses one document again from its stored copy, whatever its status or attempt count. Returns the document object, usually pending.
| Status | detail | What to do |
|---|---|---|
404 | "Document not found" | The id is wrong, deleted, or in another knowledge base. |
404 | "Original file is no longer available" | The stored copy is gone. Upload the file again. |
422 | validation list | document_id is not a UUID. |
#Download a document
{BASE_URL}/public/kb/documents/{document_id}/downloadGives you the original file. Works for any status. Response is 307 Temporary Redirect; the Location header holds a signed URL valid for 5 minutes that needs no Authorization header. Don't store it; ask this route again each time.
curl -L -o q3-report.pdf \
"{BASE_URL}/public/kb/documents/c1b2b054-2be4-401f-b1d3-9f0516e43381/download" \
-H "Authorization: Bearer $KB_API_KEY"curl -L follows the redirect and does not send your key to the storage host.
#Delete a document
{BASE_URL}/public/kb/documents/{document_id}Removes a document. It disappears from every listing and count and is no longer searchable. It cannot be restored through the API. Returns 204 No Content.
#Folder sources
A folder source links the knowledge base to a folder in a cloud drive. AI Studio then adds new files, updates changed files and removes deleted files for you.
#How folder sync works
provider | Drive |
|---|---|
google_drive | Google Drive |
onedrive | Microsoft OneDrive |
sharepoint | Microsoft SharePoint document libraries |
You need a connected account first. This API cannot connect a drive, because connecting needs a person to sign in and consent in a browser. The user who created your key must connect the drive once in the AI Studio app, under connectors. Browse and sync then read the drive with that user's account, so they only see folders that user can open.
Two ways to run a sync.
- On a schedule. Set
sync_interval_minutes(60 to 10080). The first sync starts right away, then repeats. Each run is spread by a few minutes. - On demand. Leave out the interval, then call Sync a source now.
Folder sync intervals
Allowed range for sync_interval_minutes, with common choices marked.
| Change in the folder | What happens in the knowledge base |
|---|---|
| New file | Downloaded and ingested. |
| Changed file | Downloaded and ingested again. Detected from the provider's content marker, so renaming or changing sharing does not reprocess it. |
| Unchanged file | Nothing. Counted in unchanged. |
| File removed from the folder | The document is removed from the knowledge base. |
File that cannot be taken (unsupported type, over 200 MB, over the 5,000-file limit, a lock file such as ~$report.docx) | Skipped and listed in last_result.skipped with a reason. If it was ingested before, the existing document is kept. |
| Document whose ingestion failed | Retried, up to 3 attempts in total. |
Google Docs, Sheets and Slides are converted to .docx, .xlsx and .pptx and ingested. Other Google-native types are skipped. With recursive: true, files in subfolders are included too.
Only one sync per source runs at a time. A sync finishing means files were fetched and queued; each document still goes through the document lifecycle.
#The source object
{
"id": "8d9e40bf-3706-4127-9b92-64d3cac3d437",
"kb_id": "3b5f69f3-945e-4d68-922d-00e30c66cfcb",
"user_id": "44e1b6a2-7c1d-4f0a-9e2b-1a2b3c4d5e6f",
"provider": "onedrive",
"external_folder_id": "01ABCDEFGHIJKLMNOP",
"folder_name": "Reports",
"folder_path": "Reports/2026",
"folder_web_url": "https://onedrive.live.com/...",
"site_name": null,
"site_web_url": null,
"recursive": true,
"sync_interval_minutes": 1440,
"next_sync_at": "2026-11-28T04:12:00Z",
"sync_status": "ok",
"last_synced_at": "2026-11-27T04:09:31Z",
"last_error": null,
"last_result": {
"status": "ok",
"added": 2, "updated": 1, "removed": 0, "unchanged": 37, "retried": 0,
"skipped": [
{ "name": "walkthrough.mov", "reason": "unsupported file type (mov)", "external_id": "01QRSTUVWX", "web_url": "https://onedrive.live.com/..." }
]
},
"created_at": "2026-11-01T10:00:00Z",
"updated_at": "2026-11-27T04:09:31Z"
}| Field | Type | Meaning |
|---|---|---|
id | UUID | The source id. Store it; the other source routes need it. |
user_id | UUID | The user whose drive account the sync uses. |
provider | string | google_drive, onedrive or sharepoint. |
external_folder_id | string | The provider's folder id. Renaming the folder does not break the source. |
folder_name, folder_path, folder_web_url | string or null | Name, path and link. |
site_name, site_web_url | string or null | The SharePoint site above the folder. |
recursive | boolean | Whether subfolders are included. |
sync_interval_minutes | integer or null | Schedule. null means on demand only. |
next_sync_at | datetime or null | When the next scheduled sync is due. |
sync_status | string | See below. |
last_synced_at | datetime or null | When the last successful sync finished. |
last_error | string or null | Why the last sync failed or stopped. |
last_result | object or null | What the last sync did. null before the first sync. |
last_result has status, added, updated, removed, unchanged, retried, skipped (each with name, reason, external_id, web_url) and error when the sync failed or stopped. Typical skip reasons: unsupported file type (mov), larger than 200 MB, folder exceeds 5000 files, download failed.
#sync_status values
| Value | Meaning | What to do |
|---|---|---|
pending | Connected, no sync has run yet. | Wait, or trigger a sync. |
syncing | A sync is running. | Keep polling. |
ok | The last sync succeeded. | Nothing. |
error | The last sync failed. Read last_error. | Often the drive connection needs reconnecting, or the folder was deleted. |
needs_review | The safety stop fired. Nothing was removed. | Check that the folder holds what you expect. |
disabled | Syncing is switched off for this source. | None through this API. |
#Browse folders
{BASE_URL}/public/kb/sources/browseLists one level of folders in a connected drive, so you can find a folder id.
| Name | Type | Required | Meaning |
|---|---|---|---|
provider | string | yes | google_drive, onedrive or sharepoint. |
folder_id | string | no | List the folders inside this folder. |
folder_path | string | no | List the folders inside this path, for example Reports/2026. |
curl -G "{BASE_URL}/public/kb/sources/browse" \
-H "Authorization: Bearer $KB_API_KEY" \
--data-urlencode "provider=onedrive" \
--data-urlencode "folder_path=Reports/2026"Response is { "folder": {...}, "folders": [...] }. Each folder has id, name, web_url, path, shared, owner, kind (folder, or for SharePoint also site and library) and selectable. selectable: false means you can open the entry but not connect it, such as a SharePoint site.
| Status | detail | What to do |
|---|---|---|
400 | "Connector '<provider>' is not configured. ..." | The key's user has not connected this drive. Connect it in the app. |
400 | "Your <Drive> connection has expired. ..." with X-Reconnect-Required: true | See Reconnect required. |
404 | provider message | The folder was not found. |
422 | validation list | provider is missing. |
#List sources
{BASE_URL}/public/kb/sourcesReturns every folder source, oldest first, as an array of source objects. Poll this after you trigger a sync.
#Connect a folder
{BASE_URL}/public/kb/sourcesLinks a folder to the knowledge base. The folder is looked up during this request, so a wrong path or missing connection fails now, not later in the background.
| Field | Type | Required | Meaning |
|---|---|---|---|
provider | string | yes | google_drive, onedrive or sharepoint. |
folder_id | string | one of the two | The provider's folder id. Most exact. |
folder_path | string | one of the two | A path such as Reports/2026. |
recursive | boolean | no | Include files in subfolders. Default false. |
sync_interval_minutes | integer | no | 60 to 10080. Leave it out for on-demand only. |
curl -X POST "{BASE_URL}/public/kb/sources" \
-H "Authorization: Bearer $KB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"provider": "onedrive", "folder_path": "Reports/2026", "recursive": true, "sync_interval_minutes": 1440}'Response 201 Created: the new source, with sync_status: "pending". With sync_interval_minutes set the first sync starts right away; poll List sources instead of calling sync.
| Status | detail | What to do |
|---|---|---|
400 | "'<name>' cannot be connected directly. Open it and choose a document library, or a folder inside one." | You picked an entry with selectable: false. |
404 | provider message | The folder was not found. |
409 | "'<name>' is already connected to this knowledge base." | Use the existing source. |
422 | validation list | Neither folder_id nor folder_path, unsupported provider, or interval outside 60 to 10080. |
#Change a source
{BASE_URL}/public/kb/sources/{source_id}| Field | Type | Meaning |
|---|---|---|
recursive | boolean | Include or stop including subfolders. Takes effect on the next sync. |
sync_interval_minutes | integer | New schedule, 60 to 10080. The next run is rescheduled from now. |
manual_only | boolean | true removes the schedule. The source stays and can still be synced on demand. |
Response 200 OK: the updated source.
#Remove a source
{BASE_URL}/public/kb/sources/{source_id}Stops syncing the folder. By default, documents already ingested stay and show origin: "manual" from then on. Pass purge=true to remove them too. If you later connect the same folder again, kept documents are matched to their files. Returns 204 No Content.
curl -X DELETE "{BASE_URL}/public/kb/sources/8d9e40bf-3706-4127-9b92-64d3cac3d437?purge=true" \
-H "Authorization: Bearer $KB_API_KEY"#Sync a source now
{BASE_URL}/public/kb/sources/{source_id}/syncQueues a sync and returns at once. A first sync of a large folder can take many minutes, so poll List sources for sync_status and last_result. If a sync is already running the extra one does nothing, and it is skipped while the source is needs_review.
{
"source_id": "8d9e40bf-3706-4127-9b92-64d3cac3d437",
"sync_status": "ok",
"queued": true,
"detail": "Sync queued. Poll GET /sources for the outcome."
}sync_status here is the status before this sync runs. Drive problems (connection expired, folder deleted) show up later as sync_status: "error" and last_error.
#Errors
Errors are JSON with a detail field. Validation errors (422) carry a list; unexpected server errors (500) include a request_id to quote if you contact support. Every response also carries an X-Request-ID header.
| Status | Meaning |
|---|---|
200 | Success with a body. |
201 | Created (a folder source, or a key). |
202 | Accepted: a sync was queued. |
204 | Success with no body (delete, revoke). |
307 | Redirect to a signed download URL. |
400 | Unsupported file type, drive not connected or expired, folder cannot be connected, or the provider refused. |
401 | Missing, unknown or revoked API key, or its user is deactivated. |
404 | Knowledge base, document, source or folder not found, or the stored file is gone. |
409 | That folder is already connected. |
422 | The request did not pass validation. |
500 | Server error. Retry later; quote request_id. |
#Reconnect required
When the drive connection of the key's user has expired or was revoked at the provider, browse and connect calls answer:
HTTP/1.1 400 Bad Request
X-Reconnect-Required: true
X-Reconnect-Provider: onedrive
X-Reconnect-Provider-Label: Microsoft OneDrive
{"detail": "Your Microsoft OneDrive connection has expired. Please reconnect Microsoft OneDrive in Settings → Connectors."}Check the X-Reconnect-Required header, not the message text. Retrying will not help: the key's user must reconnect the drive in the AI Studio app. Scheduled syncs hit the same problem and report it as sync_status: "error".
#End-to-end example (Python)
Uploads a file, waits until ingestion is done, then lists the documents. Needs httpx.
import json
import os
import time
import httpx
BASE_URL = "https://studio.scaletechsolutions.ai/api/v1"
API_KEY = os.environ["AI_STUDIO_KB_API_KEY"] # keep the key out of your code
def main() -> None:
headers = {"Authorization": f"Bearer {API_KEY}"}
with httpx.Client(base_url=BASE_URL, headers=headers, timeout=60) as client:
# 1. Upload a file with some metadata.
with open("q3-report.pdf", "rb") as f:
response = client.post(
"/public/kb/upload",
files={"file": ("q3-report.pdf", f, "application/pdf")},
data={"custom_metadata": json.dumps({"team": "finance"})},
)
response.raise_for_status()
document = response.json()
print(f"Uploaded {document['filename']} as {document['id']} ({document['status']})")
# 2. Poll the status summary until nothing is pending or processing.
deadline = time.monotonic() + 30 * 60 # give up after 30 minutes
while True:
response = client.get("/public/kb/documents/status")
response.raise_for_status()
status = response.json()
if not status["in_progress"]:
break
if time.monotonic() > deadline:
raise TimeoutError("Ingestion is still running after 30 minutes")
print(f"pending={status['pending']} processing={status['processing']}")
time.sleep(5)
for failure in status["failures"]:
print(f"Failed: {failure['filename']}: {failure['error_message']}")
# 3. List the documents and find ours.
response = client.get("/public/kb/documents")
response.raise_for_status()
for doc in response.json():
marker = " <- new" if doc["id"] == document["id"] else ""
print(f"{doc['status']:<10} {doc['chunk_count']:>5} chunks {doc['filename']}{marker}")
if __name__ == "__main__":
main()The status summary covers the whole knowledge base, so in_progress also waits for other documents still being processed, for example from a folder sync running at the same time.