All pages

API reference

Add a file to a knowledge base

POST /v1/knowledge-bases/{knowledge_base_id}/documents

View as Markdown

Send one file as multipart/form-data: text, Markdown, CSV, JSON, PDF or Word. The answer is 202 with the source, pending: it is indexed in the background, and agents answer from it once it reads indexed. The same bytes twice in one base are refused. Needs knowledge:write and a live key.

Parameters

Name In Type Required Description
knowledge_base_id path string (uuid) Yes

Body

Sent as multipart/form-data.

Field Type Required Description
file string Yes The file.
generate_faqs boolean No Also write questions and answers from it. Each one costs credit.

Answer

202 with KnowledgeDocument.

Errors

Every error is a problem document with a stable code.

Status When
401 The key is missing, mistyped, unknown, revoked or expired.
403 A test key, or a key limited to some agents.
404 This key reaches no such knowledge base.
409 The same file is already in the base, or the project is frozen.
413 The file is over the size this deployment takes.
415 Not a file type the base reads, or a text file that is not UTF-8.
422 The file is empty, or the base holds as many sources as it may.
429 Too many files sent just now. Wait for Retry-After.
500 Something went wrong on our side. Quote the request_id to support.

Examples

Add a file to a knowledge base
#!/bin/sh
# Add a file to a knowledge base. With a live key. It is indexed in the background: read it until it says indexed.
curl -sS --fail-with-body -X POST "https://api.aigently.ai/v1/knowledge-bases/6e8a0c2d-4f6b-4d8e-a0c2-4e6a8c0e2a4c/documents" \
  -H "Authorization: Bearer $AIGENTLY_API_KEY" \
  -F "file=@opening-hours.md;type=text/markdown"

Try it

Sends this request to the API from your browser, with a test key. Nothing it does rings a phone.