---
title: "Create a scheduled task."
method: POST
path: "/scheduled_tasks"
tags: ["Scheduled Tasks"]
---

# Create a scheduled task.

`POST /scheduled_tasks`

## Request

- Base URL: `https://h2ogpte.genai.h2o.ai/api/v1`
- URL: `https://h2ogpte.genai.h2o.ai/api/v1/scheduled_tasks`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/h2o/apis/h2ogpte-rest-api/docs/scheduled_tasks/post.ts> (a function with typed inputs; its response is checked against the schema)

## Request body

- ScheduledTaskCreateRequest
  - `name` string, required
  - `description` string
  - `schedule_type` 'once' | 'recurring' | 'interval', required
  - `schedule_expression` string, required: ISO-8601 datetime for once, 5-field cron for recurring, "N minutes"/"N hours" for interval.
  - `task_type` 'chat_completion' | 'agent_task', required
  - `task_config` object, required: Must contain a non-empty "message" key (the question/prompt). May include "timezone", "collection_id", "llm_args".
  - `max_executions` integer, nullable
  - `expires_at` string, date-time, nullable
  - `notification_email` string

## Response `201`

Created

- ScheduledTask
  - `id` string, uuid
  - `user_id` string, uuid
  - `username` string
  - `name` string
  - `description` string
  - `schedule_type` 'once' | 'recurring' | 'interval'
  - `schedule_expression` string
  - `task_type` 'chat_completion' | 'agent_task'
  - `task_config` object
  - `status` 'active' | 'paused' | 'completed' | 'expired'
  - `execution_status` string: Runtime execution state: idle or running.
  - `last_execution_at` string, date-time, nullable
  - `next_execution_at` string, date-time, nullable
  - `execution_count` integer
  - `max_executions` integer, nullable
  - `expires_at` string, date-time, nullable
  - `created_at` string, date-time
  - `updated_at` string, date-time
  - `is_owner` boolean
  - `notification_email` string

## Other responses

- `401`: Unauthorized - Invalid or missing API key
- `default`: Unexpected error

---

[API](https://skmtc.dev/h2o/apis/h2ogpte-rest-api.md) - [All operations](https://skmtc.dev/h2o/apis/h2ogpte-rest-api/llms.txt) - [OpenAPI document](https://skmtc.dev/h2o/apis/h2ogpte-rest-api/revisions/a82a117320f4?raw)
