---
title: "Change server code switches"
method: PATCH
path: "/api/{ns}/{id}/lambda"
tags: ["Brew Lambda"]
---

# Change server code switches

`PATCH /api/{ns}/{id}/lambda`

## Request

- Base URL: `https://brewpage.app`
- URL: `https://brewpage.app/api/{ns}/{id}/lambda`
- Auth: one of:
  - API key in header `X-Owner-Token`
  - API key in header `X-Manage-Key`

enabled: the owner switch, any owner proof. Off: your code does not run; saves follow the page's list rules. accountRead: "Reads your other pages", only with the profile that published the code (its X-Owner-Token or a signed-in session). Answers the same view as the read.

## Path parameters

- `ns` string, required
- `id` string, required

## Headers

- `X-Owner-Token` unknown
- `X-Manage-Key` unknown

## Request body

- LambdaSwitchRequest: Server code switches; either or both
  - `enabled` boolean, nullable: Owner switch. Off: your code does not run; saves follow the page's list rules.
  - `accountRead` boolean, nullable: "Reads your other pages": only with the profile that published the code

## Response `200`

Saved; same answer as the read

- LambdaView: Server code of an HTML page or site: switches, code, counters, usage and the newest runs (owner only).
  - `enabled` boolean, required: Owner switch. Off: your code does not run; saves follow the page's list rules.
  - `pausedByBrewPage` boolean, required: Paused by BrewPage: the code does not run; while enabled, saves of a page with beforeWrite are refused until lifted. With enabled false, saves follow the page's list rules.
  - `running` boolean, required: The code runs now: on, not paused and server code available.
  - `accountRead` boolean, required: "Reads your other pages" (bp.account): off by default, off again after any code, token or profile change.
  - `accountReadAllowed` boolean, required: This request may change accountRead: it carries the profile that published the code.
  - `version` integer, required: Code version: +1 for each changed lambda.js
  - `file` string, required: Always lambda.js
  - `source` string, required: The text of lambda.js
  - `handlers` string[], required: Exported handlers: onEntry, onComment, beforeWrite
  - `endpoints` string[], required: Own endpoint names (at most 2), called by the page with bp.lambda(name, body)
  - `counters` unknown, required
  - `usage` LambdaUsage, required: Usage windows: this page's UTC hour (runs), the profile's UTC day (runs, run time, fetches)
    - `hour` LambdaWindow, required: Runs, run time in milliseconds (server clock) and fetch requests of one window; absent = not counted there
      - `runs` integer, required
      - `wallMs` integer
      - `fetches` integer
    - `accountDay` LambdaWindow: Runs, run time in milliseconds (server clock) and fetch requests of one window; absent = not counted there
      - `runs` integer, required
      - `wallMs` integer
      - `fetches` integer
  - `limits` LambdaUsage, required: Caps of the same windows as usage, as they apply to this page now
    - `hour` LambdaWindow, required: Runs, run time in milliseconds (server clock) and fetch requests of one window; absent = not counted there
      - `runs` integer, required
      - `wallMs` integer
      - `fetches` integer
    - `accountDay` LambdaWindow: Runs, run time in milliseconds (server clock) and fetch requests of one window; absent = not counted there
      - `runs` integer, required
      - `wallMs` integer
      - `fetches` integer
  - `runs` LambdaRunView[], required: Newest finished runs, newest first
    - `id` integer, required: Run id
    - `trigger` string, required: entry, comment, before_write or endpoint
    - `handler` string, required: Handler or endpoint name
    - `outcome` string, required: ok, threw, cpu, wall, memory, stack, host_calls, output, crash, busy, unavailable, quota, off, lost or gone
    - `startedAt` string, date-time
    - `wallMs` integer
    - `calls` integer
    - `fetches` integer
    - `version` integer: Code version that ran
    - `error` string: Error name, message and stack, at most 2 KB
    - `log` string: console lines of the run, at most 16 KB
  - `nextOffset` integer: offset for GET .../lambda/runs to read older runs; absent when none
  - `updatedAt` string, date-time, required

## Other responses

- `400`: LAMBDA_INVALID: send enabled and/or accountRead as true or false
- `403`: Owner token revoked or expired; or OWNER_AUTHORIZATION_FAILED: a public publication you do not own; or LAMBDA_PROFILE_REQUIRED: accountRead needs the profile that published the code
- `404`: PUBLICATION_UNAVAILABLE: no such HTML page or site, not yours, hidden or expired; or LAMBDA_NOT_FOUND: the page has no server code
- `409`: OLD_PUBLICATION_READ_ONLY
- `429`: Rate limited: wait Retry-After (= retryAfterSeconds); no account: accountUrl, free sign-up with higher limits; or STATE_RATE_LIMITED: too much at once, wait Retry-After
- `503`: LAMBDA_UNAVAILABLE: server code is switched off for now; wait Retry-After

## Changes

- **2026-12-02** `04a8f351c1aa`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/brewpage/apis/brewpage-api/changes/api/:ns/:id/lambda/patch.md)

---

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