---
title: "Edit a site's pages and code: commit to its source"
method: POST
path: "/sites/{id}/source/commits"
tags: ["Sites"]
---

# Edit a site's pages and code: commit to its source

`POST /sites/{id}/source/commits`

## Request

- Base URL: `https://api.crevio.co/v1`
- URL: `https://api.crevio.co/v1/sites/{id}/source/commits`
- Auth: API key in header `Authorization`

Applies 1 to 100 file operations to the site's `main` branch as one commit. To send a unified diff instead of whole files, use `POST /sites/{id}/source/commits/diff`. It does not deploy: to put the commit live, call `POST /sites/{id}/deploy` with `commit_sha` set to the returned `sha`.

Each operation is an `upsert` (the file's whole new content; text as UTF-8, binary files as base64 with `encoding: base64`) or a `delete`. Paths are relative to the repository root. `..`, `.git/` and a leading `/` are refused, and so are environment files (`.env`, `.env.*`, `.dev.vars`): store secrets with `POST /sites/{id}/secrets` instead. The upserts together carry at most 4 MiB, and a path may appear in one operation only.

Pass `expected_head_sha`, the `head_sha` your edits are based on. If `main` has moved the call fails with `409 stale_head` and `error.head_sha`, the current head: read the files you are changing again and retry against it. Without it, the call still fails the same way if `main` moves while the commit is pushed, so no one's work is ever overwritten.

Operations that leave every file as it was make no commit and answer `changed: false` with the current head, so retrying a commit that already landed is safe.

A repository that refuses the commit for another reason, such as a protected branch on a connected GitHub repository, answers `422 commit_rejected` with its reason.

## Path parameters

- `id` string, required

## Headers

- `Idempotency-Key` string

## Request body

- object
  - `message` string, required: The commit message, 1 to 5000 characters.
  - `operations` object[], required: 1 to 100 file operations, applied together as one commit. A path may appear once. The upserts together carry at most 4 MiB.
    - `action` 'upsert' | 'delete', required: `upsert` writes the whole file, creating it or replacing it. `delete` removes it; deleting a path that does not exist does nothing.
    - `path` string, required: Relative to the repository root, e.g. `src/routes/index.tsx`. No `..`, no `.git/`, no leading `/`, and no environment files (`.env`, `.env.*`, `.dev.vars`).
    - `content` string: For `upsert`, required: the file's full new content. UTF-8 text, or base64 when `encoding` is `base64`.
    - `encoding` 'utf8' | 'base64': How `content` is encoded. Use `base64` for images, fonts and other binary files.
  - `expected_head_sha` string: The `head_sha` your edits are based on (from a source read or your last commit). If `main` is anywhere else the call fails with `409 stale_head` and changes nothing. A prefix of 7 or more characters is accepted.

## Response `200`

The commit `main` now points at

- object
  - `object` 'site_source_commit', required
  - `sha` string, required: The commit `main` now points at.
  - `previous_sha` string, required: The commit `main` pointed at before.
  - `changed` boolean, required: False when the operations left every file as it was: no commit was made and `sha` equals `previous_sha`.

## Other responses

- `401`: Authentication required
- `403`: Forbidden
- `404`: Resource not found
- `409`: `main` moved since `expected_head_sha`, or while the commit was being pushed. Nothing was committed. `error.head_sha` is where `main` is now: read the files you are changing again and retry against it.
- `422`: Validation error
- `429`: Rate limit exceeded — 600 requests per minute per owner on the free tier: every API key and OAuth token one person holds on an account shares one budget, and the account's team keys share another. Retry after the number of seconds in `Retry-After`.
- `503`: Feature not configured for this workspace

## Changes

- **2026-11-15** `56c22ab9b282`: 6 warning
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `401`
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `403`
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `404`
  - added the new `idempotency_error` enum value to the `error/type` response property for the response status `422`
  - …2 more
- **2026-11-15** `3d2d9bae7da4`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/crevio/apis/crevio-api-v1/changes/sites/:id/source/commits/post.md)

---

[API](https://skmtc.dev/crevio/apis/crevio-api-v1.md) - [All operations](https://skmtc.dev/crevio/apis/crevio-api-v1/llms.txt) - [OpenAPI document](https://skmtc.dev/crevio/apis/crevio-api-v1/revisions/ccbd8fcbd6d7?raw)
