# Toggle auto-retrain > Turn weekly automatic retraining of a website source on or off Website sources can retrain themselves every week, so the agent keeps up with changes to your site. In QwryAI the switch belongs to each website source, not to the whole agent: `toggle_auto_retrain` turns it on or off for one source. Like every change made through the API, it returns a review first; the switch flips when you apply it. ```http POST https://api.qwryai.com/public/v1/tools/toggle_auto_retrain ``` ## Authentication Send your API key as `Authorization: Bearer `, or in an `x-api-key` header. The key needs **Change sources and training**. See [Authentication](/docs/api-reference/v2/authentication). ## Body parameters | Name | Type | Required | Description | | - | - | - | - | | `chatbotId` | `string` | Yes | The agent's id, from [List agents](/docs/api-reference/v2/agents/list-agents). | | `sourceId` | `string` | Yes | The website source's `id`, from `list_sources`. | | `expectedVersion` | `integer` | Yes | The source's `version` as you just read it. If the source changed since, the review is refused. | | `enabled` | `boolean` | Yes | `true` retrains the source every week; `false` stops it. | > [!NOTE] > > Weekly retraining works only on website sources, and only while the source is idle. Turning it on needs a plan that includes automatic retraining. ## Request example > [tab] cURL > > ```bash > curl -X POST 'https://api.qwryai.com/public/v1/tools/toggle_auto_retrain' \ > -H 'Authorization: Bearer YOUR_API_KEY' \ > -H 'Content-Type: application/json' \ > -d '{ > "chatbotId": "YOUR_AGENT_ID", > "sourceId": "YOUR_SOURCE_ID", > "expectedVersion": 4, > "enabled": true > }' > ``` > [tab] JavaScript > > ```javascript > const API = "https://api.qwryai.com/public/v1"; > const headers = { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json" }; > > const { data: review } = await fetch(`${API}/tools/toggle_auto_retrain`, { > method: "POST", > headers, > body: JSON.stringify({ > chatbotId: "YOUR_AGENT_ID", > sourceId: "YOUR_SOURCE_ID", > expectedVersion: 4, > enabled: true, > }), > }).then((r) => r.json()); > > await fetch(`${API}/reviews/${review.reviewId}/apply`, { method: "POST", headers }); > ``` > [tab] Python > > ```python > import requests > > API = "https://api.qwryai.com/public/v1" > headers = {"Authorization": "Bearer YOUR_API_KEY"} > > review = requests.post(f"{API}/tools/toggle_auto_retrain", headers=headers, json={ > "chatbotId": "YOUR_AGENT_ID", > "sourceId": "YOUR_SOURCE_ID", > "expectedVersion": 4, > "enabled": True, > }).json()["data"] > > requests.post(f"{API}/reviews/{review['reviewId']}/apply", headers=headers) > ``` ## Response ```json { "success": true, "data": { "status": "review_required", "reviewId": "2c9e7a41-5b3d-4f08-9e6a-1d4b8c7f0a25", "tool": "toggle_auto_retrain", "changes": [ { "title": "Set weekly retraining for source: qwryai.com", "before": { "weekly retraining": "Off" }, "after": { "weekly retraining": "On" } } ], "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." } } ``` Apply it with `POST /public/v1/reviews/{reviewId}/apply` within 15 minutes. Afterwards, `list_sources` shows `autoRetrain: true` on the source. ## Errors | HTTP status | Code | When | | - | - | - | | 400 | `INVALID_ARGUMENTS` | A missing or malformed argument, or the source isn't a website. | | 400 | `CHATBOT_ID_REQUIRED` | The body has no valid `chatbotId`. | | 401 | `API_KEY_REQUIRED` / `INVALID_API_KEY` | No credential, or an unknown, deleted or expired one. | | 403 | `INSUFFICIENT_PERMISSION` | The key doesn't hold **Change sources and training**. | | 403 | `PLAN_FEATURE_UNAVAILABLE` | Turning it on: the plan doesn't include automatic retraining. | | 404 | `CHATBOT_NOT_FOUND` | No agent with that `chatbotId` in your workspace. | | 404 | `SOURCE_NOT_FOUND` | No source with that `sourceId` on this agent. | | 409 | `SOURCE_VERSION_CONFLICT` | The source changed after you read it. Read `version` again. | | 409 | `SOURCE_OPERATION_IN_PROGRESS` | The source is training, being removed or otherwise busy. Try again once it's idle. | | 429 | `INTEGRATION_RATE_LIMIT_EXCEEDED` | More than 2,000 requests in 15 minutes. | See [Error Handling](/docs/api-reference/v2/error-handling) for every code.