# restore_code_backup

Source: https://modulify.ai/docs/api/backups/restore-code-backup

Rolls the source code of a site back to an earlier code backup and reloads the preview from it, deleting the whole site chat history.

- Title: Restore a site code backup
- Scope: `sites:delete`
- Access: Destructive
- Endpoint: `POST /v1/restore_code_backup`

It does far more than its name suggests. It deletes the entire site chat history: every message exchanged with the site agent is removed for everyone in the project and cannot be brought back, the agent loses all memory of what was discussed, and any messages queued to run next are thrown away unsent. Any file the agent wrote since that code backup is reverted, and files added since are deleted.

No backup is taken first, unlike `restore_backup`. The tool tells the client never to call it speculatively: it has to tell you plainly that your whole conversation with the agent will be deleted, and get your agreement first. Restoring does not publish, so the live site keeps serving what you published last.

If a generation is running, it refuses with a `409` reading `AI is currently generating. Stop it before restoring this code backup!` unless `cancelActiveJob` is set, which stops that generation mid-flight. It also refuses with a `409` when another code backup is already being restored for the site (`Another code backup is already being restored for this site!`), and when the latest changes of the site are still being saved after about 30 seconds of waiting (`Your latest changes are still being saved. Try restoring again in a moment!`). In both of those cases nothing was changed, so try again in a moment.

Like `restore_backup`, it is refused while the site code is being moved into GitHub, when Modulify has lost access to the GitHub repository that holds the site or that repository was deleted, and when the code lives in the workspace's own GitHub but the workspace is on the Free plan. See [Restore a backup](https://modulify.ai/docs/editor/backups#restore-a-backup).

## Request

Call it with a `POST` to `https://api.modulify.ai/v1/restore_code_backup`, sending the inputs below as a JSON object. The token needs the `sites:delete` scope.

> **Warning**
>
> This method is marked destructive: it deletes or overwrites data. Check the inputs before you call it, and send an [Idempotency-Key](https://modulify.ai/docs/api/idempotency) header whenever you might retry it.

```bash
curl -X POST https://api.modulify.ai/v1/restore_code_backup \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"projectId":"PROJECT_ID","codeBackupId":"CODE_BACKUP_ID"}'
```

Over MCP, the same method is the [restore_code_backup tool](https://modulify.ai/docs/mcp/backups/restore-code-backup).

## Inputs

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `projectId` | string | Yes | The site id. |
| `codeBackupId` | string | Yes | The code backup to roll back to, from `list_code_backups`. |
| `cancelActiveJob` | boolean | No | True to stop a generation that is running instead of refusing. Set it only when you have agreed to lose that work. |

## Response

Every call answers with the [JSON envelope](https://modulify.ai/docs/api/requests-and-responses#the-response) of `success`, `message`, `data`, `code` and `version`. `data` holds the result described above, and on a method that returns a total, `count` carries it. The [response headers](https://modulify.ai/docs/api/requests-and-responses#headers-on-every-method-call) carry the call's `X-Request-Id` and what is left of your per-minute budget in `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`. [Errors](https://modulify.ai/docs/api/errors) explains every status code a call can answer with.