> ## 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](https://developer.opus.com/api-reference/v1-code/create-code.md) 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.

> [!NOTE]
>
> Omitting `sourceCode` carries the current version's source forward unchanged, so you can revise metadata without resending the module.

## Headers

**x-service-key** `string` *required*

Your API authentication key

## Path Parameters

**codeId** `string` *required*

The code node to revise. This is `id` from [Create a Code Node](https://developer.opus.com/api-reference/v1-code/create-code.md) — not its `versionId`. Must be a UUID.

## Body Parameters

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

**code** `object` *required*

The fields to change. All of them are optional.

**code.name** `string`

Code node display name. Maximum 255 characters.

**code.description** `string`

What the code does, shown under its name. Maximum 2048 characters.

**code.icon** `string`

Code icon as a base64-encoded SVG (or PNG) — a plain string, with no `data:` prefix. Maximum 65535 characters.

**code.sourceCode** `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.

**code.inputs** `object`

Replacement input schema, keyed by each variable's `variableName`. Same shape and limits as on create — see [Variable object](https://developer.opus.com/api-reference/v1-code/create-code.md#variable-object).

**code.outputs** `object`

Replacement output schema. Same shape and limits as `inputs`.

**code.categories** `string[]`

Replacement category list. Maximum 5 entries. See [Categories](https://developer.opus.com/api-reference/v1-code/create-code.md#categories).

**code.status** `string`

Code status — `active`, `inactive`, `soon` or `deprecated`.

**code.isNew** `boolean`

Show the "new" badge on the code tile.

**code.isPopular** `boolean`

Show the "popular" badge on the code tile.

**code.isBeta** `boolean`

Show the "beta" badge on the code tile.

## Response

**id** `string` *required*

The code id, unchanged.

**name** `string` *required*

Code node display name.

**description** `string`

Code node description.

**versionId** `string`

Id of the new version this call created. Differs on every successful call, including one that changes only a badge.

> [!NOTE]
>
> The response echoes only these four fields. `icon`, `categories`, `status` and the badge flags are stored but not returned.

## Errors

**400** `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.

**401** `Unauthorized`

Missing, invalid, or expired API key.

**403** `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.

**404** `Not Found`

No code node with that id.

```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);
```

```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}"
}
```


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