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

# 创建工作流

> 创建一个多步骤自动化工作流。

创建一个工作流，将多个 AI 任务串联起来，并支持调度、事件触发和条件逻辑。

## 身份验证

需要 Bearer 令牌。参见 [身份验证](/api-reference/authentication)。

## 请求体

<ParamField body="name" type="string" required>
  人类可读的工作流名称。
</ParamField>

<ParamField body="triggerType" type="string" required>
  工作流的触发方式。取值为：`schedule`、`event`、`manual` 之一。
</ParamField>

<ParamField body="triggerConfig" type="object">
  触发器专属配置（例如，调度触发器使用 `{ "cron": "0 9 * * 1" }`）。
</ParamField>

<ParamField body="steps" type="object[]" required>
  工作流步骤的有序数组。至少需要一个步骤。

  <Expandable title="Step object">
    <ParamField body="type" type="string" required>步骤类型（例如 `"ai_transform"`、`"notification"`、`"http"`）。</ParamField>
    <ParamField body="name" type="string" required>步骤名称。</ParamField>
    <ParamField body="config" type="object" required>步骤专属配置。</ParamField>
    <ParamField body="onSuccess" type="integer">成功时跳转到的下一步骤的索引。</ParamField>
    <ParamField body="onFailure" type="integer">失败时跳转到的下一步骤的索引。</ParamField>
  </Expandable>
</ParamField>

<ParamField body="enabled" type="boolean" default="true">
  该工作流是否处于启用状态。
</ParamField>

## 请求示例

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://www.hitheo.ai/api/v1/workflows \
    -H "Authorization: Bearer $THEO_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Weekly Pipeline Report",
      "triggerType": "schedule",
      "triggerConfig": { "cron": "0 9 * * 1" },
      "steps": [
        {
          "type": "ai_transform",
          "name": "Generate report",
          "config": { "prompt": "Analyze this week's pipeline changes", "skills": ["data-extraction"] }
        },
        {
          "type": "notification",
          "name": "Send to team",
          "config": { "channel": "email", "to": "team@acme.com" }
        }
      ]
    }'
  ```

  ```typescript SDK theme={null}
  const workflow = await theo.createWorkflow({
    name: "Weekly Pipeline Report",
    triggerType: "schedule",
    triggerConfig: { cron: "0 9 * * 1" },
    steps: [
      {
        type: "ai_transform",
        name: "Generate report",
        config: { prompt: "Analyze this week's pipeline changes", skills: ["data-extraction"] },
      },
      {
        type: "notification",
        name: "Send to team",
        config: { channel: "email", to: "team@acme.com" },
      },
    ],
  });
  ```
</CodeGroup>

## 响应（HTTP 201）

<ResponseField name="workflow" type="object">
  创建成功的工作流对象，包含自动生成的 `id` 和时间戳。
</ResponseField>

## 错误

| 状态码 | 代码 | 描述 |
| - | - | - |
| 400 | `missing_fields` | 缺少必填字段 `name`、`triggerType` 和 `steps` |

## 端点

`POST /api/v1/workflows`

需要通过 Bearer 令牌进行身份验证。参见 [身份验证](/api-reference/authentication)。


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