Training Sources
Programmatically manage custom file uploads - add, list, retrieve, and delete sources via API.
Overview
- Upload files (PDFs, Word docs, spreadsheets, etc.)
- List and filter your custom sources
- Retrieve source details
- Delete sources individually or in bulk
Enable Manage Sources Permission for your API key in Settings → Custom APIs.
Authentication
Authorization: YOUR_API_KEY
See Getting Started - Authentication.
Endpoints
1. List Custom Sources
GET /external/sources/custom
Retrieve paginated list with optional filtering.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | Filter by name (partial, case-insensitive) |
status | string | Filter by status (active, error, processing) |
type | string | Filter by file type |
teamId | string | Filter by team ID |
page | number | Page number (default: 1) |
pageSize | number | Items per page (default: 100, max: 1000) |
Example
curl "https://api.chataid.com/external/sources/custom?teamId=team123&status=active" \
-H "Authorization: YOUR_API_KEY"
Response
{
"ok": true,
"data": [
{
"id": "65e1c08202791119fbe1d476",
"name": "Product Documentation.pdf",
"status": "active",
"type": "pdf",
"url": "https://storage.chataid.com/...",
"wordCount": 15420,
"usageCounts": 87,
"createdAt": "2024-03-01T10:30:00Z"
}
],
"page": 1,
"pageSize": 10,
"total": 42,
"totalPages": 5
}
2. Get Custom Source by ID
GET /external/sources/custom/:id
Retrieve single source details.
Example
curl "https://api.chataid.com/external/sources/custom/65e1c08202791119fbe1d476" \
-H "Authorization: YOUR_API_KEY"
Response
{
"ok": true,
"data": {
"id": "65e1c08202791119fbe1d476",
"name": "Product Documentation.pdf",
"status": "active",
"type": "pdf",
"wordCount": 15420,
"createdAt": "2024-03-01T10:30:00Z"
}
}
3. Add Custom Sources (Upload)
POST /external/sources/custom
Upload one or more files.
- Use
multipart/form-dataencoding - For Node.js 18+, use built-in
FormData - Append files as
Blobwith proper MIME types
Query Parameters
| Parameter | Type | Description |
|---|---|---|
teamId | string | Team ID (optional, defaults to org-wide) |
Request Body
Content-Type: multipart/form-data
| Field | Type | Description |
|---|---|---|
files | File[] | One or more files to upload |
Supported Formats
| Category | Formats |
|---|---|
| Documents | PDF, Word (.doc, .docx), Text (.txt), Markdown (.md), HTML |
| Spreadsheets | Excel (.xls, .xlsx), CSV |
| Presentations | PowerPoint (.ppt, .pptx) |
| Images | PNG, JPEG, GIF |
See Data Sources - Supported File Types.
Example
- cURL
- JavaScript
- Python
curl -X POST "https://api.chataid.com/external/sources/custom?teamId=team123" \
-H "Authorization: YOUR_API_KEY" \
-F "files=@/path/to/file1.pdf" \
-F "files=@/path/to/file2.docx"
const formData = new FormData();
formData.append('files', new Blob([fileBuffer], { type: 'application/pdf' }), 'file1.pdf');
formData.append('files', new Blob([fileBuffer2], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' }), 'file2.docx');
const response = await fetch('https://api.chataid.com/external/sources/custom?teamId=team123', {
method: 'POST',
headers: { 'Authorization': API_KEY },
body: formData
});
files = [
('files', ('file1.pdf', open('/path/to/file1.pdf', 'rb'), 'application/pdf')),
('files', ('file2.docx', open('/path/to/file2.docx', 'rb')))
]
response = requests.post(
'https://api.chataid.com/external/sources/custom?teamId=team123',
headers={'Authorization': API_KEY},
files=files
)
Response
{
"ok": true,
"message": "Started training on 2 sources successfully."
}
Files process asynchronously. Use List Custom Sources to check status.
Common Errors
Unsupported file type: <filename>- Use supported formatsFile already exists: <filename>- Rename or delete existingFile size exceeds limit- Max 100 MB per fileAPI Key does not have permission to manage sources- Enable permissions
4. Delete Multiple Sources
DELETE /external/sources/custom
Delete by IDs or filters.
This operation is irreversible. Deleted sources cannot be recovered.
Request Body
Content-Type: application/json
Specify either ids or filters:
| Field | Type | Description |
|---|---|---|
ids | string[] | Array of source IDs to delete |
filters | object | Filter criteria to delete all matches |
If neither is provided, all custom sources will be deleted.
Filter Options
| Field | Description |
|---|---|
name | Filter by source name |
status | Filter by status (e.g., error) |
type | Filter by file type |
teamId | Filter by team ID |
Examples
Delete by IDs:
curl -X DELETE "https://api.chataid.com/external/sources/custom" \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"ids": ["id1", "id2"]}'
Delete by filter:
curl -X DELETE "https://api.chataid.com/external/sources/custom" \
-H "Authorization: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"filters": {"status": "error"}}'
Response
{
"ok": true,
"deletedCount": 25
}
5. Delete Source by ID
DELETE /external/sources/custom/:id
Delete single source.
Cannot be undone.
Example
curl -X DELETE "https://api.chataid.com/external/sources/custom/65e1c08202791119fbe1d476" \
-H "Authorization: YOUR_API_KEY"
Response
{
"ok": true
}
Error Responses
| Status | Error | Solution |
|---|---|---|
| 401 | Unauthorized: No Authorization Token Provided | Add Authorization header |
| 401 | Unauthorized: Invalid Access Token | Generate new API key |
| 403 | API Key does not have permission to manage sources | Enable "Manage Sources Permission" |
| 404 | Custom source not found | Verify source ID |
| 400 | Unsupported file type | Use supported formats |
See Getting Started - Error Handling.
Best Practices
- Check Permissions - Ensure API key has "Manage Sources Permission"
- Validate Files - Check formats before uploading
- Monitor Status - Poll source status after upload
- Use Filters - Reduce response size when listing
- Handle Errors - Implement proper error handling
- Organize by Teams - Assign sources appropriately
- Cleanup Regularly - Remove old or error sources
Related Documentation
- Data Sources - All data source types
- Custom APIs Settings - Configure permissions
- Getting Started - Authentication basics
- Asking Questions - Query your knowledge base