# adddocument: RAG – Add Document to Knowledge Base

> adddocument (RAG – Add Document to Knowledge Base) is a 1001fx API function in the group Knowledge bases (RAG): POST https://api.1001fx.com/rag/adddocument, 1 credit per 1,000 tokens (minimum 1). It works as a ready-made module in Make or as a plain HTTP call.

Adds a document (PDF, Word, PowerPoint, Excel, OpenDocument, HTML, text, Markdown, CSV; scans and images with useOcr) to a knowledge base, which is created on first use. The text is split into passages and embedded for rag/search and rag/ask. The same documentId replaces the document; unchanged content is not read again (0 credits). Costs 1 credit per 1,000 tokens read, plus the storage until the end of the month (1 credit per MB and month above 10 MB free per account, result.storageCredits). For large documents send the call with the header x-fx-webhook (runs in the background).

- Group: Knowledge bases (RAG)
- Endpoint: `POST https://api.1001fx.com/rag/adddocument`
- Authentication: header `X-API-KEY: YOURSECRETAPIKEY`
- Content type: multipart/form-data
- Credits: 1 credit per 1,000 tokens (minimum 1)
- Ready-made in: Make
- Docs: https://1001fx.com/functions/adddocument

## Parameters

- `knowledgeBase` (string, required) – Knowledge base: Name or ID of the knowledge base, e.g. "Support FAQ" or support-faq (same knowledge base). rag/adddocument creates it if it does not exist.
- `file` (file, optional) – File: The document. Either file or fileUrl.
- `fileUrl` (string, optional) – File URL: Public URL of the document. Either file, fileUrl or text.
- `text` (string, optional) – Text: The content as text (or Markdown). Either file, fileUrl or text.
- `title` (string, optional) – Title: Shown in the sources of rag/ask. Default: the title of the file or its name.
- `sourceUrl` (string, optional) – Source URL: Link to the original, e.g. in Google Drive – returned with the sources.
- `lastModified` (string, optional) – Last modified: ISO 8601, e.g. modifiedTime of the Drive file. Default: from the file (Last-Modified header, PDF/Office properties) or now.
- `author` (string, optional) – Author: Default: from the file properties.
- `useOcr` (boolean, optional, default `false`) – Use OCR: For scans and images: reads the document with OCR (6 credits per page on top, at most 8 pages).
- `documentId` (string, optional) – Document ID: Optional, e.g. the Google Drive file ID. The same ID replaces the document; without it an ID is generated.
- `metadata` (any, optional) – Metadata: Own key-value pairs for filters. Object {"department": "support", "tags": ["billing"]} or array [{"key": "year", "value": "2026", "type": "number"}] (type text, number, boolean or date). At most 50 keys and 8 KB.
- `keepOriginal` (boolean, optional, default `false`) – Keep original: Stores the file encrypted (counts as storage) so it can be downloaded in the app.

## Example: RAG – Add Document to Knowledge Base

```bash
curl -X POST 'https://api.1001fx.com/rag/adddocument' \
  -H 'X-API-KEY: YOURSECRETAPIKEY'
```
