Skip to content
QwryAI
Documentation
Pages

Endpoints

Train agent

Train every new or changed source, as Retrain agent does on the Data sources page

Adding or editing a source doesn't retrain the agent by itself. train_pending_sources is the API's Retrain agent button: it trains every source with untrained changes (new, changed or failed) and removes every source marked for removal, in one review. To train a single source instead, use start_training with its sourceId and expectedVersion.

Training runs in the background. Applying the review queues it; follow progress with check_training_status or find_sources_by_status. See Sources.

POSThttps://api.qwryai.com/public/v1/tools/train_pending_sources

Authentication

Send your API key as Authorization: Bearer <api-key>, or in an x-api-key header. The key needs Change sources and training. See Authentication.

Body parameters

NameTypeRequiredDescription
chatbotIdstringYesThe agent's id, from List agents.

start_training takes chatbotId, sourceId and expectedVersion (the source's version from list_sources) to train that one source.

Request example

Bash
curl -X POST 'https://api.qwryai.com/public/v1/tools/train_pending_sources' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"chatbotId": "YOUR_AGENT_ID"}'

# Apply the review it returns to queue training
curl -X POST 'https://api.qwryai.com/public/v1/reviews/REVIEW_ID/apply' \
  -H 'Authorization: Bearer YOUR_API_KEY'

Response

The review lists each source that will train:

JSON
{
  "success": true,
  "data": {
    "status": "review_required",
    "reviewId": "6f0a3d92-7c1e-4b58-a2d4-9e3b5c1f7a80",
    "tool": "train_pending_sources",
    "changes": [
      { "title": "Train source: Returns policy", "before": { "training": "Changed" }, "after": { "training": "Queued" } },
      { "title": "Train source: Shipping FAQ", "before": { "training": "Not trained" }, "after": { "training": "Queued" } }
    ],
    "unchanged": [],
    "expiresAt": "2026-12-01T10:15:00.000Z",
    "next": "Show these changes to the user. Call apply_change with this reviewId only after they approve; the review expires in 15 minutes."
  }
}

Applying it queues a training job for each source:

JSON
{
  "success": true,
  "data": {
    "status": "succeeded",
    "reviewId": "6f0a3d92-7c1e-4b58-a2d4-9e3b5c1f7a80",
    "tool": "train_pending_sources",
    "data": {
      "applied": true,
      "trained": [
        { "jobId": "JOB_ID_1", "sourceId": "SOURCE_ID_1", "status": "pending", "applied": true, "training": "pending" },
        { "jobId": "JOB_ID_2", "sourceId": "SOURCE_ID_2", "status": "pending", "applied": true, "training": "pending" }
      ]
    },
    "receipt": {
      "applied": true,
      "queued": 2,
      "notQueued": [],
      "coverage": "Admission is committed for each queued source. Job status describes asynchronous training; admission alone does not prove completion."
    }
  }
}

Errors

HTTP statusCodeWhen
400INVALID_ARGUMENTSNo source is waiting to be trained, or the body has another field.
400CHATBOT_ID_REQUIREDThe body has no valid chatbotId.
401API_KEY_REQUIRED / INVALID_API_KEYNo credential, or an unknown, deleted or expired one.
403INSUFFICIENT_PERMISSIONThe key doesn't hold Change sources and training.
404CHATBOT_NOT_FOUNDNo agent with that chatbotId in your workspace.
409STALE_REVIEW / REVIEW_EXPIREDApplying: the sources changed after the review, or 15 minutes passed. Call the tool again.
429INTEGRATION_RATE_LIMIT_EXCEEDEDMore than 2,000 requests in 15 minutes.

See Error Handling for every code.

Explore the documentation