> ## Documentation Index
> Fetch the complete documentation index at: https://developer.opus.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update a Code Node

> Revise a code node your organization owns, cutting a new version

Revise a code node your organization owns.

Every field is optional — omitted fields keep their current value. Each call cuts a new code version rather than editing in place, so the previous state stays addressable.

Use the `id` returned by [Create a Code Node](/api-reference/v1-code/create-code) as `{codeId}`.

Requires the **Code: Full** permission at organization level, and a verified organization.

<Warning>
  `sourceCode`, `inputs` and `outputs` are replaced **wholesale**, not merged field by field. Send the complete value you want stored — a partial `inputs` map drops every variable you left out.
</Warning>

<Note>
  Omitting `sourceCode` carries the current version's source forward unchanged, so you can revise metadata without resending the module.
</Note>

## Headers

<ParamField header="x-service-key" type="string" required>
  Your API authentication key
</ParamField>

## Path Parameters

<ParamField path="codeId" type="string" required>
  The code node to revise. This is `id` from [Create a Code Node](/api-reference/v1-code/create-code) — not its `versionId`. Must be a UUID.
</ParamField>

## Body Parameters

The code node is nested under a `code` key.

<ParamField body="code" type="object" required>
  The fields to change. All of them are optional.
</ParamField>

<ParamField body="code.name" type="string">
  Code node display name. Maximum 255 characters.
</ParamField>

<ParamField body="code.description" type="string">
  What the code does, shown under its name. Maximum 2048 characters.
</ParamField>

<ParamField body="code.icon" type="string">
  Code icon as a base64-encoded SVG (or PNG) — a plain string, with no `data:` prefix. Maximum 65535 characters.
</ParamField>

<ParamField body="code.sourceCode" type="string">
  Replacement Python source. Must define `main(inputs)`. Replaces the stored source wholesale. Maximum 262144 bytes when UTF-8 encoded. Omit to carry the current source forward.
</ParamField>

<ParamField body="code.inputs" type="object">
  Replacement input schema, keyed by each variable's `variableName`. Same shape and limits as on create — see [Variable object](/api-reference/v1-code/create-code#variable-object).
</ParamField>

<ParamField body="code.outputs" type="object">
  Replacement output schema. Same shape and limits as `inputs`.
</ParamField>

<ParamField body="code.categories" type="string[]">
  Replacement category list. Maximum 5 entries. See [Categories](/api-reference/v1-code/create-code#categories).
</ParamField>

<ParamField body="code.status" type="string">
  Code status — `active`, `inactive`, `soon` or `deprecated`.
</ParamField>

<ParamField body="code.isNew" type="boolean">
  Show the "new" badge on the code tile.
</ParamField>

<ParamField body="code.isPopular" type="boolean">
  Show the "popular" badge on the code tile.
</ParamField>

<ParamField body="code.isBeta" type="boolean">
  Show the "beta" badge on the code tile.
</ParamField>

## Response

<ResponseField name="id" type="string" required>
  The code id, unchanged.
</ResponseField>

<ResponseField name="name" type="string" required>
  Code node display name.
</ResponseField>

<ResponseField name="description" type="string">
  Code node description.
</ResponseField>

<ResponseField name="versionId" type="string">
  Id of the new version this call created. Differs on every successful call, including one that changes only a badge.
</ResponseField>

<Note>
  The response echoes only these four fields. `icon`, `categories`, `status` and the badge flags are stored but not returned.
</Note>

## Errors

<ResponseField name="400" type="Bad Request">
  Invalid body, a `codeId` that is not a UUID, an `inputs`/`outputs` entry that is not a valid variable, or source that failed the security scan. A scan failure carries a `violations` array.
</ResponseField>

<ResponseField name="401" type="Unauthorized">
  Missing, invalid, or expired API key.
</ResponseField>

<ResponseField name="403" type="Forbidden">
  The code node belongs to another organization, your organization is not verified to author code, the API key is not org-scoped, or the key owner lacks the **Code: Full** permission in the organization.
</ResponseField>

<ResponseField name="404" type="Not Found">
  No code node with that id.
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl --request PATCH \
    --url https://operator.opus.com/api/v1/code/{CODE_ID} \
    --header 'Content-Type: application/json' \
    --header 'x-service-key: {YOUR_SERVICE_KEY}' \
    --data '{
      "code": {
        "description": "Collapses runs of whitespace and lowercases the result",
        "sourceCode": "import re\n\n\ndef main(inputs):\n    raw_text = inputs.get(\"raw_text\") or \"\"\n\n    return {\"clean_text\": re.sub(r\"\\s+\", \" \", raw_text).strip().lower()}\n",
        "categories": ["text_processing", "validation_and_normalization"],
        "status": "active",
        "isNew": false
      }
    }'
  ```

  ```python Python theme={null}
  import requests

  code_id = "{CODE_ID}"
  url = f"https://operator.opus.com/api/v1/code/{code_id}"
  headers = {
      "Content-Type": "application/json",
      "x-service-key": "{YOUR_SERVICE_KEY}"
  }
  source = '''import re


  def main(inputs):
      raw_text = inputs.get("raw_text") or ""

      return {"clean_text": re.sub(r"\\s+", " ", raw_text).strip().lower()}
  '''
  payload = {
      "code": {
          "description": "Collapses runs of whitespace and lowercases the result",
          "sourceCode": source,
          "categories": ["text_processing", "validation_and_normalization"],
          "status": "active",
          "isNew": False,
      }
  }

  response = requests.patch(url, json=payload, headers=headers)
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const codeId = "{CODE_ID}";
  const source = `import re


  def main(inputs):
      raw_text = inputs.get("raw_text") or ""

      return {"clean_text": re.sub(r"\\s+", " ", raw_text).strip().lower()}
  `;

  const response = await fetch(`https://operator.opus.com/api/v1/code/${codeId}`, {
    method: "PATCH",
    headers: {
      "Content-Type": "application/json",
      "x-service-key": "{YOUR_SERVICE_KEY}",
    },
    body: JSON.stringify({
      code: {
        description: "Collapses runs of whitespace and lowercases the result",
        sourceCode: source,
        categories: ["text_processing", "validation_and_normalization"],
        status: "active",
        isNew: false,
      },
    }),
  });

  const data = await response.json();
  console.log(data);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 Response theme={null}
  {
    "id": "{CODE_ID}",
    "name": "Normalize Text",
    "description": "Collapses runs of whitespace and lowercases the result",
    "versionId": "{NEW_CODE_VERSION_ID}"
  }
  ```
</ResponseExample>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.