---
title: "Save a new version of a page's code"
description: "Save a new version without overwriting; the page points to the latest version."
canonical: "https://grid82.com/docs/builder-api/pages/code-set"
updated: "2026-11-13"
---

# Save a new version of a page's code

`PUT https://studio.grid82.app/v1/apps/{appId}/pages/{pageId}/code`

Save a new version without overwriting; the page points to the latest version.

Include a note explaining why for the history. Send `baseVersion` (the page's `version` when read) to receive 409 if someone has saved since, rather than burying their version.

Requires the `pages:write` scope. Operation `pages.code.set`. MCP tool `pages_code_set`. CLI: `grid82 pages code set` (`npx grid82`).

## Path parameters

| Name     | Type   | Required | Description |
| -------- | ------ | -------- | ----------- |
| `appId`  | string | yes      |             |
| `pageId` | string | yes      |             |

## Headers

| Name              | Type   | Required | Description                                                                                                                                                                                                                                                        |
| ----------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `Idempotency-Key` | string | no       | Any unique string. Sending the same key with the same request again returns the first response (marked `Idempotency-Replayed: true`) instead of running it twice. Reusing it for a different request is refused with 409. Kept for 24 hours. Up to 255 characters. |

## Request body

| Field         | Type                                        | Required | Description              |
| ------------- | ------------------------------------------- | -------- | ------------------------ |
| `source`      | string                                      | yes      | Up to 400000 characters. |
| `note`        | string                                      | no       | Up to 200 characters.    |
| `via`         | "assistant" or "hand" or "api" or "restore" | no       |                          |
| `baseVersion` | integer                                     | no       | At least 0.              |

**Authorizations**

- `Authorization` (bearer, in header, required)

## Response

**200**: Success

- `data` (`object`, required)
- `data.version` (`integer`, required)
- `data.at` (`string`, required)
- `data.bundleHash` (`string,null`, required, default: `null`)
- `data.buildError` (`string,null`, required, default: `null`)
- `data.warnings` (`string[]`, required, default: `[]`)

```json
{
  "data": {
    "version": 123,
    "at": "<string>",
    "bundleHash": null,
    "buildError": null,
    "warnings": []
  }
}
```

**4XX**: Refused

- `error` (`object`, required)
- `error.code` (`enum<string>`, required, one of: `not_found, forbidden, unauthenticated, validation_failed, conflict, rate_limited, payment_required, not_implemented, internal`)
- `error.message` (`string`, required)
- `error.details` (`Record<string, unknown>`)

```json
{
  "error": {
    "code": "not_found",
    "message": "<string>",
    "details": {}
  }
}
```

**Example request**

```bash
curl --request PUT \
  --url 'https://studio.grid82.app/v1/apps/<appId>/pages/<pageId>/code' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "source": "<string>"
}'
```
