Skip to main content
PATCH
/
rest
/
workflows
/
{workflow_id_or_name}
Patch Workflow
curl --request PATCH \
  --url https://api.promptlayer.com/rest/workflows/{workflow_id_or_name} \
  --header 'Content-Type: application/json' \
  --header 'X-API-KEY: <x-api-key>' \
  --data '
{
  "base_version": 123,
  "commit_message": "<string>",
  "nodes": {},
  "required_input_variables": {},
  "edges": [
    {
      "source_node_name": "<string>",
      "target_node_name": "<string>",
      "is_and": true,
      "conditionals": [
        {
          "position": 1,
          "operator": "=",
          "left_config": {},
          "right_config": {}
        }
      ]
    }
  ],
  "release_labels": [
    "<string>"
  ]
}
'
{
  "success": true,
  "workflow_id": 123,
  "workflow_name": "<string>",
  "workflow_version_id": 123,
  "version_number": 123,
  "base_version": 123,
  "release_labels": [
    "<string>"
  ],
  "nodes": [
    {
      "id": "<string>",
      "name": "<string>",
      "node_type": "<string>",
      "is_output_node": true
    }
  ],
  "required_input_variables": {}
}
Partially update a Workflow by creating a new version with merged changes. This endpoint allows you to modify specific nodes without resending the entire configuration. The PATCH operation:
  1. Fetches the specified base version (or latest if not specified)
  2. Merges your node updates with existing nodes
  3. Creates a new version with the merged configuration

HTTP Request

PATCH /rest/workflows/{workflow_id_or_name}

Path Parameters

  • workflow_id_or_name (string, required): The ID or name of the Workflow to update.

Request Body

The request body expects a JSON object with the following structure:

Schema

{
  "base_version": "integer (optional)",
  "commit_message": "string (optional)",
  "nodes": {
    "node_name": {
      "node_type": "string (optional)",
      "configuration": "object (optional)",
      "dependencies": ["string"] "(optional)",
      "is_output_node": "boolean (optional)"
    },
    "node_to_remove": null
  },
  "required_input_variables": {
    "variable_name": "type"
  },
  "edges": [...],
  "release_labels": ["string"]
}

Parameters

Version Control

  • base_version (integer, optional): The version number to base changes on. Defaults to the latest version.
  • commit_message (string, optional): A message describing the changes.

Node Updates

The nodes object is keyed by node name:
  • Updating a node: Provide the node name with an object containing the fields to update. Unspecified fields are preserved from the base version.
  • Removing a node: Set the node name to null.
  • Adding a node: Provide a node name that doesn’t exist in the base version with node_type and configuration (required for new nodes). See Node & Column Types for available node types.

Other Fields

  • required_input_variables (object, optional): If provided, replaces the input variables entirely.
  • edges (array, optional): If provided, replaces edges entirely. If not provided, edges are copied from the base version (excluding edges referencing removed nodes).
  • release_labels (array of strings, optional): Labels to attach to the new version.

Response

Status Code: 201 (Created)
{
  "success": true,
  "message": "Workflow version created successfully",
  "workflow_id": 123,
  "workflow_name": "my-workflow",
  "workflow_version_id": 789,
  "version_number": 3,
  "base_version": 2,
  "release_labels": ["staging"],
  "nodes": [
    {
      "id": "uuid",
      "name": "updated_node",
      "node_type": "VARIABLE",
      "is_output_node": true
    }
  ],
  "required_input_variables": {
    "user_input": "string"
  }
}

Examples

Update a Single Node’s Configuration

Update just the configuration of one node while preserving everything else:
import requests

response = requests.patch(
    "https://api.promptlayer.com/rest/workflows/my-workflow",
    headers={"X-API-KEY": "your-api-key"},
    json={
        "commit_message": "Updated prompt template version",
        "nodes": {
            "response_generator": {
                "configuration": {
                    "template": {
                        "prompt_name": "response-v2",
                        "label": "production"
                    }
                }
            }
        }
    }
)

Add a New Node

Add a new node to an existing workflow:
response = requests.patch(
    "https://api.promptlayer.com/rest/workflows/my-workflow",
    headers={"X-API-KEY": "your-api-key"},
    json={
        "commit_message": "Added logging node",
        "nodes": {
            "logger": {
                "node_type": "CODE_EXECUTION",
                "configuration": {
                    "code": "print(f'Processing: {input_data}')",
                    "language": "PYTHON"
                },
                "dependencies": ["input_data"],
                "is_output_node": False
            }
        }
    }
)

Remove a Node

Remove a node from the workflow:
response = requests.patch(
    "https://api.promptlayer.com/rest/workflows/my-workflow",
    headers={"X-API-KEY": "your-api-key"},
    json={
        "commit_message": "Removed deprecated node",
        "nodes": {
            "old_processor": None  # This removes the node
        }
    }
)

Branch from a Specific Version

Create a new version based on an older version (not the latest):
response = requests.patch(
    "https://api.promptlayer.com/rest/workflows/my-workflow",
    headers={"X-API-KEY": "your-api-key"},
    json={
        "base_version": 5,  # Branch from version 5
        "commit_message": "Hotfix based on v5",
        "nodes": {
            "output": {
                "configuration": {
                    "value": {"type": "string", "value": "fixed"}
                }
            }
        }
    }
)

Update Multiple Nodes at Once

response = requests.patch(
    "https://api.promptlayer.com/rest/workflows/my-workflow",
    headers={"X-API-KEY": "your-api-key"},
    json={
        "commit_message": "Major update",
        "nodes": {
            "node_a": {
                "configuration": {"value": {"type": "string", "value": "updated_a"}}
            },
            "node_b": {
                "dependencies": ["node_a", "new_input"]
            },
            "old_node": None,  # Remove this node
            "new_node": {      # Add this node
                "node_type": "VARIABLE",
                "configuration": {"value": {"type": "string", "value": "new"}},
                "dependencies": [],
                "is_output_node": False
            }
        },
        "required_input_variables": {
            "original_input": "string",
            "new_input": "string"
        },
        "release_labels": ["staging"]
    }
)

Update and Deploy to Production

response = requests.patch(
    "https://api.promptlayer.com/rest/workflows/123",
    headers={"X-API-KEY": "your-api-key"},
    json={
        "commit_message": "Production deploy",
        "nodes": {
            "response": {
                "configuration": {
                    "template": {"prompt_name": "prod-response", "label": "production"}
                }
            }
        },
        "release_labels": ["production"]  # Move production label to this version
    }
)

Merge Behavior

FieldMerge Behavior
nodesMerge by name - update matching, keep unmentioned, remove null
nodes[name].configurationDeep merge with existing config
nodes[name].dependenciesFull replace (not merged)
nodes[name].is_output_nodeUpdate if specified
required_input_variablesFull replace if specified
edgesFull replace if specified, otherwise copied from base
release_labelsMove labels to new version

Error Responses

Status CodeError
400Validation error, no output nodes, invalid dependencies
401Missing or invalid API key
404Workflow not found, base version not found

Headers

X-API-KEY
string
required

Your API key for authentication.

Path Parameters

workflow_id_or_name
string
required

The ID or name of the workflow to update.

Body

application/json

Request body for partially updating a workflow.

base_version
integer | null

The version number to base changes on. Defaults to the latest version.

commit_message
string | null

A message describing the changes.

nodes
object

Node updates keyed by node name. Use null to remove a node.

required_input_variables
object

If provided, replaces the input variables entirely.

edges
object[] | null

If provided, replaces edges entirely.

release_labels
string[] | null

Labels to attach to the new version.

Response

Workflow version created successfully

Response after creating or patching a workflow.

success
boolean
required

Indicates if the request was successful.

workflow_id
integer
required

The ID of the workflow.

workflow_name
string
required

The name of the workflow.

workflow_version_id
integer
required

The ID of the created workflow version.

version_number
integer
required

The version number.

base_version
integer | null

The base version this was created from (PATCH only).

release_labels
string[] | null

Labels attached to this version.

nodes
object[]

Summary of nodes in the workflow.

required_input_variables
object

Required input variables for the workflow.