> ## 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.