Guides
Sources
Read and manage the websites, text and Q&A your agent learns from, then train it
The source tools give your code the same control as Data sources in the dashboard: list sources and their training state, read what's inside them, add text, Q&A pairs and websites, rename or delete them, and start training. Reading needs Read agent settings; changes need Change sources and training.
Every change goes through a review that you apply, and training is its own step. Adding a source saves it as New; it isn't used in answers until you train.
Source types
| Type | type value | List and read | Add | Edit | Delete and restore |
|---|---|---|---|---|---|
| Website | url | ✓ | ✓ add_url_source | ✓ name, description, crawl options, pages | ✓ |
| Plain Text | text | ✓ | ✓ upload_text_source | ✓ content | ✓ |
| Q&A Pairs | qa | ✓ | ✓ add_qna_pairs | ✓ content | ✓ |
| Document | file, csv, excel | ✓ | ✗ | ✓ name and description | ✓ |
| Notion | notion | ✓ | ✗ | ✓ name and description | ✓ |
Once added, the API lists, reads, renames, trains and deletes them like any other source.
Source status
list_sources returns each source's lifecycle fields. find_sources_by_status also adds the single status the Data sources page shows:
status | Meaning |
|---|---|
new | Saved but never trained. Not used in answers yet. |
changed | Edited since it last trained. The previous version still answers. |
training | Training now. |
trained | Live: the agent answers from it. |
failed | The last training didn't finish. Any earlier trained version still answers. |
partly_trained | A website with pages still left to train. |
removed | Deleted, waiting for the next training to take it out of the agent. |
curl -X POST 'https://api.qwryai.com/public/v1/tools/find_sources_by_status' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"chatbotId": "YOUR_AGENT_ID", "statuses": ["new", "changed", "failed"], "page": 1}'get_sources_summary returns the totals: how many sources of each kind, what's waiting to train, and how much of the plan's training quota is used. check_training_status follows one source.
Training is a separate step
A new, edited or deleted source changes nothing in the agent's answers until you train:
| Tool | Does |
|---|---|
train_pending_sources | What Retrain agent does on the Data sources page: trains every new, changed and failed source and removes every removed one, up to 20 per review. |
start_training | Trains one source at the expectedVersion you read. |
toggle_auto_retrain | Turns weekly retraining on or off for a website source, on plans that include it. |
Applying a training review queues the training; it doesn't wait for it to finish. Poll find_sources_by_status or check_training_status until the source reads trained or failed.
Editing a source
Each edit names the version you read, as expectedVersion. If someone changed the source after you read it, the review is refused and you read it again. To replace text or Q&A content, read the document in full with read_source_document first, then send the whole new content to update_source_content.
Deletes wait for training
delete_source deletes a source that was never trained at once. A trained source is marked Removed instead: the agent keeps answering from it until the next training removes it, and until then restore_source brings it back. After that training, the delete can't be undone.
Endpoints
List sources
Every source with its type, version and lifecycle, 20 per page.
Sources summary
Source counts, pending changes and training quota.
Get source
One source's training state, or its documents and content.
Create source
Add text, Q&A pairs or a website through a review.
Update source
Rename a source, change its content or a website's crawl options.
Delete source
Delete an untrained source, or mark a trained one Removed until the next training.
Restore source
Bring back a Removed source before training removes it.
Error codes
Source-specific error codes beyond the standard authentication and rate-limiting errors:
| Code | HTTP | Description |
|---|---|---|
INVALID_ARGUMENTS | 400 | An argument failed the tool's schema, such as text over 10,000 characters or more than 3 Q&A pairs in one call. |
CHATBOT_NOT_FOUND | 404 | No agent with that chatbotId in your workspace. |
NOTHING_TO_CHANGE | 409 | The source already has the values you sent. |
STALE_REVIEW | 409 | The source changed after the review. Read it again and call the tool again. |
TOO_MANY_CHANGES | 400 | More than 20 changes in one review. |
INSUFFICIENT_PERMISSION | 403 | Reading needs Read agent settings; changes need Change sources and training. |