The Knowledge Base API lets you programmatically add documents to your LeafPad Knowledge Base — the same content the AI uses when generating blog posts for your organization.
You can feed data in two ways:
File upload — upload a
.txt,.md, or.pdffile directlyText input — send raw text as JSON; LeafPad stores it as a
.txtfile automatically
Endpoint
POST https://leafpad.io/api/public/v1/knowledge-baseAuthentication
All requests require authentication. You can authenticate using:
API Key (recommended) — pass your key in the
x-api-keyheader. Generate one under Settings → API Keys.Session cookie — works when calling from a browser session.
The API key must have been created while an organization was active. LeafPad automatically binds the organization ID to the key so each upload is routed to the correct knowledge base.
File Upload
Send a multipart/form-data request with a file field.
Supported formats
.txt— plain text.md— Markdown.pdf— PDF documents
Max file size: 20 MB per request
Example — cURL
curl -X POST https://leafpad.io/api/public/v1/knowledge-base \
-H "x-api-key: YOUR_API_KEY" \
-F "[email protected]"Example — Node.js
import { FormData } from 'formdata-node';
import { fileFromPath } from 'formdata-node/file-from-path';
const form = new FormData();
form.set('file', await fileFromPath('./product-docs.md'));
const res = await fetch('https://leafpad.io/api/public/v1/knowledge-base', {
method: 'POST',
headers: { 'x-api-key': process.env.LEAFPAD_API_KEY },
body: form,
});
const data = await res.json();
console.log(data.document); // { id, fileName, fileType, fileSize, publicUrl }Text Input
Send an application/json request with a text field. LeafPad writes the content to a .txt file in your knowledge base.
Body parameters
Field | Type | Required | Description |
|---|---|---|---|
| string | Yes | The raw text content to store |
| string | No | Display name (default: |
Example — cURL
curl -X POST https://leafpad.io/api/public/v1/knowledge-base \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": "Our product is...", "fileName": "product-overview.txt"}'Example — Python
import requests
res = requests.post(
'https://leafpad.io/api/public/v1/knowledge-base',
headers={
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json',
},
json={
'text': 'Our product is...',
'fileName': 'product-overview.txt',
},
)
print(res.json()) # {'success': True, 'document': {...}}Response
On success the API returns 201 Created:
{
"success": true,
"document": {
"id": 42,
"fileName": "product-overview.txt",
"fileType": "text/plain",
"fileSize": 1024,
"publicUrl": "https://..."
}
}Error Responses
Status | Cause |
|---|---|
| Missing, invalid, or revoked API key |
| No active organization on the key, missing fields, or file too large |
| Unsupported Content-Type |
| Storage or database error (R2 upload is rolled back automatically) |
Limits
Max file size: 20 MB per request
Supported types:
.txt,.md,.pdfStorage quota: 50 MB total per organization (visible in Business → Knowledge Base)
Rate limit: 2,000 requests per day per API key
Managing Documents
Documents uploaded via the API appear immediately in Business → Knowledge Base in your dashboard. You can monitor embedding status, view storage usage, and delete documents from there.
Published with LeafPad