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

# Create task

> Creates a new AI task. Use trigger_type to schedule it: `immediate` runs once right away, `cron` runs on a cron expression, `interval` runs every N seconds, `once` runs at a specific scheduled_at, `event` runs in response to account events. For recurring tasks (`cron`/`interval`), add an optional `condition_script` — a cheap JavaScript gate that runs before each fire (no LLM, no credits) and skips the run unless its last expression is truthy, so the agent only wakes when there's work to do.



## OpenAPI

````yaml /developer/api-reference/openapi.json post /tasks
openapi: 3.1.1
info:
  title: Crevio API V1
  version: 1.0.0
  description: >
    API for the Crevio creator platform — a multi-tenant SaaS for digital
    product sales.

    Uses snake_case keys following Stripe conventions. All resource IDs are
    string IDs (e.g., "prod_abc123").
  contact:
    email: support@crevio.co
    name: Crevio Support
    url: https://crevio.co/docs
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: https://api.crevio.co/v1
    description: Production
security:
  - ApiKey: []
tags:
  - name: Account
    description: Current account information
  - name: Analytics
    description: Account-wide business analytics
  - name: BlogCategories
    description: Blog post categories
  - name: BlogPosts
    description: Blog content management
  - name: Carts
    description: Shopping cart management
  - name: CheckoutLinks
    description: Shareable checkout links
  - name: Checkouts
    description: Checkout session management
  - name: Customers
    description: Customer relationship management
  - name: Discounts
    description: Discount code management
  - name: Emails
    description: Email sending
  - name: Experiences
    description: Digital experiences (courses, communities, downloads)
  - name: Files
    description: File uploads and external media management
  - name: FormSubmissions
    description: Form submission management
  - name: FormationDocuments
    description: Documents generated for a formation
  - name: Formations
    description: Whitelabel business formation via doola Partner API
  - name: Forms
  - name: Invoices
    description: Invoice creation, payment, and lifecycle management
  - name: LegalPages
  - name: Me
    description: Current user profile
  - name: OrderItems
    description: Order line items
  - name: Orders
    description: Order history and details
  - name: PriceVariants
    description: Product pricing tiers
  - name: Products
    description: Digital product catalog
  - name: Refunds
    description: Refund management
  - name: Reviews
    description: Product reviews
  - name: Socials
    description: Social media management (accounts, posts, media).
  - name: Subscriptions
    description: Subscription lifecycle management (cancel, pause, resume)
  - name: Tags
    description: Customer tags
  - name: TaskRuns
    description: Individual execution records for AI tasks.
  - name: Tasks
    description: >-
      AI tasks — scheduled or event-triggered agentic work (cron, interval,
      once, immediate, event).
  - name: WebhookEndpoints
    description: Webhook endpoint management
  - name: WebhookEvents
    description: Webhook event delivery history
  - name: Leads
    description: Find, verify and enrich business leads (Hunter.io-backed).
  - name: Ads
    description: >-
      Paid advertising — campaigns, ad groups, ads, audiences, targeting, leads,
      conversions, and reports across Meta, Google, TikTok, LinkedIn, Pinterest,
      and X.
  - name: Domains
    description: Custom web domains for your sites.
  - name: Web
    description: >-
      Web search & scraping (search, read, map, crawl, extract, research),
      backed by Firecrawl.
  - name: Skills
    description: >-
      AI skills marketplace — search the catalog and install or uninstall skills
      for your account's agent.
  - name: Schedules
    description: Reusable availability schedules that back event types.
  - name: EventTypes
    x-displayName: Event Types
    description: Bookable services customers can schedule time on.
  - name: Bookings
    description: Reservations made against event types.
  - name: Connections
    description: Third-party app connections (connect, list, execute)
  - name: Approvals
    description: Human-in-the-loop approvals for gated actions
  - name: Logs
    description: Account activity log
paths:
  /tasks:
    post:
      tags:
        - Tasks
      summary: Create task
      description: >-
        Creates a new AI task. Use trigger_type to schedule it: `immediate` runs
        once right away, `cron` runs on a cron expression, `interval` runs every
        N seconds, `once` runs at a specific scheduled_at, `event` runs in
        response to account events. For recurring tasks (`cron`/`interval`), add
        an optional `condition_script` — a cheap JavaScript gate that runs
        before each fire (no LLM, no credits) and skips the run unless its last
        expression is truthy, so the agent only wakes when there's work to do.
      operationId: createTask
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AiTaskRequest'
      responses:
        '201':
          description: Task created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AiTask'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - ApiKey: []
      x-codeSamples:
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { Crevio } from "@crevio/sdk";

            const crevio = new Crevio({
              apiKey: process.env["CREVIO_API_KEY"] ?? "",
            });

            async function run() {
              const result = await crevio.tasks.create({});

              console.log(result);
            }

            run();
components:
  schemas:
    AiTaskRequest:
      type: object
      properties:
        name:
          type: string
        description:
          type:
            - string
            - 'null'
        prompt:
          type: string
        trigger_type:
          type: string
          enum:
            - immediate
            - cron
            - interval
            - once
            - event
        cron_expression:
          type:
            - string
            - 'null'
        interval_seconds:
          type:
            - integer
            - 'null'
        scheduled_at:
          type:
            - string
            - 'null'
          format: date-time
        timezone:
          type: string
        model_id:
          type:
            - string
            - 'null'
        agent:
          type: string
          enum:
            - business
            - engineering
          description: >-
            Which agent runs the task. Use `engineering` for pure code/build
            work on a site; defaults to `business`.
        condition_script:
          type:
            - string
            - 'null'
          description: >-
            Cheap pre-run gate for recurring tasks (`cron`/`interval`). Plain
            JavaScript run in a sandboxed isolate against the same `crevioApi.*`
            connector as the execute tool, BEFORE each scheduled run — no LLM,
            no credits. The task only runs when the script's last expression (or
            explicit `return`) is truthy; it skips on `false`/`null`. **Default
            to setting this whenever the task is "act only when X"**
            (new/unfulfilled/failed records, a threshold crossed, an unread
            inbox, a metric at zero) — without it the agent wakes and spends
            credits on every tick even when there's nothing to do. Only omit it
            for tasks that genuinely should run every tick (e.g. a scheduled
            report the user always wants). End with a boolean, e.g. `const r =
            await crevioApi.listOrders({ status: 'succeeded' }); r.data.some(o
            => o.fulfillment_status !== 'fulfilled')`. Errors fail open (the
            task runs). Ignored for non-recurring triggers.
        approval_mode:
          type: string
          enum:
            - autonomous
            - supervised
            - read_only
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
        active:
          type: boolean
        delivery_methods:
          type: array
          items:
            type: string
            enum:
              - notification
              - email
              - telegram
              - discord
              - slack
        event_conditions:
          type:
            - object
            - 'null'
        site_id:
          type: string
          description: >-
            Site this task works on (`site_...`); its repo is mounted as the
            run's workspace. Defaults to the account's default working site.
    AiTask:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
        name:
          type: string
        description:
          type:
            - string
            - 'null'
        prompt:
          type: string
        trigger_type:
          type: string
          enum:
            - immediate
            - cron
            - interval
            - once
            - event
        cron_expression:
          type:
            - string
            - 'null'
        interval_seconds:
          type:
            - integer
            - 'null'
        scheduled_at:
          type:
            - string
            - 'null'
          format: date-time
        event_conditions:
          type:
            - object
            - 'null'
        condition_script:
          type:
            - string
            - 'null'
        timezone:
          type: string
        delivery_methods:
          type: array
          items:
            type: string
            enum:
              - notification
              - email
              - telegram
              - discord
              - slack
        approval_mode:
          type: string
          enum:
            - autonomous
            - supervised
            - read_only
        model_id:
          type:
            - string
            - 'null'
        agent:
          type: string
          enum:
            - business
            - engineering
        active:
          type: boolean
        expires_at:
          type:
            - string
            - 'null'
          format: date-time
        next_run_at:
          type:
            - string
            - 'null'
          format: date-time
        last_run_at:
          type:
            - string
            - 'null'
          format: date-time
        total_runs_count:
          type: integer
        consecutive_failure_count:
          type: integer
        total_credits_consumed:
          type: integer
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        site_id:
          type:
            - string
            - 'null'
      required:
        - id
        - object
        - name
        - description
        - prompt
        - trigger_type
        - cron_expression
        - interval_seconds
        - scheduled_at
        - event_conditions
        - condition_script
        - timezone
        - delivery_methods
        - approval_mode
        - model_id
        - agent
        - active
        - expires_at
        - next_run_at
        - last_run_at
        - total_runs_count
        - consecutive_failure_count
        - total_credits_consumed
        - created_at
        - updated_at
        - site_id
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            type:
              type: string
              enum:
                - api_error
                - invalid_request_error
                - validation_error
            code:
              type: string
            message:
              type: string
            param:
              type: string
            errors:
              type: object
          required:
            - type
            - message
      required:
        - error
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              type: invalid_request_error
              code: bad_request
              message: The request was malformed or contained invalid parameters
    Unauthorized:
      description: Authentication required
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              type: invalid_request_error
              code: authentication_required
              message: You did not provide an API key.
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              type: invalid_request_error
              code: forbidden
              message: You do not have permission to perform this action
    UnprocessableEntity:
      description: Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              type: validation_error
              code: validation_failed
              message: Email is required
              errors:
                email:
                  - can't be blank
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              type: api_error
              code: internal_error
              message: An unexpected error occurred
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: Authorization
      description: 'API key in the format: Bearer {api_token}'

````