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

# Create automation

> Create an automation for the API key's organization. Modem assigns the organization's earliest owner.

Provide a complete automation definition. Event schedules accept canonical registered event names only.
To send output to Slack or Discord, provide sourceName and sourceChannelId together. Otherwise Modem uses
the organization's saved default output destination. Requests fail when no valid destination is available.

This operation supports Idempotency-Key and accepts organization API keys only; service JWTs are rejected.




## OpenAPI

````yaml /api-reference/openapi.json post /automations
openapi: 3.1.1
info:
  description: >-
    The public Modem API. Authenticate with an organization API key:
    `Authorization: Bearer modem_…`.
  title: Modem API
  version: 1.0.0
servers:
  - description: Production
    url: https://api.modem.dev/v1
security:
  - bearerAuth: []
paths:
  /automations:
    post:
      tags:
        - Automations
      summary: Create automation
      description: >
        Create an automation for the API key's organization. Modem assigns the
        organization's earliest owner.


        Provide a complete automation definition. Event schedules accept
        canonical registered event names only.

        To send output to Slack or Discord, provide sourceName and
        sourceChannelId together. Otherwise Modem uses

        the organization's saved default output destination. Requests fail when
        no valid destination is available.


        This operation supports Idempotency-Key and accepts organization API
        keys only; service JWTs are rejected.
      operationId: automations.createPublic
      parameters:
        - description: >-
            Replays a successful mutating request for 24 hours. Reuse with a
            different payload returns 409.
          in: header
          name: Idempotency-Key
          required: false
          schema:
            maxLength: 255
            type: string
      requestBody:
        content:
          application/json:
            schema:
              anyOf:
                - additionalProperties: false
                  properties:
                    allowedCapabilities:
                      anyOf:
                        - items:
                            type: string
                          type: array
                        - type: 'null'
                      description: >-
                        Explicit capability keys when capabilityMode is custom.
                        Null means all.
                      title: Allowed Capabilities
                    capabilityMode:
                      description: >-
                        Whether this task uses all visible capabilities or a
                        custom subset.
                      enum:
                        - all
                        - custom
                      title: Capability Mode
                      type: string
                    enabled:
                      type: boolean
                    modelLevel:
                      description: Persisted model level for automation execution.
                      enum:
                        - high
                        - low
                        - med
                      title: Model Level
                      type: string
                    name:
                      minLength: 1
                      type: string
                    prompt:
                      maxLength: 130000
                      minLength: 1
                      type: string
                    schedule:
                      anyOf:
                        - additionalProperties: false
                          properties:
                            expr:
                              minLength: 1
                              type: string
                            type:
                              const: cron
                          required:
                            - expr
                            - type
                          type: object
                        - additionalProperties: false
                          properties:
                            rrule:
                              minLength: 1
                              type: string
                            type:
                              const: rrule
                          required:
                            - rrule
                            - type
                          type: object
                        - additionalProperties: false
                          properties:
                            at:
                              format: date-time
                              type: string
                            type:
                              const: at
                          required:
                            - at
                            - type
                          type: object
                        - additionalProperties: false
                          properties:
                            'n':
                              exclusiveMinimum: 0
                              type: integer
                            type:
                              const: every
                            unit:
                              enum:
                                - hours
                                - minutes
                              type: string
                          required:
                            - 'n'
                            - type
                            - unit
                          type: object
                        - additionalProperties: false
                          properties:
                            delaySeconds:
                              maximum: 604800
                              minimum: 1
                              type: integer
                            events:
                              items:
                                enum:
                                  - github.issue.closed
                                  - github.pr.created
                                  - github.pr.dismissed
                                  - github.pr.merged
                                  - gitlab.mr.closed
                                  - gitlab.mr.created
                                  - gitlab.mr.merged
                                  - sentry.feedback.created
                                  - stripe.customer.created
                                  - stripe.invoice.payment_failed
                                  - stripe.subscription.canceled
                                  - stripe.subscription.created
                                  - stripe.subscription.trial_ending
                                  - topic.created
                                  - topic.priority.high
                                type: string
                              maxItems: 20
                              minItems: 1
                              type: array
                            type:
                              const: event
                          required:
                            - events
                            - type
                          type: object
                    templateSlug:
                      pattern: ^[a-z0-9-]+$
                      type: string
                    timezone:
                      minLength: 1
                      type: string
                  required:
                    - name
                    - prompt
                    - schedule
                    - timezone
                  type: object
                - additionalProperties: false
                  properties:
                    allowedCapabilities:
                      anyOf:
                        - items:
                            type: string
                          type: array
                        - type: 'null'
                      description: >-
                        Explicit capability keys when capabilityMode is custom.
                        Null means all.
                      title: Allowed Capabilities
                    capabilityMode:
                      description: >-
                        Whether this task uses all visible capabilities or a
                        custom subset.
                      enum:
                        - all
                        - custom
                      title: Capability Mode
                      type: string
                    enabled:
                      type: boolean
                    modelLevel:
                      description: Persisted model level for automation execution.
                      enum:
                        - high
                        - low
                        - med
                      title: Model Level
                      type: string
                    name:
                      minLength: 1
                      type: string
                    prompt:
                      maxLength: 130000
                      minLength: 1
                      type: string
                    schedule:
                      anyOf:
                        - additionalProperties: false
                          properties:
                            expr:
                              minLength: 1
                              type: string
                            type:
                              const: cron
                          required:
                            - expr
                            - type
                          type: object
                        - additionalProperties: false
                          properties:
                            rrule:
                              minLength: 1
                              type: string
                            type:
                              const: rrule
                          required:
                            - rrule
                            - type
                          type: object
                        - additionalProperties: false
                          properties:
                            at:
                              format: date-time
                              type: string
                            type:
                              const: at
                          required:
                            - at
                            - type
                          type: object
                        - additionalProperties: false
                          properties:
                            'n':
                              exclusiveMinimum: 0
                              type: integer
                            type:
                              const: every
                            unit:
                              enum:
                                - hours
                                - minutes
                              type: string
                          required:
                            - 'n'
                            - type
                            - unit
                          type: object
                        - additionalProperties: false
                          properties:
                            delaySeconds:
                              maximum: 604800
                              minimum: 1
                              type: integer
                            events:
                              items:
                                enum:
                                  - github.issue.closed
                                  - github.pr.created
                                  - github.pr.dismissed
                                  - github.pr.merged
                                  - gitlab.mr.closed
                                  - gitlab.mr.created
                                  - gitlab.mr.merged
                                  - sentry.feedback.created
                                  - stripe.customer.created
                                  - stripe.invoice.payment_failed
                                  - stripe.subscription.canceled
                                  - stripe.subscription.created
                                  - stripe.subscription.trial_ending
                                  - topic.created
                                  - topic.priority.high
                                type: string
                              maxItems: 20
                              minItems: 1
                              type: array
                            type:
                              const: event
                          required:
                            - events
                            - type
                          type: object
                    sourceChannelId:
                      minLength: 1
                      type: string
                    sourceName:
                      enum:
                        - discord
                        - slack
                      type: string
                    templateSlug:
                      pattern: ^[a-z0-9-]+$
                      type: string
                    timezone:
                      minLength: 1
                      type: string
                  required:
                    - name
                    - prompt
                    - schedule
                    - sourceChannelId
                    - sourceName
                    - timezone
                  type: object
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  allowedCapabilities:
                    anyOf:
                      - items:
                          type: string
                        type: array
                      - type: 'null'
                    description: >-
                      Explicit capability keys when capabilityMode is custom.
                      Null means all.
                    title: Allowed Capabilities
                  capabilityMode:
                    description: >-
                      Whether this task uses all visible capabilities or a
                      custom subset.
                    enum:
                      - all
                      - custom
                    title: Capability Mode
                    type: string
                  createdAt:
                    description: Timestamp when the task was created.
                    format: date-time
                    title: Created At
                    type: string
                  enabled:
                    description: Whether the task is actively being scheduled.
                    title: Enabled
                    type: boolean
                  id:
                    format: uuid
                    type: string
                  lastAttemptAt:
                    anyOf:
                      - format: date-time
                        type: string
                      - type: 'null'
                    description: >-
                      Timestamp when the most recent execution attempt started,
                      including manual runs.
                    title: Last Attempt At
                  lastErrorMessage:
                    anyOf:
                      - type: string
                      - type: 'null'
                    description: Most recent error message if status is error.
                    title: Last Error Message
                  lastRunAt:
                    anyOf:
                      - format: date-time
                        type: string
                      - type: 'null'
                    description: >-
                      Timestamp of the most recent scheduler-managed execution,
                      used to calculate the next run.
                    title: Last Run At
                  modelLevel:
                    description: Persisted model level for automation execution.
                    enum:
                      - high
                      - low
                      - med
                    title: Model Level
                    type: string
                  name:
                    description: Human-readable name for the automation.
                    minLength: 1
                    title: Name
                    type: string
                  nextRunAt:
                    anyOf:
                      - format: date-time
                        type: string
                      - type: 'null'
                    description: Timestamp of the next scheduled execution.
                    title: Next Run At
                  outputChannels:
                    items:
                      properties:
                        channel:
                          enum:
                            - discord
                            - email
                            - slack
                          type: string
                        destinations:
                          anyOf:
                            - items:
                                minLength: 1
                                type: string
                              type: array
                            - type: 'null'
                        mode:
                          enum:
                            - any-internal
                            - any
                            - specific
                          type: string
                      required:
                        - channel
                        - destinations
                        - mode
                      type: object
                    minItems: 1
                    type: array
                  prompt:
                    description: AI prompt or instructions executed when the task runs.
                    minLength: 1
                    title: Prompt
                    type: string
                  schedule:
                    anyOf:
                      - additionalProperties: false
                        properties:
                          expr:
                            minLength: 1
                            type: string
                          type:
                            const: cron
                        required:
                          - expr
                          - type
                        type: object
                      - additionalProperties: false
                        properties:
                          rrule:
                            minLength: 1
                            type: string
                          type:
                            const: rrule
                        required:
                          - rrule
                          - type
                        type: object
                      - additionalProperties: false
                        properties:
                          at:
                            format: date-time
                            type: string
                          type:
                            const: at
                        required:
                          - at
                          - type
                        type: object
                      - additionalProperties: false
                        properties:
                          'n':
                            exclusiveMinimum: 0
                            type: integer
                          type:
                            const: every
                          unit:
                            enum:
                              - hours
                              - minutes
                            type: string
                        required:
                          - 'n'
                          - type
                          - unit
                        type: object
                      - additionalProperties: false
                        properties:
                          delaySeconds:
                            maximum: 604800
                            minimum: 1
                            type: integer
                          events:
                            items:
                              enum:
                                - github.issue.closed
                                - github.pr.created
                                - github.pr.dismissed
                                - github.pr.merged
                                - gitlab.mr.closed
                                - gitlab.mr.created
                                - gitlab.mr.merged
                                - sentry.feedback.created
                                - stripe.customer.created
                                - stripe.invoice.payment_failed
                                - stripe.subscription.canceled
                                - stripe.subscription.created
                                - stripe.subscription.trial_ending
                                - topic.created
                                - topic.priority.high
                              type: string
                            maxItems: 20
                            minItems: 1
                            type: array
                          type:
                            const: event
                        required:
                          - events
                          - type
                        type: object
                  status:
                    description: Current health status of the automation.
                    enum:
                      - completed
                      - error
                      - healthy
                      - paused
                    title: Status
                    type: string
                  templateSlug:
                    anyOf:
                      - pattern: ^[a-z0-9-]+$
                        type: string
                      - type: 'null'
                  timezone:
                    description: IANA timezone identifier for schedule evaluation.
                    minLength: 1
                    title: Timezone
                    type: string
                  updatedAt:
                    description: Timestamp when the task was last updated.
                    format: date-time
                    title: Updated At
                    type: string
                required:
                  - allowedCapabilities
                  - capabilityMode
                  - enabled
                  - id
                  - lastErrorMessage
                  - modelLevel
                  - name
                  - outputChannels
                  - prompt
                  - schedule
                  - status
                  - templateSlug
                  - timezone
                type: object
          description: OK
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Invalid request (validation failed).
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Missing or invalid API key.
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: The API key does not have access to this resource.
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: The requested resource was not found.
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: >-
            The request conflicts with an existing resource or idempotency
            operation.
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Rate limit exceeded.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Internal server error.
components:
  schemas:
    Error:
      properties:
        code:
          description: Machine-readable error code, e.g. `NOT_FOUND`.
          examples:
            - NOT_FOUND
          type: string
        data:
          description: Optional structured error details.
        defined:
          description: True if the error was declared in the procedure contract.
          type: boolean
        message:
          description: Human-readable error message.
          type: string
        status:
          description: HTTP status code.
          examples:
            - 404
          type: integer
      required:
        - code
        - defined
        - message
        - status
      type: object
  securitySchemes:
    bearerAuth:
      description: Organization API key (`modem_…`).
      scheme: bearer
      type: http

````