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

# Scheduled Task erstellen

> Erstelle eine Scheduled Task, die diesem Workspace-API-Key gehört

Erstellt eine Scheduled Task, die diesem Workspace-API-Key gehört. Neue Aufgaben starten mit `active` auf `true`. Der Status der Antwort ist `201`. Der Body enthält kein `runCount`.

## Basis-URL

```
https://api.langdock.com/automations/v1
```

<Warning>
  **Dedicated Deployments**

  Ersetze `api.langdock.com` durch `<your-deployment-url>/api/public` in allen Anfragen.
</Warning>

## Benötigte Scopes

Dieser Endpoint braucht den Scope `AUTOMATION_API` (**Scheduled Tasks API**) auf einem Workspace-API-Key.

Ein Workspace kann 10 Aufgaben für diesen Besitzer halten. Die nächste Erstellung liefert `400` mit der Message `AUTOMATION_LIMIT_REACHED`. Eine abgelaufene Trial liefert `403` mit dem Code `TRIAL_EXPIRED`.

## Parameter

Sende einen JSON-Body. Unbekannte Felder werden abgelehnt. Die Zeitplanregeln stehen in der [Scheduled Tasks API Übersicht](/de/developer/scheduled-tasks-api/scheduled-tasks-overview).

| Parameter                  | Typ            | Pflicht                          | Beschreibung                                                                                                    |
| -------------------------- | -------------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `name`                     | string         | Ja                               | 1 bis 200 Zeichen.                                                                                              |
| `prompt`                   | string         | Ja                               | 1 bis 120000 Zeichen.                                                                                           |
| `frequency`                | string         | Ja                               | `MANUAL`, `DAILY`, `WEEKDAYS`, `WEEKLY`, `MONTHLY` oder `SELECTED_WEEKDAYS`.                                    |
| `timeOfDay`                | string         | Für jede Frequenz außer `MANUAL` | `HH:mm` im 24-Stunden-Format.                                                                                   |
| `dayOfWeek`                | integer        | Für `WEEKLY`                     | 0 (Sonntag) bis 6 (Samstag).                                                                                    |
| `dayOfMonth`               | integer        | Für `MONTHLY`                    | 1 bis 31.                                                                                                       |
| `daysOfWeek`               | integer\[]     | Für `SELECTED_WEEKDAYS`          | Mindestens ein Tag, jeder von 0 bis 6. Höchstens 7 Werte.                                                       |
| `timezone`                 | string \| null | Nein                             | IANA-Name, höchstens 64 Zeichen. Leer oder weggelassen wird bei einer geplanten Frequenz als `UTC` gespeichert. |
| `modelMode`                | string         | Nein                             | `UNSET`, `EXPLICIT` oder `AUTO`.                                                                                |
| `modelId`                  | string \| null | Wenn `modelMode` `EXPLICIT` ist  | Modell-UUID. Muss in derselben Anfrage stehen.                                                                  |
| `assistantId`              | string \| null | Nein                             | UUID des primären Agenten. Muss für den Key verfügbar sein.                                                     |
| `taggedAssistantId`        | string \| null | Nein                             | Zusätzliche Agentenerwähnung. Wird verworfen, wenn der Key sie nicht nutzen kann.                               |
| `taggedIntegrationIds`     | string\[]      | Nein                             | Höchstens 20. Nicht erreichbare IDs werden verworfen.                                                           |
| `taggedKnowledgeFolderIds` | string\[]      | Nein                             | Höchstens 20. Nicht erreichbare IDs werden verworfen.                                                           |
| `taggedWorkflowIds`        | string\[]      | Nein                             | Höchstens 20. Nicht erreichbare IDs werden verworfen.                                                           |
| `taggedSkillSlugs`         | string\[]      | Nein                             | Höchstens 20. Jeder Slug hat höchstens 100 Zeichen. Nicht erreichbare Slugs werden verworfen.                   |
| `attachmentIds`            | string\[]      | Nein                             | Höchstens 20 Anhang-UUIDs, die diesem Key im Workspace schon gehören.                                           |

## Beispiel

```javascript theme={null}
const axios = require("axios");

async function createScheduledTask() {
  const response = await axios.post(
    "https://api.langdock.com/automations/v1",
    {
      name: "Monday pipeline brief",
      prompt: "Summarize overnight pipeline changes for the revenue team.",
      frequency: "WEEKLY",
      timeOfDay: "09:00",
      dayOfWeek: 1,
      timezone: "Europe/Berlin"
    },
    {
      headers: {
        Authorization: "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
      }
    }
  );

  console.log(response.status, response.data.automation.id);
}

createScheduledTask();
```

## Antwortformat

### Erfolgreiche Antwort (201 Created)

`automation` entspricht dem [Scheduled-Task-Objekt](/de/developer/scheduled-tasks-api/scheduled-tasks-overview) ohne `runCount`.

```typescript theme={null}
{
  automation: {
    id: string;
    createdAt: string;
    name: string;
    prompt: string;
    modelId: string | null;
    modelMode: "UNSET" | "EXPLICIT" | "AUTO";
    assistantId: string | null;
    taggedAssistantId: string | null;
    frequency:
      | "MANUAL"
      | "DAILY"
      | "WEEKDAYS"
      | "WEEKLY"
      | "MONTHLY"
      | "SELECTED_WEEKDAYS";
    timeOfDay: string | null;
    dayOfWeek: number | null;
    dayOfMonth: number | null;
    daysOfWeek: number[];
    timezone: string | null;
    active: boolean;
    lastRunAt: string | null;
    attachments: Array<{
      id: string;
      name: string;
      mimeType: string | null;
      type: string | null;
    }>;
    taggedIntegrationIds: string[];
    taggedKnowledgeFolderIds: string[];
    taggedWorkflowIds: string[];
    taggedSkillSlugs: string[];
  };
}
```

## Fehlerbehandlung

| Statuscode | Beschreibung                                                                                                                                        |
| ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| 400        | Ungültiger Body oder Message `AUTOMATION_LIMIT_REACHED`                                                                                             |
| 401        | Ungültiger oder fehlender API-Key, oder der Key-User wurde nicht gefunden                                                                           |
| 403        | `AUTOMATION_API` fehlt, persönlicher API-Key, Scheduled Tasks deaktiviert, kein Produktzugriff, `TRIAL_EXPIRED` oder `AUTOMATION_TAG_ACCESS_DENIED` |
| 405        | Methode nicht erlaubt                                                                                                                               |
| 429        | Rate Limit überschritten                                                                                                                            |
| 500        | Interner Serverfehler                                                                                                                               |

Ein ungültiger Body liefert `400` mit der Message `Invalid request` und einem `errors`-Array. Fehlende Uhrzeitfelder nutzen `timeOfDay is required for scheduled automations`, `dayOfWeek is required for weekly automations`, `dayOfMonth is required for monthly automations` oder `daysOfWeek is required for selected weekday automations`. Eine ungültige Zeitzone nutzt `timezone must be a valid IANA identifier`. `modelMode` `EXPLICIT` ohne `modelId` nutzt `modelId is required for explicit model selection`. Eine abgelaufene Trial liefert `403` mit dem Code `TRIAL_EXPIRED` und der Message `Your trial has expired. Upgrade to continue.`

<Info>
  Langdock blockiert Anfragen aus Browser-Origins absichtlich, um deinen API-Key zu schützen und deine Anwendungen sicher zu halten. Mehr dazu findest du im Guide zu [API Key Best Practices](/de/admin/ai-adoption-and-rollout/best-practices/api-key-best-practices).
</Info>


## OpenAPI

````yaml POST /automations/v1
openapi: 3.0.0
info:
  title: Langdock API
  version: 3.0.0
servers:
  - url: https://api.langdock.com
    description: Production
security:
  - bearerAuth: []
paths:
  /automations/v1:
    post:
      tags:
        - Scheduled Tasks
      summary: Create a scheduled task
      description: >-
        Creates a scheduled task owned by this workspace API key. New tasks
        start active. The response does not include runCount.
      operationId: createScheduledTask
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required:
                - name
                - prompt
                - frequency
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 200
                prompt:
                  type: string
                  minLength: 1
                  maxLength: 120000
                frequency:
                  type: string
                  enum:
                    - MANUAL
                    - DAILY
                    - WEEKDAYS
                    - WEEKLY
                    - MONTHLY
                    - SELECTED_WEEKDAYS
                timeOfDay:
                  type: string
                  nullable: true
                  description: 24 hour HH:mm. Required unless frequency is MANUAL.
                dayOfWeek:
                  type: integer
                  minimum: 0
                  maximum: 6
                  nullable: true
                  description: Required for WEEKLY. 0 is Sunday and 6 is Saturday.
                dayOfMonth:
                  type: integer
                  minimum: 1
                  maximum: 31
                  nullable: true
                  description: Required for MONTHLY.
                daysOfWeek:
                  type: array
                  maxItems: 7
                  items:
                    type: integer
                    minimum: 0
                    maximum: 6
                  description: Required for SELECTED_WEEKDAYS.
                timezone:
                  type: string
                  nullable: true
                  maxLength: 64
                  description: >-
                    IANA timezone. Empty or omitted on a scheduled frequency is
                    stored as UTC.
                modelMode:
                  type: string
                  enum:
                    - UNSET
                    - EXPLICIT
                    - AUTO
                modelId:
                  type: string
                  format: uuid
                  nullable: true
                  description: Required in the same request when modelMode is EXPLICIT.
                assistantId:
                  type: string
                  format: uuid
                  nullable: true
                taggedAssistantId:
                  type: string
                  format: uuid
                  nullable: true
                taggedIntegrationIds:
                  type: array
                  maxItems: 20
                  items:
                    type: string
                    format: uuid
                taggedKnowledgeFolderIds:
                  type: array
                  maxItems: 20
                  items:
                    type: string
                    format: uuid
                taggedWorkflowIds:
                  type: array
                  maxItems: 20
                  items:
                    type: string
                    format: uuid
                taggedSkillSlugs:
                  type: array
                  maxItems: 20
                  items:
                    type: string
                    maxLength: 100
                attachmentIds:
                  type: array
                  maxItems: 20
                  items:
                    type: string
                    format: uuid
      responses:
        '201':
          description: >-
            Scheduled task created. The automation object does not include
            runCount.
        '400':
          description: Invalid body, or message AUTOMATION_LIMIT_REACHED
        '401':
          description: Invalid or missing API key, or the key user was not found
        '403':
          description: >-
            Missing AUTOMATION_API, a personal API key, Scheduled Tasks
            disabled, no product access, TRIAL_EXPIRED, or
            AUTOMATION_TAG_ACCESS_DENIED
        '405':
          description: Method not allowed
        '429':
          description: Rate limit exceeded
        '500':
          description: Internal server error
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: API key as Bearer token. Format "Bearer YOUR_API_KEY"

````