Create custom operator

Create a custom operator that can be used in the workflow. Code type provides Python code or source files. Built-in binding types create binding configurations based on a workflow operator version.

HTTP
POST $CLOUDSIGMA_API_BASE/workflow/v2/custom-operators

Before you call

Configure the CloudSigma regional endpoint and authentication before calling. The endpoint, credentials, workspace, and resource IDs must belong to the same region. Prepare personal access token and target workspace ID that can access the target workspace. Prepare content according to the type you want to create:

  • When creating a code type, prepare Python source code or source file IDs.

  • When creating a built-in binding type, first query workflow operator details and select the base operator version. Record the operator ID, version, and required binding configuration.

Request body

Shell
curl -X POST "$CLOUDSIGMA_API_BASE/workflow/v2/custom-operators" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "文本计数",
    "identifier": "text_counter",
    "description": "统计输入文本的字符数。",
    "language": "python",
    "handler": "main.handle",
    "input_schema": {
      "type": "object",
      "properties": {
        "text": {
          "type": "string",
          "description": "要统计的文本。"
        }
      }
    },
    "output_schema": {
      "type": "object",
      "properties": {
        "count": {
          "type": "integer",
          "description": "文本的字符数。"
        }
      }
    },
    "code": "def handle(workspace_id, sdk, input):\n    return {\"count\": len(input[\"text\"])}"
  }'

Code types need to provide code or source files, and built-in binding types need to specify a base operator. The two types of exclusive fields cannot be mixed. The code entry defaults to main.handle, and the enabled status defaults to true.

When the ID of the associated directory and database is less than or equal to 0, it will be ignored. When filling in the node ID, it must conform to the prefix format. Even if the suffix contains workspace information, it does not mean that the service has verified its ownership.

The service will check the root object of the input and output definition, and the relationship between type, properties, and required. The description attribute can be omitted.

The input attribute of the code operator cannot be empty, and the output properties can be omitted. When a built-in binding has no input mapping, an empty property object can be submitted. The JSON Schema will not be fully compiled on save, nor will the code be run.

Field

Type

Required

Description

name

string

Yes

operator name.

description

string

Yes

operator description.

kind

string or null

No

operator type. Code type when omitted.

language

string or null

No

The implementation language of the code type. Currently only python is supported.

handler

string or null

No

Code type handler function. Python handler functions use module and function names, such as main.handle. The corresponding function must accept three parameters: workspace_id, sdk and input.

version

string or null

No

operator version. When omitted, v1.

isolation_level

string or null

No

Isolation configuration for code types. Currently only PUBLIC is supported.

code

string or null

No

Source code for code types. Choose one from source_file_id.

source_file_id

string or null

No

The source file ID of the code type. Choose one of two options: code.

base_node_id

string or null

Conditional

The base operator ID of the built-in binding type. Required when selecting built-in binding.

base_node_version

string or null

Conditional

The base operator version of the built-in binding type. Required when selecting built-in binding.

node_id

string or null

No

Optional operator identifier. Must comply with the custom operator prefix format, and the suffix is ​​not used to verify workspace ownership.

identifier

string

Yes

operator identification.

input_schema

object or string

Yes

Enter the definition. Attributes need to declare the type, and the description can be omitted. The specific structure and type conditions are explained after the table.

output_schema

object or string

Yes

Output definition. Attributes need to declare the type, and the description can be omitted. The specific structure and type conditions are explained after the table.

binding_config

object or string

No

Binding configuration required for built-in binding types.

catalog_id

integer or null

No

Associate Catalog ID. Non-positive values ​​are ignored when created. 0 clears the association when updating, and negative numbers are invalid.

database_id

integer or null

No

Associated database ID. Non-positive values ​​are ignored when created. 0 clears the association when updating, and negative numbers are invalid.

enabled

boolean or null

No

Whether to enable initially.

Successful response

JSON
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "id": 123,
    "node_id": "moi:custom.operator:workspace:text_counter",
    "name": "文本计数",
    "identifier": "text_counter",
    "description": "统计输入文本的字符数。",
    "language": 1,
    "handler": "main.handle",
    "isolation_level": "PUBLIC",
    "input_schema": "{\"type\":\"object\"}",
    "output_schema": "{\"type\":\"object\"}",
    "enabled": true,
    "created_by": "user_01",
    "updated_by": "user_01",
    "kind": 1,
    "catalog_id": 1,
    "database_id": 2
  }
}

Field

Type

Description

code

string

success code.

msg

string

Response information.

data

object

The data returned by this operation.

data.id

integer

The new custom operator ID.

data.node_id

string

The operator ID in the workflow.

data.name

string

operator name.

data.identifier

string

operator identification.

data.description

string

operator description.

data.language

integer

operator implements language code.

data.handler

string

Code type handler function.

data.version

string

operator version.

data.isolation_level

string

operator isolation configuration.

data.source_file_id

string

Source file ID. Returned when created from source file.

data.input_schema

string

Enter the defined serialization content.

data.output_schema

string

Outputs the serialized content of the definition.

data.enabled

boolean

Whether the operator is enabled.

data.created_by

string

Creator ID.

data.updated_by

string

Last updated by identifier.

data.created_at

integer

Creation time.

data.updated_at

integer

Last updated time.

data.kind

integer

operator type code.

data.base_node_id

string

Association ID.

data.base_node_version

string

Base node version.

data.binding_config

string

Extended configuration.

data.catalog_id

integer

The associated Catalog ID.

data.database_id

integer

The associated database ID.

Error response

JSON
{
  "code": "ErrParamInvalid",
  "msg": "请求参数无效"
}

Field

Type

Required

Description

code

string

No

error code.

msg

string

No

Readable error message.

Common HTTP errors

HTTP status

Error code

Common cause

Recommended action

400

ErrParamInvalid, ErrWorkspaceRequired

Invalid request field, workspace, or operation precondition.

Fix the request parameters and submit again.

403

ErrForbidden

The current identity or active role does not have permission for this operation.

Use an authorized identity or contact an administrator to grant access.

404

ErrNotFound

The target object or required reference was not found.

Verify the object identifier, workspace, and current status.

409

ErrAlreadyExists

Conflict in resource state, request payload, or concurrent modification.

Re-read the current state and version, then handle according to the latest result.

500

ErrServer

Internal processing failed; write operations may have been partially applied.

Retain request and trace details, and verify the current state before retrying.

503

ErrServiceUnavailable

A business, runtime, or authorization dependency is temporarily unavailable.

After the dependency recovers, check existing results first instead of blindly repeating writes.

Last updated on