# Publish operator API service

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Publish the specified version of the operator as a callable API service. Save the service name after successful publishing; it can be called after the service is enabled.

```text
POST https://moi.matrixorigin.cn/newmoi/workflow/v2/workitems/catalog/$NODE_ID/api-service
```

## Preparation before calling

First [View operator list](../operator-catalog/list-operators.md) to confirm the operator to be released and its version. Prepare the personal access token, target workspace ID, operator ID, and version that has access to the target workspace.


## Request body

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>node_id</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The operator ID to be published. It can be obtained from the [View operator list](../operator-catalog/list-operators.md) response.</dd></div>
  <div class="mo-api-field"><dt><code>version</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The operator version to be released.</dd></div>
  <div class="mo-api-field"><dt><code>compute_resource_id</code><span class="mo-api-field__type">string</span></dt><dd>Specifies the computing resource ID for the service.</dd></div>
  <div class="mo-api-field"><dt><code>timeout_seconds</code><span class="mo-api-field__type">integer</span></dt><dd>Single call timeout, in seconds. When 0 is not passed or 0 is passed, it is 30, and the maximum value is 300.</dd></div>
  <div class="mo-api-field"><dt><code>max_concurrency</code><span class="mo-api-field__type">integer</span></dt><dd>The maximum number of concurrent calls, cannot be a negative number.</dd></div>
  <div class="mo-api-field"><dt><code>rate_limit_per_min</code><span class="mo-api-field__type">integer</span></dt><dd>Maximum number of calls per minute, cannot be negative.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Request example</p>
```

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/workflow/v2/workitems/catalog/$NODE_ID/api-service" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{
    \"version\": \"$VERSION\",
    \"timeout_seconds\": 30
  }"
```

:::
::::

## Successful response

The response returns service identification, status, calling address and configuration. After successful publishing, the service can be called; use the returned service name as it is for [call service](invoke-operator-api-service.md).


The response fields are as follows.

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">string</span></dt><dd>OK on success.</dd></div>
  <div class="mo-api-field"><dt><code>msg</code><span class="mo-api-field__type">string</span></dt><dd>OK on success.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.api_service_id</code><span class="mo-api-field__type">string</span></dt><dd>Service ID.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.operator_id</code><span class="mo-api-field__type">integer</span></dt><dd>Published custom operator ID.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.node_id</code><span class="mo-api-field__type">string</span></dt><dd>Published operator ID.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.version</code><span class="mo-api-field__type">string</span></dt><dd>Published operator version.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.service_name</code><span class="mo-api-field__type">string</span></dt><dd>Service name.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.status</code><span class="mo-api-field__type">string</span></dt><dd>Service status. ready means it can be called.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.result_mode</code><span class="mo-api-field__type">string</span></dt><dd>The result return mode of the service.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.auth_mode</code><span class="mo-api-field__type">string</span></dt><dd>The authentication mode of the service.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.method</code><span class="mo-api-field__type">string</span></dt><dd>The HTTP method used to call the service.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.path</code><span class="mo-api-field__type">string</span></dt><dd>Relative path to the calling service.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.workflow_id</code><span class="mo-api-field__type">string</span></dt><dd>The workflow ID associated with the service; returned if there is a value.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.workflow_def_id</code><span class="mo-api-field__type">string</span></dt><dd>The workflow definition ID associated with the service; returned if there is a value.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.workflow_version_id</code><span class="mo-api-field__type">string</span></dt><dd>The workflow version ID associated with the service; returned if there is a value.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.compute_resource_id</code><span class="mo-api-field__type">string</span></dt><dd>The computing resource ID used; only returned if there is a value.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.timeout_seconds</code><span class="mo-api-field__type">integer</span></dt><dd>Timeout for a single call, in seconds; returned if there is a value.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.max_concurrency</code><span class="mo-api-field__type">integer</span></dt><dd>The maximum number of concurrent calls; returned when there is a value.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.rate_limit_per_min</code><span class="mo-api-field__type">integer</span></dt><dd>Maximum number of calls per minute; returned if there is a value.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.input_schema</code><span class="mo-api-field__type">string</span></dt><dd>The serialized content of the input schema; returned if there is a value.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.output_schema</code><span class="mo-api-field__type">string</span></dt><dd>Output the serialized content of schema; return if there is a value.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.invoke</code><span class="mo-api-field__type">object</span></dt><dd>Information required to call the service; returned if there is a value.</dd></div>
  <div class="mo-api-field"><dt><code>data.service.deployment</code><span class="mo-api-field__type">object</span></dt><dd>Service deployment information; returned if there is a value.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Successful response example</p>
```

```json
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "service": {
      "api_service_id": "api_2e859efcedc1e0efea48b465b2197784",
      "node_id": "moi:data.sql.process",
      "version": "v1",
      "service_name": "operator-api-37f61ebdaa18aa51",
      "status": "ready",
      "method": "POST",
      "path": "/workspaces/ws-001/dynamic-services/invoke",
      "result_mode": "<result_mode>",
      "invoke": {
        "method": "POST",
        "path": "/workspaces/ws-001/dynamic-services/invoke",
        "result_mode": "<result_mode>",
        "body_example": {
          "service_name": "operator-api-37f61ebdaa18aa51",
          "payload": {}
        }
      }
    }
  }
}
```

:::
::::

## Error response

::::{div} mo-api-split
:::{div} mo-api-split-main

```{raw} html
<dl class="mo-api-fields">
  <div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">string</span></dt><dd>Error code.</dd></div>
  <div class="mo-api-field"><dt><code>msg</code><span class="mo-api-field__type">string</span></dt><dd>Readable error message.</dd></div>
  <div class="mo-api-field"><dt><code>data</code><span class="mo-api-field__type">null</span></dt><dd>`null` in an error response.</dd></div>
</dl>
```

:::
:::{div} mo-api-split-aside

```{raw} html
<p class="mo-api-example-label">Error response example</p>
```

```json
{
  "code": "ErrParamInvalid",
  "msg": "请求参数无效",
  "data": null
}
```

:::
::::

## Follow-up operations

After completion [View operator API service configuration](get-operator-api-service.md) confirms the current status.
